MySQL 8.4.3
Source Code Documentation
sp.cc File Reference
#include "sql/sp.h"
#include <string.h>
#include <algorithm>
#include <atomic>
#include <memory>
#include <new>
#include <utility>
#include <vector>
#include "lex_string.h"
#include "m_string.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_psi_config.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/bits/psi_statement_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/my_loglevel.h"
#include "mysql/psi/mysql_sp.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd_routine.h"
#include "sql/dd/dd_utility.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/function.h"
#include "sql/dd/types/procedure.h"
#include "sql/dd/types/routine.h"
#include "sql/dd/types/schema.h"
#include "sql/dd/types/trigger.h"
#include "sql/dd_sp.h"
#include "sql/dd_sql_view.h"
#include "sql/dd_table_share.h"
#include "sql/debug_sync.h"
#include "sql/error_handler.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/lock.h"
#include "sql/log_event.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/set_var.h"
#include "sql/sp_cache.h"
#include "sql/sp_head.h"
#include "sql/sp_pcontext.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_db.h"
#include "sql/sql_digest_stream.h"
#include "sql/sql_error.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "template_utils.h"

Classes

class  anonymous_namespace{sp.cc}::Silence_deprecated_warning
 Silence DEPRECATED SYNTAX warnings when loading a stored procedure into the cache. More...
 
class  Bad_db_error_handler
 

Namespaces

namespace  anonymous_namespace{sp.cc}
 

Macros

#define SP_TYPE_STRING(type)    (type == enum_sp_type::FUNCTION ? "FUNCTION" : "PROCEDURE")
 

Functions

static bool create_string (THD *thd, String *buf, enum_sp_type type, const char *db, size_t dblen, const char *name, size_t namelen, const char *params, size_t paramslen, const char *returns, size_t returnslen, const char *body, size_t bodylen, st_sp_chistics *chistics, const LEX_CSTRING &definer_user, const LEX_CSTRING &definer_host, sql_mode_t sql_mode, bool if_not_exists)
 Generates the CREATE... string from the table information. More...
 
bool load_charset (MEM_ROOT *mem_root, Field *field, const CHARSET_INFO *dflt_cs, const CHARSET_INFO **cs)
 
bool load_collation (MEM_ROOT *mem_root, Field *field, const CHARSET_INFO *dflt_cl, const CHARSET_INFO **cl)
 
static bool lock_routine_name (THD *thd, enum_sp_type type, const sp_name *name, enum_mdl_type mdl_lock_type)
 Acquire Shared MDL lock on the routine object. More...
 
static void recursion_level_error (THD *thd, sp_head *sp)
 Return appropriate error about recursion limit reaching. More...
 
static enum_sp_return_code db_find_routine (THD *thd, enum_sp_type type, const sp_name *name, sp_head **sphp)
 Find routine definition in data dictionary table and create corresponding sp_head object for it. More...
 
static sp_headsp_compile (THD *thd, String *defstr, sql_mode_t sql_mode, Stored_program_creation_ctx *creation_ctx)
 The function parses input strings and returns SP structure. More...
 
enum_sp_return_code db_load_routine (THD *thd, enum_sp_type type, const char *sp_db, size_t sp_db_len, const char *sp_name, size_t sp_name_len, sp_head **sphp, sql_mode_t sql_mode, const char *params, const char *returns, const char *body, st_sp_chistics *sp_chistics, const char *definer_user, const char *definer_host, longlong created, longlong modified, Stored_program_creation_ctx *creation_ctx)
 
static bool check_routine_already_exists (THD *thd, sp_head *sp, bool if_not_exists, bool &already_exists)
 Method to check if routine with same name already exists. More...
 
static bool create_routine_precheck (THD *thd, sp_head *sp)
 Precheck for create routine statement. More...
 
static bool sp_binlog_create_routine_stmt (THD *thd, sp_head *sp, const LEX_USER *definer, bool if_not_exists, bool already_exists)
 Method to log create routine event to binlog. More...
 
bool sp_create_routine (THD *thd, sp_head *sp, const LEX_USER *definer, bool if_not_exists, bool &sp_already_exists)
 Creates a stored routine. More...
 
enum_sp_return_code sp_drop_routine (THD *thd, enum_sp_type type, sp_name *name)
 Drops a stored routine. More...
 
bool sp_update_routine (THD *thd, enum_sp_type type, sp_name *name, st_sp_chistics *chistics)
 Updates(Alter) a stored routine. More...
 
