My Project
|
#include <sp_head.h>
Public Types | |
enum | { HAS_RETURN = 1, MULTI_RESULTS = 8, CONTAINS_DYNAMIC_SQL = 16, IS_INVOKED = 32, HAS_SET_AUTOCOMMIT_STMT = 64, HAS_COMMIT_OR_ROLLBACK = 128, LOG_SLOW_STATEMENTS = 256, LOG_GENERAL_LOG = 512, HAS_SQLCOM_RESET = 1024, HAS_SQLCOM_FLUSH = 2048, MODIFIES_DATA = 4096 } |
Public Member Functions | |
bool | is_invoked () const |
Is this routine being executed? | |
ulong | sp_cache_version () const |
void | set_sp_cache_version (ulong sp_cache_version) |
Set the value of the SP cache version. | |
Stored_program_creation_ctx * | get_creation_ctx () |
void | set_creation_ctx (Stored_program_creation_ctx *creation_ctx) |
void | set_body_start (THD *thd, const char *begin_ptr) |
Set the body-definition start position. | |
void | set_body_end (THD *thd) |
Set the statement-definition (body-definition) end position. | |
bool | execute_trigger (THD *thd, const LEX_STRING *db_name, const LEX_STRING *table_name, GRANT_INFO *grant_info) |
bool | execute_function (THD *thd, Item **args, uint argcount, Field *return_fld) |
bool | execute_procedure (THD *thd, List< Item > *args) |
bool | show_create_routine (THD *thd, enum_sp_type type) |
bool | add_instr (THD *thd, sp_instr *instr) |
bool | modifies_data () const |
uint | instructions () |
sp_instr * | last_instruction () |
bool | reset_lex (THD *thd) |
bool | restore_lex (THD *thd) |
char * | name (uint *lenp=0) const |
char * | create_string (THD *thd, ulong *lenp) |
Field * | create_result_field (uint field_max_length, const char *field_name, TABLE *table) |
void | set_info (longlong created, longlong modified, st_sp_chistics *chistics, sql_mode_t sql_mode) |
void | set_definer (const char *definer, uint definerlen) |
void | set_definer (const LEX_STRING *user_name, const LEX_STRING *host_name) |
void | optimize () |
void | add_mark_lead (uint ip, List< sp_instr > *leads) |
sp_instr * | get_instr (uint i) |
bool | add_used_tables_to_table_list (THD *thd, TABLE_LIST ***query_tables_last_ptr, TABLE_LIST *belong_to_view) |
bool | is_not_allowed_in_function (const char *where) |
bool | show_routine_code (THD *thd) |
void | propagate_attributes (Query_tables_list *prelocking_ctx) |
sp_pcontext * | get_root_parsing_context () const |
MEM_ROOT * | get_persistent_mem_root () const |
MEM_ROOT * | get_current_mem_root () const |
bool | check_show_access (THD *thd, bool *full_access) |
bool | set_security_ctx (THD *thd, Security_context **save_ctx) |
Static Public Member Functions | |
static void * | operator new (size_t size) throw () |
static void | operator delete (void *ptr, size_t size) throw () |
Public Attributes | |
enum_sp_type | m_type |
Stored program type. | |
uint | m_flags |
Stored program flags. | |
Create_field | m_return_field_def |
sp_parser_data | m_parser_data |
Attributes used during the parsing stage only. | |
st_sp_chistics * | m_chistics |
Stored program characteristics. | |
sql_mode_t | m_sql_mode |
LEX_STRING | m_qname |
Fully qualified name (<db name>="">.<sp name>="">). | |
bool | m_explicit_name |
Prepend the db name? */. | |
LEX_STRING | m_db |
LEX_STRING | m_name |
LEX_STRING | m_params |
LEX_STRING | m_body |
LEX_STRING | m_body_utf8 |
LEX_STRING | m_defstr |
LEX_STRING | m_definer_user |
LEX_STRING | m_definer_host |
longlong | m_created |
longlong | m_modified |
ulong | m_recursion_level |
Recursion level of the current SP instance. The levels are numbered from 0. | |
sp_head * | m_next_cached_sp |
sp_head * | m_first_instance |
Pointer to the first element of the above list. | |
sp_head * | m_first_free_instance |
sp_head * | m_last_cached_sp |
HASH | m_sroutines |
Security_context | m_security_ctx |
SQL_I_List< SQL_I_List < Item_trigger_field > > | m_list_of_trig_fields_item_lists |
SQL_I_List< Item_trigger_field > | m_cur_instr_trig_field_items |
st_trg_chistics | m_trg_chistics |
Trigger characteristics. | |
class Table_triggers_list * | m_trg_list |
The Table_triggers_list instance, where this trigger belongs to. | |
Friends | |
sp_head * | sp_start_parsing (THD *, enum_sp_type, sp_name *) |
sp_head represents one instance of a stored program. It might be of any type (stored procedure, function, trigger, event).
anonymous enum |
Possible values of m_flags
bool sp_head::add_instr | ( | THD * | thd, |
sp_instr * | instr | ||
) |
Add instruction to SP.
thd | Thread context. |
instr | Instruction. |
void sp_head::add_mark_lead | ( | uint | ip, |
List< sp_instr > * | leads | ||
) |
Helper used during flow analysis during code optimization. See the implementation of opt_mark()
.
ip | the instruction to add to the leads list |
leads | the list of remaining paths to explore in the graph that represents the code, during flow analysis. |
bool sp_head::add_used_tables_to_table_list | ( | THD * | thd, |
TABLE_LIST *** | query_tables_last_ptr, | ||
TABLE_LIST * | belong_to_view | ||
) |
Add tables used by routine to the table list.
Converts multi-set of tables used by this routine to table list and adds this list to the end of table list specified by 'query_tables_last_ptr'.
Elements of list will be allocated in PS memroot, so this list will be persistent between PS executions.
[in] | thd | Thread context |
[in,out] | query_tables_last_ptr | Pointer to the next_global member of last element of the list where tables will be added (or to its root). |
[in] | belong_to_view | Uppermost view which uses this routine, NULL if none. |
true | if some elements were added |
false | otherwise. |
bool sp_head::check_show_access | ( | THD * | thd, |
bool * | full_access | ||
) |
Check if a user has access right to a SP.
thd | Thread context. | |
[out] | full_access | Set to 1 if the user has SELECT to the 'mysql.proc' table or is the owner of the stored program. |
Field * sp_head::create_result_field | ( | uint | field_max_length, |
const char * | field_name, | ||
TABLE * | table | ||
) |
Create Field-object corresponding to the RETURN field of a stored function. This operation makes sense for stored functions only.
field_max_length | the max length (in the sense of Item classes). |
field_name | the field name (item name). |
table | the field's table. |
bool sp_head::execute_function | ( | THD * | thd, |
Item ** | args, | ||
uint | argcount, | ||
Field * | return_fld | ||
) |
Execute a function.
thd | Thread context. |
argp | Passed arguments (these are items from containing statement?) |
argcount | Number of passed arguments. We need to check if this is correct. |
return_value_fld | Save result here. |
bool sp_head::execute_procedure | ( | THD * | thd, |
List< Item > * | args | ||
) |
Execute a procedure.
The function does the following steps:
thd | Thread context. |
args | List of values passed as arguments. |
bool sp_head::execute_trigger | ( | THD * | thd, |
const LEX_STRING * | db_name, | ||
const LEX_STRING * | table_name, | ||
GRANT_INFO * | grant_info | ||
) |
Execute trigger stored program.
thd | Thread context |
db | database name |
table | table name |
grant_info | GRANT_INFO structure to be filled with information about definer's privileges on subject table |
MEM_ROOT* sp_head::get_current_mem_root | ( | ) | const [inline] |
sp_instr* sp_head::get_instr | ( | uint | i | ) | [inline] |
Get SP-instruction at given index.
NOTE: it is important to have *unsigned* int here, sometimes we get (-1) passed here, so it get's converted to MAX_INT, and the result of the function call is NULL.
MEM_ROOT* sp_head::get_persistent_mem_root | ( | ) | const [inline] |
sp_pcontext* sp_head::get_root_parsing_context | ( | ) | const [inline] |
bool sp_head::is_not_allowed_in_function | ( | const char * | where | ) | [inline] |
Check if this stored routine contains statements disallowed in a stored function or trigger, and set an appropriate error message if this is the case.
bool sp_head::modifies_data | ( | ) | const [inline] |
Returns true if any substatement in the routine directly (not through another routine) modifies data/changes table.
void sp_head::optimize | ( | ) |
Do some minimal optimization of the code:
This is the main mark and move loop; it relies on the following methods in sp_instr and its subclasses:
bool sp_head::reset_lex | ( | THD * | thd | ) |
Reset LEX-object during parsing, before we parse a sub statement.
thd | Thread context. |
bool sp_head::restore_lex | ( | THD * | thd | ) |
Restore LEX-object during parsing, after we have parsed a sub statement.
thd | Thread context. |
bool sp_head::set_security_ctx | ( | THD * | thd, |
Security_context ** | save_ctx | ||
) |
Change routine security context, and check if there is an EXECUTE privilege in new context. If there is no EXECUTE privilege, change the context back and return an error.
thd | Thread context. | |
[out] | save_ctx | Where to save the old security context. |
bool sp_head::show_create_routine | ( | THD * | thd, |
enum_sp_type | type | ||
) |
Implement SHOW CREATE statement for stored routines.
thd | Thread context. |
type | Stored routine type (SP_TYPE_PROCEDURE or SP_TYPE_FUNCTION) |
bool sp_head::show_routine_code | ( | THD * | thd | ) |
Return the routine instructions as a result set.
ulong sp_head::sp_cache_version | ( | ) | const [inline] |
Get the value of the SP cache version, as remembered when the routine was inserted into the cache.
sp_head* sp_start_parsing | ( | THD * | , |
enum_sp_type | , | ||
sp_name * | |||
) | [friend] |
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 progam name |
List of all the Item_trigger_field items created while parsing sp instruction. After parsing, in add_instr method this list is moved to per instruction Item_trigger_field list "sp_lex_instr::m_trig_field_list".
Pointer to the first free (non-INVOKED) routine in the list of cached instances for this SP. This pointer is set only for the first SP in the list of instances (see above m_first_cached_sp pointer). The pointer equal to 0 if we have no free instances. For non-first instance value of this pointer meaningless (point to itself);
Pointer to the last element in the list of instances of the SP. For non-first instance value of this pointer meaningless (point to itself);
List of item (Item_trigger_field objects)'s lists representing fields in old/new version of row in trigger. We use this list for checking whether all such fields are valid or not at trigger creation time and for binding these fields to TABLE object at table open (although for latter pointer to table being opened is probably enough).
A list of diferent recursion level instances for the same procedure. For every recursion level we have a sp_head instance. This instances connected in the list. The list ordered by increasing recursion level (m_recursion_level).
Definition of the RETURN-field (from the RETURNS-clause). It's used (and valid) for stored functions only.
sql_mode_t sp_head::m_sql_mode |
The value of sql_mode system variable at the CREATE-time.
It should be stored along with the character sets in the Stored_program_creation_ctx.
HASH sp_head::m_sroutines |
Set containing names of stored routines used by this routine. Note that unlike elements of similar set for statement elements of this set are not linked in one list. Because of this we are able save memory by using for this set same objects that are used in 'sroutines' sets for statements of which this stored routine consists.