MySQL 9.1.0
Source Code Documentation
|
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <string>
#include "field_types.h"
#include "lex_string.h"
#include "map_helpers.h"
#include "my_inttypes.h"
#include "mysql/udf_registration_types.h"
#include "sql/item.h"
#include "sql/sp_head.h"
#include "sql/sql_lex.h"
Go to the source code of this file.
Classes | |
class | Stored_routine_creation_ctx |
Stored_routine_creation_ctx – creation context of stored routines (stored procedures and functions). More... | |
class | Sroutine_hash_entry |
Structure that represents element in the set of stored routines used by statement or routine. More... | |
Namespaces | |
namespace | dd |
The version of the current data dictionary table definitions. | |
Macros | |
#define | SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL |
#define | SP_DEFAULT_SUID_MAPPING SP_IS_SUID |
Typedefs | |
using | sql_mode_t = uint64_t |
Functions | |
bool | sp_drop_db_routines (THD *thd, const dd::Schema &schema) |
Drop all routines in database 'db'. More... | |
bool | lock_db_routines (THD *thd, const dd::Schema &schema) |
Acquires exclusive metadata lock on all stored routines in the given database. More... | |
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. More... | |
sp_head * | sp_setup_routine (THD *thd, enum_sp_type type, sp_name *name, sp_cache **cp) |
Setup a cached routine for execution. 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... | |
bool | sp_exist_routines (THD *thd, Table_ref *procs, bool is_proc) |
This is used by sql_acl.cc:mysql_routine_grant() and is used to find the routines in 'routines'. More... | |
bool | sp_show_create_routine (THD *thd, enum_sp_type type, sp_name *name) |
Implement SHOW CREATE statement for stored routines. 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 *chistics, const char *definer_user, const char *definer_host, longlong created, longlong modified, Stored_program_creation_ctx *creation_ctx) |
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... | |
bool | sp_update_routine (THD *thd, enum_sp_type type, sp_name *name, st_sp_chistics *chistics) |
Updates(Alter) 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_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... | |
bool | sp_add_own_used_routine (Query_tables_list *prelocking_ctx, Query_arena *arena, Sroutine_hash_entry::entry_type type, sp_name *sp_name) |
Convenience wrapper around sp_add_used_routine() for most common case - stored procedure or function which are explicitly used by the 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... | |
const uchar * | sp_sroutine_key (const uchar *ptr, size_t *plen) |
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) |
sp_head * | sp_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... | |
Table_ref * | sp_add_to_query_tables (THD *thd, LEX *lex, const char *db, const char *name) |
Item * | sp_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... | |
String * | sp_get_item_value (THD *thd, Item *item, String *str) |
Return a string representation of the Item value. More... | |
Variables | |
static const uint | MYSQL_STORED_ROUTINE_BODY_LENGTH = 4294967295U |
static const int | MYSQL_STORED_ROUTINE_COMMENT_LENGTH = 65535 |
#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL |
#define SP_DEFAULT_SUID_MAPPING SP_IS_SUID |
using sql_mode_t = uint64_t |
anonymous enum |
enum enum_sp_return_code |
|
strong |
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 * | chistics, | ||
const char * | definer_user, | ||
const char * | definer_host, | ||
longlong | created, | ||
longlong | modified, | ||
Stored_program_creation_ctx * | creation_ctx | ||
) |
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 | ||
) |
bool lock_db_routines | ( | THD * | thd, |
const dd::Schema & | schema | ||
) |
Acquires exclusive metadata lock on all stored routines in the given database.
thd | Thread handler |
schema | Schema object |
false | Success |
true | Failure |
|
inline |
Convenience wrapper around sp_add_used_routine() for most common case - stored procedure or function which are explicitly used by the statement.
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.
prelocking_ctx | Prelocking context of the statement |
arena | Arena in which memory for new element of the set will be allocated |
type | Routine type (one of FUNCTION/PROCEDURE/ TRIGGER ...) |
db | Database name |
db_length | Database name length |
name | Routine name |
name_length | Routine name length |
lowercase_db | Indicates whether db needs to be lowercased when constructing key. |
name_normalize_type | Indicates if names needs to be normalized (lowercased / accent needs to be removed). |
own_routine | Indicates whether routine is explicitly or implicitly used. |
belong_to_view | Uppermost view which uses this routine (nullptr if routine is not used by view) |
True | - new element was added. |
False | - element was not added (because it is already present in the set). |
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.
[in] | thd | Thread context. |
[in] | type | Type of object (FUNCTION or PROCEDURE). |
[in] | name | Name of routine. |
[in] | lookup_only | Only 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] | sp | Pointer to sp_head object for routine, NULL if routine was not found. |
SP_OK | Either routine is found and was successfully loaded into cache or it does not exist. |
non-SP_OK | Error while loading routine from DD table. |
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.
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().
true | bad name |
false | name is ok |
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.
thd | Thread context. | |
sp | Stored routine object to store. | |
definer | Definer of the SP. | |
if_not_exists | True if 'IF NOT EXISTS' clause was specified. | |
[out] | sp_already_exists | Set to true if routine already exists. |
false | Success. |
true | Error. |
bool sp_drop_db_routines | ( | THD * | thd, |
const dd::Schema & | schema | ||
) |
Drop all routines in database 'db'.
thd | Thread context. |
schema | Schema object. |
false | Success |
true | Error |
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.
thd | Thread context. |
type | Stored routine type (PROCEDURE or FUNCTION) |
name | Stored routine name. |
Evaluate an expression and store the result in the field.
thd | current thread object |
standalone | if 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_field | the field to store the result |
expr_item_ptr | the root item of the expression |
This is used by sql_acl.cc:mysql_routine_grant() and is used to find the routines in 'routines'.
thd | Thread handler |
routines | List of needles in the hay stack |
is_proc | Indicates whether routines in the list are procedures or functions. |
false | Found. |
true | Not found |
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.
thd | thread context |
type | type of object (FUNCTION or PROCEDURE) |
name | name of procedure |
cp | hash to look routine in |
cache_only | if true perform cache-only lookup (Don't look in data dictionary) |
NonNULL | pointer to sp_head object for the procedure |
NULL | in case of error. |
void sp_finish_parsing | ( | THD * | thd | ) |
Finish parsing of a stored program.
This is a counterpart of sp_start_parsing().
thd | Thread context. |
uint sp_get_flags_for_command | ( | LEX * | lex | ) |
lex | LEX-object, representing an SQL-statement inside SP. |
Return a string representation of the Item value.
thd | Thread context. |
item | The item to evaluate |
str | String buffer for representation of the value. |
NULL | on error |
non-NULL | a pointer to valid a valid string on success |
Prepare an Item for evaluation (call of fix_fields).
thd | thread handler |
standalone | if 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_addr | pointer to item reference |
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.
prelocking_ctx | Prelocking context of the statement |
sp_head * sp_setup_routine | ( | THD * | thd, |
enum_sp_type | type, | ||
sp_name * | name, | ||
sp_cache ** | cp | ||
) |
Setup a cached routine for execution.
thd | thread context |
type | type of object (FUNCTION or PROCEDURE) |
name | name of procedure |
cp | hash to look routine in |
NonNULL | pointer to sp_head object for the procedure |
NULL | in case of error. |
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().
thd | Thread context. |
type | Stored routine type (PROCEDURE or FUNCTION) |
name | Stored routine name. |
false | on success |
true | on error |
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().
thd | Thread context. |
sp_type | The stored program type |
sp_name | The stored program name |
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.
thd | Thread context. |
type | Stored routine type (PROCEDURE or FUNCTION) |
name | Stored routine name. |
chistics | New values of stored routine attributes to write. |
false | Success. |
true | Error. |
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.
thd | Thread context |
prelocking_ctx | Prelocking context of the statement |
src | Hash representing set from which routines will be added |
belong_to_view | Uppermost view which uses these routines, 0 if none |
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.
thd | Thread context |
prelocking_ctx | Prelocking context of the statement |
src | List representing set from which routines will be added |
belong_to_view | Uppermost view which uses these routines, 0 if none |
|
static |
|
static |