bool lock_db_routines (THD *thd, const dd::Schema &schema)
 Acquires exclusive metadata lock on all stored routines in the given database. More...
 
bool sp_drop_db_routines (THD *thd, const dd::Schema &schema)
 Drop all routines in database 'db'. More...
 
static bool show_create_routine_from_dd_routine (THD *thd, enum_sp_type type, sp_name *sp, const dd::Routine *routine)
 Prepare show create routine output from the DD routine object. More...
 
bool sp_show_create_routine (THD *thd, enum_sp_type type, sp_name *name)
 Implement SHOW CREATE statement for stored routines. More...
 
sp_headsp_find_routine (THD *thd, enum_sp_type type, sp_name *name, sp_cache **cp, bool cache_only)
 Obtain object representing stored procedure/function by its name from stored procedures cache and looking into data dictionary if needed. More...
 
sp_headsp_setup_routine (THD *thd, enum_sp_type type, sp_name *name, sp_cache **cp)
 Setup a cached routine for execution. More...
 
bool sp_exist_routines (THD *thd, Table_ref *routines, bool is_proc)
 This is used by sql_acl.cc:mysql_routine_grant() and is used to find the routines in 'routines'. More...
 
static bool sp_add_used_routine (Query_tables_list *prelocking_ctx, Query_arena *arena, const uchar *key, size_t key_length, size_t db_length, const char *name, size_t name_length, Table_ref *belong_to_view)
 Auxiliary function that adds new element to the set of stored routines used by statement. More...
 
bool sp_add_used_routine (Query_tables_list *prelocking_ctx, Query_arena *arena, Sroutine_hash_entry::entry_type type, const char *db, size_t db_length, const char *name, size_t name_length, bool lowercase_db, Sp_name_normalize_type name_normalize_type, bool own_routine, Table_ref *belong_to_view)
 Add routine or trigger which is used by statement to the set of stored routines used by this statement. More...
 
void sp_remove_not_own_routines (Query_tables_list *prelocking_ctx)
 Remove routines which are only indirectly used by statement from the set of routines used by this statement. More...
 
void sp_update_stmt_used_routines (THD *thd, Query_tables_list *prelocking_ctx, malloc_unordered_map< std::string, Sroutine_hash_entry * > *src, Table_ref *belong_to_view)
 Add contents of hash representing set of routines to the set of routines used by statement. More...
 
void sp_update_stmt_used_routines (THD *thd, Query_tables_list *prelocking_ctx, SQL_I_List< Sroutine_hash_entry > *src, Table_ref *belong_to_view)
 Add contents of list representing set of routines to the set of routines used by statement. More...
 
enum_sp_return_code sp_cache_routine (THD *thd, Sroutine_hash_entry *rt, bool lookup_only, sp_head **sp)
 A helper wrapper around sp_cache_routine() to use from prelocking until 'sp_name' is eradicated as a class. More...
 
enum_sp_return_code sp_cache_routine (THD *thd, enum_sp_type type, const sp_name *name, bool lookup_only, sp_head **sp)
 Ensure that routine is present in cache by loading it from the data dictionary if needed. More...
 
static bool strnstr (const char *str, size_t length, const char *substr)
 
static size_t find_dollar_quote (const st_sp_chistics *chistics, const char *sp_body, size_t sp_body_len, char *quote, size_t max_quote_len)
 Make sure to choose a dollar quote that does not conflict with the content of the routine. More...
 
sp_headsp_start_parsing (THD *thd, enum_sp_type sp_type, sp_name *sp_name)
 Start parsing of a stored program. More...
 
void sp_finish_parsing (THD *thd)
 Finish parsing of a stored program. More...
 
uint sp_get_flags_for_command (LEX *lex)
 
bool sp_check_name (LEX_STRING *ident)
 Check that the name 'ident' is ok. More...
 
Itemsp_prepare_func_item (THD *thd, bool standalone, Item **it_addr)
 Prepare an Item for evaluation (call of fix_fields). More...
 
bool sp_eval_expr (THD *thd, bool standalone, Field *result_field, Item **expr_item_ptr)
 Evaluate an expression and store the result in the field. More...
 
Stringsp_get_item_value (THD *thd, Item *item, String *str)
 Return a string representation of the Item value. More...
 

Macro Definition Documentation

◆ SP_TYPE_STRING

#define SP_TYPE_STRING (   type)     (type == enum_sp_type::FUNCTION ? "FUNCTION" : "PROCEDURE")

Function Documentation

◆ check_routine_already_exists()

static bool check_routine_already_exists ( THD thd,
sp_head sp,
bool  if_not_exists,
bool &  already_exists 
)
static

Method to check if routine with same name already exists.

Parameters
thdThread context.
spStored routine object to store.
if_not_existsTrue if 'IF NOT EXISTS' clause was specified.
[out]already_existsSet to true if routine already exists.
Return values
falseSuccess.
trueError.

◆ create_routine_precheck()

static bool create_routine_precheck ( THD thd,
sp_head sp 
)
static

Precheck for create routine statement.

Parameters
thdThread context.
spStored routine object to store.
Return values
falseSuccess.
trueError.

◆ create_string()

static bool create_string ( THD thd,
String buf,
enum_sp_type  type,
const char *  db,
size_t  dblen,
const char *  name,
size_t  namelen,
const char *  params,
size_t  paramslen,
const char *  returns,
size_t  returnslen,
const char *  body,
size_t  bodylen,
st_sp_chistics chistics,
const LEX_CSTRING definer_user,
const LEX_CSTRING definer_host,
sql_mode_t  sql_mode,
bool  if_not_exists 
)
static

Generates the CREATE... string from the table information.

Returns
Returns true on success, false on (alloc) failure.

◆ db_find_routine()

static enum_sp_return_code db_find_routine ( THD thd,
enum_sp_type  type,
const sp_name name,
sp_head **  sphp 
)
static

Find routine definition in data dictionary table and create corresponding sp_head object for it.

Parameters
thdThread context
typeType of routine (PROCEDURE/...)
nameName of routine
sphpOut parameter in which pointer to created sp_head object is returned (0 in case of error).
Note
This function may damage current LEX during execution, so it is good idea to create temporary LEX and make it active before calling it.
Return values
SP_OKSuccess
non-SP_OKError (one of special codes like SP_DOES_NOT_EXISTS)

◆ db_load_routine()

enum_sp_return_code db_load_routine ( THD thd,
enum_sp_type  type,
const char *  sp_db,
size_t  sp_db_len,
const char *  sp_name,
size_t  sp_name_len,
sp_head **  sphp,
sql_mode_t  sql_mode,
const char *  params,
const char *  returns,
const char *  body,
st_sp_chistics sp_chistics,
const char *  definer_user,
const char *  definer_host,
longlong  created,
longlong  modified,
Stored_program_creation_ctx creation_ctx 
)

◆ find_dollar_quote()

static size_t find_dollar_quote ( const st_sp_chistics chistics,
const char *  sp_body,
size_t  sp_body_len,
char *  quote,
size_t  max_quote_len 
)
static

Make sure to choose a dollar quote that does not conflict with the content of the routine.

This is only used for external language routines.

Parameters
[in]chisticsRoutine characteristics
[in]sp_bodyStart of external language routine body
[in]sp_body_lenLength of routine body
[out]quoteBuffer to put the dollar quote in
[in]max_quote_lenMax length of dollar quote (incl. null term.)
Returns
Length of dollar quote

◆ load_charset()

bool load_charset ( MEM_ROOT mem_root,
Field field,
const CHARSET_INFO dflt_cs,
const CHARSET_INFO **  cs 
)

◆ load_collation()

bool load_collation ( MEM_ROOT mem_root,
Field field,
const CHARSET_INFO dflt_cl,
const CHARSET_INFO **  cl 
)

◆ lock_db_routines()

bool lock_db_routines ( THD thd,
const dd::Schema schema 
)

Acquires exclusive metadata lock on all stored routines in the given database.

Parameters
thdThread handler
schemaSchema object
Return values
falseSuccess
trueFailure

◆ lock_routine_name()

static bool lock_routine_name ( THD thd,
enum_sp_type  type,
const sp_name name,
enum_mdl_type  mdl_lock_type 
)
static

Acquire Shared MDL lock on the routine object.

Parameters
thdThread context
typeType of the routine (enum_sp_type::PROCEDURE/...)
nameName of the routine
mdl_lock_typeType of MDL lock be acquired on the routine.
Return values
falseSuccess
trueError

◆ recursion_level_error()

static void recursion_level_error ( THD thd,
sp_head sp 
)
static

Return appropriate error about recursion limit reaching.

Parameters
thdThread handle
spThe stored procedure executed
Remarks
For functions and triggers we return error about prohibited recursion. For stored procedures we return about reaching recursion limit.

◆ show_create_routine_from_dd_routine()

static bool show_create_routine_from_dd_routine ( THD thd,
enum_sp_type  type,
sp_name sp,
const dd::Routine routine 
)
static

Prepare show create routine output from the DD routine object.

Parameters
[in]thdThread handle.
[in]typeStored routine type.
[in]spStored routine name.
[in]routineRoutine object read for the routine.
Return values
falseon success
trueon error

◆ sp_add_used_routine() [1/2]

static bool sp_add_used_routine ( Query_tables_list prelocking_ctx,
Query_arena arena,
const uchar key,
size_t  key_length,
size_t  db_length,
const char *  name,
size_t  name_length,
Table_ref belong_to_view 
)
static

Auxiliary function that adds new element to the set of stored routines used by statement.

The elements of Query_tables_list::sroutines set are accessed on prepared statement re-execution. Because of this we have to allocate memory for both hash element and copy of its key in persistent arena.

Parameters
prelocking_ctxPrelocking context of the statement
arenaArena in which memory for new element will be allocated
keyKey for the hash representing set
key_lengthKey length.
db_lengthLength of db name component in the key.
nameName of the routine.
name_lengthLength of the routine name.
belong_to_viewUppermost view which uses this routine (0 if routine is not used by view)
Note
Will also add element to end of 'Query_tables_list::sroutines_list' list.
Return values
truenew element was added.
falseelement was not added (because it is already present in the set).

◆ sp_add_used_routine() [2/2]

bool sp_add_used_routine ( Query_tables_list prelocking_ctx,
Query_arena arena,
Sroutine_hash_entry::entry_type  type,
const char *  db,
size_t  db_length,
const char *  name,
size_t  name_length,
bool  lowercase_db,
Sp_name_normalize_type  name_normalize_type,
bool  own_routine,
Table_ref belong_to_view 
)

Add routine or trigger which is used by statement to the set of stored routines used by this statement.

To be friendly towards prepared statements one should pass persistent arena as second argument.

Parameters
prelocking_ctxPrelocking context of the statement
arenaArena in which memory for new element of the set will be allocated
typeRoutine type (one of FUNCTION/PROCEDURE/ TRIGGER ...)
dbDatabase name
db_lengthDatabase name length
nameRoutine name
name_lengthRoutine name length
lowercase_dbIndicates whether db needs to be lowercased when constructing key.
name_normalize_typeIndicates if names needs to be normalized (lowercased / accent needs to be removed).
own_routineIndicates whether routine is explicitly or implicitly used.
belong_to_viewUppermost view which uses this routine (nullptr if routine is not used by view)
Note
Will also add element to end of 'Query_tables_list::sroutines_list' list (and will take into account if this is an explicitly used routine).
Return values
True- new element was added.
False- element was not added (because it is already present in the set).

◆ sp_binlog_create_routine_stmt()

static bool sp_binlog_create_routine_stmt ( THD thd,
sp_head sp,
const LEX_USER definer,
bool  if_not_exists,
bool  already_exists 
)
static

Method to log create routine event to binlog.

Parameters
thdThread context.
spStored routine object to store.
definerDefiner of the routine.
if_not_existsTrue if 'IF NOT EXISTS' clause was specified.
already_existsTrue if routine already exists.
Return values
falsesuccess
trueerror

◆ sp_cache_routine() [1/2]

enum_sp_return_code sp_cache_routine ( THD thd,
enum_sp_type  type,
const sp_name name,
bool  lookup_only,
sp_head **  sp 
)

Ensure that routine is present in cache by loading it from the data dictionary if needed.

If the routine is present but old, reload it. Emit an appropriate error if there was a problem during loading.

Parameters
[in]thdThread context.
[in]typeType of object (FUNCTION or PROCEDURE).
[in]nameName of routine.
[in]lookup_onlyOnly check that the routine is in the cache. If it's not, don't try to load. If it is present, but old, don't try to reload.
[out]spPointer to sp_head object for routine, NULL if routine was not found.
Return values
SP_OKEither routine is found and was successfully loaded into cache or it does not exist.
non-SP_OKError while loading routine from DD table.

◆ sp_cache_routine() [2/2]

enum_sp_return_code sp_cache_routine ( THD thd,
Sroutine_hash_entry rt,
bool  lookup_only,
sp_head **  sp 
)

A helper wrapper around sp_cache_routine() to use from prelocking until 'sp_name' is eradicated as a class.

◆ sp_check_name()

bool sp_check_name ( LEX_STRING ident)

Check that the name 'ident' is ok.

It's assumed to be an 'ident' from the parser, so we only have to check length and trailing spaces. The former is a standard requirement (and 'show status' assumes a non-empty name), the latter is a mysql:ism as trailing spaces are removed by get_field().

Return values
truebad name
falsename is ok

◆ sp_compile()

static sp_head * sp_compile ( THD thd,
String defstr,
sql_mode_t  sql_mode,
Stored_program_creation_ctx creation_ctx 
)
static

The function parses input strings and returns SP structure.

Parameters
[in]thdThread handler
[in]defstrCREATE... string
[in]sql_modeSQL mode
[in]creation_ctxCreation context of stored routines
Return values
Pointeron sp_head struct Success
NULLerror

◆ sp_create_routine()

bool sp_create_routine ( THD thd,
sp_head sp,
const LEX_USER definer,
bool  if_not_exists,
bool &  sp_already_exists 
)

Creates a stored routine.

Atomicity: The operation to create a stored routine is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary, stored routines and table definition caches are in sync with operation state. Cache do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

Parameters
thdThread context.
spStored routine object to store.
definerDefiner of the SP.
if_not_existsTrue if 'IF NOT EXISTS' clause was specified.
[out]sp_already_existsSet to true if routine already exists.
Return values
falseSuccess.
trueError.

◆ sp_drop_db_routines()

bool sp_drop_db_routines ( THD thd,
const dd::Schema schema 
)

Drop all routines in database 'db'.

Parameters
thdThread context.
schemaSchema object.
Return values
falseSuccess
trueError

◆ sp_drop_routine()

enum_sp_return_code sp_drop_routine ( THD thd,
enum_sp_type  type,
sp_name name 
)

Drops a stored routine.

Atomicity: The operation to drop a stored routine is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary, stored routines and table definition caches are in sync with operation state. Cache do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

Parameters
thdThread context.
typeStored routine type (PROCEDURE or FUNCTION)
nameStored routine name.
Returns
Error code. SP_OK is returned on success. Other SP_ constants are used to indicate about errors.

◆ sp_eval_expr()

bool sp_eval_expr ( THD thd,
bool  standalone,
Field result_field,
Item **  expr_item_ptr 
)

Evaluate an expression and store the result in the field.

Parameters
thdcurrent thread object
standaloneif true, thd->lex contains preparation and execution state of item, otherwise item is part of a query expression that is already in executing state.
result_fieldthe field to store the result
expr_item_ptrthe root item of the expression
Returns
false on success, true on error

◆ sp_exist_routines()

bool sp_exist_routines ( THD thd,
Table_ref routines,
bool  is_proc 
)

This is used by sql_acl.cc:mysql_routine_grant() and is used to find the routines in 'routines'.

Parameters
thdThread handler
routinesList of needles in the hay stack
is_procIndicates whether routines in the list are procedures or functions.
Return values
falseFound.
trueNot found

◆ sp_find_routine()

sp_head * sp_find_routine ( THD thd,
enum_sp_type  type,
sp_name name,
sp_cache **  cp,
bool  cache_only 
)

Obtain object representing stored procedure/function by its name from stored procedures cache and looking into data dictionary if needed.

Parameters
thdthread context
typetype of object (FUNCTION or PROCEDURE)
namename of procedure
cphash to look routine in
cache_onlyif true perform cache-only lookup (Don't look in data dictionary)
Return values
NonNULLpointer to sp_head object for the procedure
NULLin case of error.

◆ sp_finish_parsing()

void sp_finish_parsing ( THD thd)

Finish parsing of a stored program.

This is a counterpart of sp_start_parsing().

Parameters
thdThread context.

◆ sp_get_flags_for_command()

uint sp_get_flags_for_command ( LEX lex)
Parameters
lexLEX-object, representing an SQL-statement inside SP.
Returns
a combination of:
  • sp_head::MULTI_RESULTS: added if the 'cmd' is a command that might result in multiple result sets being sent back.
  • sp_head::CONTAINS_DYNAMIC_SQL: added if 'cmd' is one of PREPARE, EXECUTE, DEALLOCATE.

◆ sp_get_item_value()

String * sp_get_item_value ( THD thd,
Item item,
String str 
)

Return a string representation of the Item value.

Parameters
thdThread context.
itemThe item to evaluate
strString buffer for representation of the value.
Note
If the item has a string result type, the string is escaped according to its character set.
Return values
NULLon error
non-NULLa pointer to valid a valid string on success

◆ sp_prepare_func_item()

Item * sp_prepare_func_item ( THD thd,
bool  standalone,
Item **  it_addr 
)

Prepare an Item for evaluation (call of fix_fields).

Parameters
thdthread handler
standaloneif true, thd->lex is directly associated with item. Preparation and execution state will be changed and preparation data will be saved for later executions. If false, item is part of a larger query expression and no such state transitions should take place. It also means that such items cannot save preparation data.
it_addrpointer to item reference
Returns
pointer to prepared Item on success, NULL on error.

◆ sp_remove_not_own_routines()

void sp_remove_not_own_routines ( Query_tables_list prelocking_ctx)

Remove routines which are only indirectly used by statement from the set of routines used by this statement.

Parameters
prelocking_ctxPrelocking context of the statement

◆ sp_setup_routine()

sp_head * sp_setup_routine ( THD thd,
enum_sp_type  type,
sp_name name,
sp_cache **  cp 
)

Setup a cached routine for execution.

Parameters
thdthread context
typetype of object (FUNCTION or PROCEDURE)
namename of procedure
cphash to look routine in
Return values
NonNULLpointer to sp_head object for the procedure
NULLin case of error.

◆ sp_show_create_routine()

bool sp_show_create_routine ( THD thd,
enum_sp_type  type,
sp_name name 
)

Implement SHOW CREATE statement for stored routines.

The operation finds the stored routine object specified by name and then calls show_create_routine_from_dd_routine().

Parameters
thdThread context.
typeStored routine type (PROCEDURE or FUNCTION)
nameStored routine name.
Return values
falseon success
trueon error

◆ sp_start_parsing()

sp_head * sp_start_parsing ( THD thd,
enum_sp_type  sp_type,
sp_name sp_name 
)

Start parsing of a stored program.

This function encapsulates all the steps necessary to initialize sp_head to start parsing SP.

Every successful call of sp_start_parsing() must finish with sp_finish_parsing().

Parameters
thdThread context.
sp_typeThe stored program type
sp_nameThe stored program name
Returns
properly initialized sp_head-instance in case of success, or NULL is case of out-of-memory error.

◆ sp_update_routine()

bool sp_update_routine ( THD thd,
enum_sp_type  type,
sp_name name,
st_sp_chistics chistics 
)

Updates(Alter) a stored routine.

Atomicity: The operation to Update(Alter) a stored routine is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary and stored routines caches caches are in sync with operation state. Cache do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

Parameters
thdThread context.
typeStored routine type (PROCEDURE or FUNCTION)
nameStored routine name.
chisticsNew values of stored routine attributes to write.
Return values
falseSuccess.
trueError.

◆ sp_update_stmt_used_routines() [1/2]

void sp_update_stmt_used_routines ( THD thd,
Query_tables_list prelocking_ctx,
malloc_unordered_map< std::string, Sroutine_hash_entry * > *  src,
Table_ref belong_to_view 
)

Add contents of hash representing set of routines to the set of routines used by statement.

Parameters
thdThread context
prelocking_ctxPrelocking context of the statement
srcHash representing set from which routines will be added
belong_to_viewUppermost view which uses these routines, 0 if none
Note
It will also add elements to end of 'Query_tables_list::sroutines_list' list.

◆ sp_update_stmt_used_routines() [2/2]

void sp_update_stmt_used_routines ( THD thd,
Query_tables_list prelocking_ctx,
SQL_I_List< Sroutine_hash_entry > *  src,
Table_ref belong_to_view 
)

Add contents of list representing set of routines to the set of routines used by statement.

Parameters
thdThread context
prelocking_ctxPrelocking context of the statement
srcList representing set from which routines will be added
belong_to_viewUppermost view which uses these routines, 0 if none
Note
It will also add elements to end of 'Query_tables_list::sroutines_list' list.

◆ strnstr()

static bool strnstr ( const char *  str,
size_t  length,
const char *  substr 
)
static