MySQL  8.0.17
Source Code Documentation
Runtime Environment

Modules

 Event Scheduler
 
 Mysys - low level utilities for MySQL
 
 Serialized Dictionary Information
 Code to serialize and deserialize data dictionary objects, and for storing and retrieving the serialized representation from files or tablespaces.
 
 Server time functions
 
 Stored Routines
 

Classes

class  Kill_non_super_conn
 This class implements callback function used by killall_non_super_threads to kill all threads that do not have the SUPER privilege. More...
 
class  Parser_oom_handler
 

Macros

#define SP_COM_STRING(LP)
 
#define MY_YACC_INIT   1000
 
#define MY_YACC_MAX   32000
 

Functions

static void sql_kill (THD *thd, my_thread_id id, bool only_kill_query)
 
bool command_satisfy_acl_cache_requirement (unsigned command)
 
bool all_tables_not_ok (THD *thd, TABLE_LIST *tables)
 Returns true if all tables should be ignored. More...
 
bool check_database_filters (THD *thd, const char *db, enum_sql_command sql_cmd)
 Checks whether the event for the given database, db, should be ignored or not. More...
 
bool some_non_temp_table_to_be_updated (THD *thd, TABLE_LIST *tables)
 
bool stmt_causes_implicit_commit (const THD *thd, uint mask)
 Returns whether the command in thd->lex->sql_command should cause an implicit commit. More...
 
void init_sql_command_flags (void)
 
bool sqlcom_can_generate_row_events (enum enum_sql_command command)
 
bool is_update_query (enum enum_sql_command command)
 
bool is_explainable_query (enum enum_sql_command command)
 
bool is_log_table_write_query (enum enum_sql_command command)
 Check if a sql command is allowed to write to log tables. More...
 
static bool sqlcom_needs_autocommit_off (const LEX *lex)
 Check if statement (typically DDL) needs auto-commit mode temporarily turned off. More...
 
void execute_init_command (THD *thd, LEX_STRING *init_command, mysql_rwlock_t *var_lock)
 
void free_items (Item *item)
 
void cleanup_items (Item *item)
 This works because items are allocated with (*THR_MALLOC)->Alloc(). More...
 
bool do_command (THD *thd)
 Read one command from connection and execute it (query or simple command). More...
 
static bool deny_updates_if_read_only_option (THD *thd, TABLE_LIST *all_tables)
 Determine if an attempt to update a non-temporary table while the read-only option was enabled has been made. More...
 
static bool is_timer_applicable_to_statement (THD *thd)
 Check whether max statement time is applicable to statement or not. More...
 
static void check_secondary_engine_statement (THD *thd, Parser_state *parser_state, const char *query_string, size_t query_length)
 Check if a statement should be restarted in another storage engine, and restart the statement if needed. More...
 
bool dispatch_command (THD *thd, const COM_DATA *com_data, enum enum_server_command command)
 Perform one connection-level (COM_XXXX) command. More...
 
bool shutdown (THD *thd, enum mysql_enum_shutdown_level level)
 Shutdown the mysqld server. More...
 
int prepare_schema_table (THD *thd, LEX *lex, Table_ident *table_ident, enum enum_schema_tables schema_table_idx)
 Create a TABLE_LIST object for an INFORMATION_SCHEMA table. More...
 
bool alloc_query (THD *thd, const char *packet, size_t packet_length)
 Read query from packet and store in thd->query. More...
 
static bool sp_process_definer (THD *thd)
 
static bool lock_tables_open_and_lock_tables (THD *thd, TABLE_LIST *tables)
 Auxiliary call that opens and locks tables for LOCK TABLES statement and initializes the list of locked tables. More...
 
static void binlog_gtid_end_transaction (THD *thd)
 This is a wrapper for MYSQL_BIN_LOG::gtid_end_transaction. More...
 
int mysql_execute_command (THD *thd, bool first_level)
 Execute command saved in thd and lex->sql_command. More...
 
static bool try_acquire_high_prio_shared_mdl_lock (THD *thd, TABLE_LIST *table, bool can_deadlock)
 Try acquire high priority share metadata lock on a table (with optional wait for conflicting locks to go away). More...
 
bool show_precheck (THD *thd, LEX *lex, bool lock)
 Do special checking for SHOW statements. More...
 
bool execute_show (THD *thd, TABLE_LIST *all_tables)
 
bool my_yyoverflow (short **yyss, YYSTYPE **yyvs, YYLTYPE **yyls, ulong *yystacksize)
 
void mysql_reset_thd_for_next_command (THD *thd)
 Reset the part of THD responsible for the state of command processing. More...
 
bool create_select_for_variable (Parse_context *pc, const char *var_name)
 Create a select to return the same output as 'SELECT @var_name'. More...
 
void mysql_parse (THD *thd, Parser_state *parser_state)
 Parse a query. More...
 
bool mysql_test_parse_for_slave (THD *thd)
 Usable by the replication SQL thread only: just parse a query to know if it can be ignored because of replicate-*-table rules. More...
 
void add_to_list (SQL_I_List< ORDER > &list, ORDER *order)
 save order by and tables in own lists. More...
 
static bool reparse_common_table_expr (THD *thd, const LEX_STRING &text, uint text_offset, PT_subquery **node)
 Produces a PT_subquery object from a subquery's text. More...
 
bool push_new_name_resolution_context (Parse_context *pc, TABLE_LIST *left_op, TABLE_LIST *right_op)
 Push a new name resolution context for a JOIN ... More...
 
void add_join_on (TABLE_LIST *b, Item *expr)
 Add an ON condition to the second operand of a JOIN ... More...
 
const CHARSET_INFOget_bin_collation (const CHARSET_INFO *cs)
 
static uint kill_one_thread (THD *thd, my_thread_id id, bool only_kill_query)
 kill on thread. More...
 
void killall_non_super_threads (THD *thd)
 
bool prepare_index_and_data_dir_path (THD *thd, const char **data_file_name, const char **index_file_name, const char *table_name)
 prepares the index and data directory path. More...
 
int append_file_to_dir (THD *thd, const char **filename_ptr, const char *table_name)
 If pointer is not a null pointer, append filename to it. More...
 
Comp_creatorcomp_eq_creator (bool invert)
 
Comp_creatorcomp_equal_creator (bool invert)
 
Comp_creatorcomp_ge_creator (bool invert)
 
Comp_creatorcomp_gt_creator (bool invert)
 
Comp_creatorcomp_le_creator (bool invert)
 
Comp_creatorcomp_lt_creator (bool invert)
 
Comp_creatorcomp_ne_creator (bool invert)
 
Itemall_any_subquery_creator (Item *left_expr, chooser_compare_func_creator cmp, bool all, SELECT_LEX *select_lex)
 Construct ALL/ANY/SOME subquery Item. More...
 
void create_table_set_open_action_and_adjust_tables (LEX *lex)
 Set proper open mode and table type for element representing target table of CREATE TABLE statement, also adjust statement table list if necessary. More...
 
void get_default_definer (THD *thd, LEX_USER *definer)
 Set the specified definer to the default value, which is the current user in the thread. More...
 
LEX_USERcreate_default_definer (THD *thd)
 Create default definer for the specified THD. More...
 
LEX_USERget_current_user (THD *thd, LEX_USER *user)
 Retuns information about user or current user. More...
 
static bool check_string_byte_length (const LEX_CSTRING &str, const char *err_msg, size_t max_byte_length)
 Check that byte length of a string does not exceed some limit. More...
 
bool check_string_char_length (const LEX_CSTRING &str, const char *err_msg, size_t max_char_length, const CHARSET_INFO *cs, bool no_error)
 
int test_if_data_home_dir (const char *dir)
 
bool check_host_name (const LEX_CSTRING &str)
 Check that host name string is valid. More...
 
bool parse_sql (THD *thd, Parser_state *parser_state, Object_creation_ctx *creation_ctx)
 Transform an SQL statement into an AST that is ready for resolving, using the supplied parser state and object creation context. More...
 
void THD::reset_for_next_command ()
 
bool Alter_info::add_field (THD *thd, const LEX_STRING *field_name, enum enum_field_types type, const char *length, const char *decimal, uint type_modifier, Item *default_value, Item *on_update_value, LEX_CSTRING *comment, const char *change, List< String > *interval_list, const CHARSET_INFO *cs, bool has_explicit_collation, uint uint_geom_type, Value_generator *gcol_info, Value_generator *default_val_expr, const char *opt_after, Nullable< gis::srid_t > srid, Sql_check_constraint_spec_list *check_cons_list, dd::Column::enum_hidden_type hidden, bool is_array=false)
 Store field definition for create. More...
 
bool PT_common_table_expr::make_subquery_node (THD *thd, PT_subquery **node)
 
bool SELECT_LEX::find_common_table_expr (THD *thd, Table_ident *table_id, TABLE_LIST *tl, Parse_context *pc, bool *found)
 Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name, *tl', and the matched with-list-element. More...
 
bool PT_with_clause::lookup (TABLE_LIST *tl, PT_common_table_expr **found)
 Looks up a table reference into the list of CTEs. More...
 
bool PT_common_table_expr::match_table_ref (TABLE_LIST *tl, bool in_self, bool *found)
 
TABLE_LISTSELECT_LEX::add_table_to_list (THD *thd, Table_ident *table, const char *alias, ulong table_options, thr_lock_type flags=TL_UNLOCK, enum_mdl_type mdl_type=MDL_SHARED_READ, List< Index_hint > *hints=0, List< String > *partition_names=0, LEX_STRING *option=0, Parse_context *pc=NULL)
 Add a table to list of used tables. More...
 
bool SELECT_LEX::init_nested_join (THD *thd)
 Initialize a new table list for a nested join. More...
 
TABLE_LISTSELECT_LEX::end_nested_join ()
 End a nested join table list. More...
 
TABLE_LISTSELECT_LEX::nest_last_join (THD *thd, size_t table_cnt=2)
 Nest last join operations. More...
 
bool SELECT_LEX::add_joined_table (TABLE_LIST *table)
 Add a table to the current join list. More...
 
TABLE_LISTSELECT_LEX::convert_right_join ()
 Convert a right join into equivalent left join. More...
 
void SELECT_LEX::set_lock_for_table (const Lock_descriptor &descriptor, TABLE_LIST *table)
 
void SELECT_LEX::set_lock_for_tables (thr_lock_type lock_type)
 Set lock for all tables in current query block. More...
 
bool SELECT_LEX_UNIT::add_fake_select_lex (THD *thd)
 Create a fake SELECT_LEX for a unit. More...
 

Variables

const LEX_STRING command_name []
 
uint sql_command_flags [SQLCOM_END+1]
 Mark all commands that somehow changes a table. More...
 
uint server_command_flags [COM_END+1]
 

Detailed Description

Macro Definition Documentation

◆ MY_YACC_INIT

#define MY_YACC_INIT   1000

◆ MY_YACC_MAX

#define MY_YACC_MAX   32000

◆ SP_COM_STRING

#define SP_COM_STRING (   LP)
Value:
((LP)->sql_command == SQLCOM_CREATE_SPFUNCTION || \
(LP)->sql_command == SQLCOM_ALTER_FUNCTION || \
(LP)->sql_command == SQLCOM_SHOW_CREATE_FUNC || \
(LP)->sql_command == SQLCOM_DROP_FUNCTION \
? "FUNCTION" \
: "PROCEDURE")
Definition: my_sqlcommand.h:89
Definition: my_sqlcommand.h:142
Definition: my_sqlcommand.h:136
Definition: my_sqlcommand.h:140

Function Documentation

◆ add_fake_select_lex()

bool SELECT_LEX_UNIT::add_fake_select_lex ( THD thd)

Create a fake SELECT_LEX for a unit.

The method create a fake SELECT_LEX object for a unit. This object is created for any union construct containing a union operation and also for any single select union construct of the form

  (SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ...

or of the form

  (SELECT ... ORDER BY LIMIT n) ORDER BY ...
Parameters
thdthread handle
Note
The object is used to retrieve rows from the temporary table where the result on the union is obtained.
Return values
1on failure to create the object
0on success

◆ add_field()

bool Alter_info::add_field ( THD thd,
const LEX_STRING field_name,
enum enum_field_types  type,
const char *  length,
const char *  decimals,
uint  type_modifier,
Item default_value,
Item on_update_value,
LEX_CSTRING comment,
const char *  change,
List< String > *  interval_list,
const CHARSET_INFO cs,
bool  has_explicit_collation,
uint  uint_geom_type,
Value_generator gcol_info,
Value_generator default_val_expr,
const char *  opt_after,
Nullable< gis::srid_t srid,
Sql_check_constraint_spec_list col_check_const_spec_list,
dd::Column::enum_hidden_type  hidden,
bool  is_array = false 
)

Store field definition for create.

Parameters
thdThe thread handler.
field_nameThe field name.
typeThe type of the field.
lengthThe length of the field or NULL.
decimalsThe length of a decimal part or NULL.
type_modifierType modifiers & constraint flags of the field.
default_valueThe default value or NULL.
on_update_valueThe ON UPDATE expression or NULL.
commentThe comment.
changeThe old column name (if renaming) or NULL.
interval_listThe list of ENUM/SET values or NULL.
csThe character set of the field.
has_explicit_collationColumn has an explicit COLLATE attribute.
uint_geom_typeThe GIS type of the field.
gcol_infoThe generated column data or NULL.
default_val_exprThe expression for generating default values, if there is one, or nullptr.
opt_afterThe name of the field to add after or the
See also
first_keyword pointer to insert first.
Parameters
sridThe SRID for this column (only relevant if this is a geometry column).
col_check_const_spec_listList of column check constraints.
hiddenWhether or not this field shoud be hidden.
is_arrayWhether it's a typed array field
Returns
Return 0 if ok

◆ add_join_on()

void add_join_on ( TABLE_LIST b,
Item expr 
)

Add an ON condition to the second operand of a JOIN ...

ON.

Add an ON condition to the right operand of a JOIN ... ON clause.

Parameters
bthe second operand of a JOIN ... ON
exprthe condition to be added to the ON clause

◆ add_joined_table()

bool SELECT_LEX::add_joined_table ( TABLE_LIST table)

Add a table to the current join list.

The function puts a table in front of the current join list of SELECT_LEX object. Thus, joined tables are put into this list in the reverse order (the most outer join operation follows first).

Parameters
tableThe table to add.
Returns
false if success, true if error (OOM).

◆ add_table_to_list()

TABLE_LIST * SELECT_LEX::add_table_to_list ( THD thd,
Table_ident table_name,
const char *  alias,
ulong  table_options,
thr_lock_type  lock_type = TL_UNLOCK,
enum_mdl_type  mdl_type = MDL_SHARED_READ,
List< Index_hint > *  index_hints_arg = 0,
List< String > *  partition_names = 0,
LEX_STRING option = 0,
Parse_context pc = NULL 
)

Add a table to list of used tables.

Parameters
thdCurrent session.
table_nameTable to add
aliasalias for table (or null if no alias)
table_optionsA set of the following bits:
  • TL_OPTION_UPDATING : Table will be updated
  • TL_OPTION_FORCE_INDEX : Force usage of index
  • TL_OPTION_ALIAS : an alias in multi table DELETE
lock_typeHow table should be locked
mdl_typeType of metadata lock to acquire on the table.
index_hints_arg
partition_names
option
pcCurrent parsing context, if available.
Returns
Pointer to TABLE_LIST element added to the total table list
Return values
0Error

◆ add_to_list()

void add_to_list ( SQL_I_List< ORDER > &  list,
ORDER order 
)

save order by and tables in own lists.

◆ all_any_subquery_creator()

Item* all_any_subquery_creator ( Item left_expr,
chooser_compare_func_creator  cmp,
bool  all,
SELECT_LEX select_lex 
)

Construct ALL/ANY/SOME subquery Item.

Parameters
left_exprpointer to left expression
cmpcompare function creator
alltrue if we create ALL subquery
select_lexpointer on parsed subquery structure
Returns
constructed Item (or 0 if out of memory)

◆ all_tables_not_ok()

bool all_tables_not_ok ( THD thd,
TABLE_LIST tables 
)

Returns true if all tables should be ignored.

◆ alloc_query()

bool alloc_query ( THD thd,
const char *  packet,
size_t  packet_length 
)

Read query from packet and store in thd->query.

Used in COM_QUERY and COM_STMT_PREPARE.

Sets the following THD variables:

  • query
  • query_length
Return values
falseok
trueerror; In this case thd->fatal_error is set

◆ append_file_to_dir()

int append_file_to_dir ( THD thd,
const char **  filename_ptr,
const char *  table_name 
)

If pointer is not a null pointer, append filename to it.

◆ binlog_gtid_end_transaction()

static void binlog_gtid_end_transaction ( THD thd)
inlinestatic

This is a wrapper for MYSQL_BIN_LOG::gtid_end_transaction.

For normal statements, the function gtid_end_transaction is called in the commit handler. However, if the statement is filtered out or not written to the binary log, the commit handler is not invoked. Therefore, this wrapper calls gtid_end_transaction in case the current statement is committing but was not written to the binary log. (The function gtid_end_transaction ensures that gtid-related end-of-transaction operations are performed; this includes generating an empty transaction and calling Gtid_state::update_gtids_impl.)

Parameters
thdThread (session) context.

◆ check_database_filters()

bool check_database_filters ( THD thd,
const char *  db,
enum_sql_command  sql_cmd 
)
inline

Checks whether the event for the given database, db, should be ignored or not.

This is done by checking whether there are active rules in ignore_db or in do_db containers. If there are, then check if there is a match, if not then check the wild_do rules.

NOTE: This means that when using this function replicate-do-db and replicate-ignore-db take precedence over wild do rules.

Parameters
thdThread handle.
dbDatabase name used while evaluating the filtering rules.
sql_cmdRepresents the current query that needs to be verified against the database filter rules.
Returns
true Query should not be filtered out from the execution. false Query should be filtered out from the execution.

◆ check_host_name()

bool check_host_name ( const LEX_CSTRING str)

Check that host name string is valid.

Parameters
[in]strstring to be checked
Returns
Operation status
Return values
falsehost name is ok
truehost name string is longer than max_length or has invalid symbols

◆ check_secondary_engine_statement()

static void check_secondary_engine_statement ( THD thd,
Parser_state parser_state,
const char *  query_string,
size_t  query_length 
)
static

Check if a statement should be restarted in another storage engine, and restart the statement if needed.

Parameters
thdthe session
parser_statethe parser state
query_stringthe query to reprepare and execute
query_lengththe length of the query

◆ check_string_byte_length()

static bool check_string_byte_length ( const LEX_CSTRING str,
const char *  err_msg,
size_t  max_byte_length 
)
static

Check that byte length of a string does not exceed some limit.

Parameters
strstring to be checked
err_msgerror message to be displayed if the string is too long
max_byte_lengthmax length
Return values
falsethe passed string is not longer than max_length
truethe passed string is longer than max_length

NOTE The function is not used in existing code but can be useful later?

◆ check_string_char_length()

bool check_string_char_length ( const LEX_CSTRING str,
const char *  err_msg,
size_t  max_char_length,
const CHARSET_INFO cs,
bool  no_error 
)

◆ cleanup_items()

void cleanup_items ( Item item)

This works because items are allocated with (*THR_MALLOC)->Alloc().

Note
The function also handles null pointers (empty list).

◆ command_satisfy_acl_cache_requirement()

bool command_satisfy_acl_cache_requirement ( unsigned  command)

◆ comp_eq_creator()

Comp_creator* comp_eq_creator ( bool  invert)

◆ comp_equal_creator()

Comp_creator* comp_equal_creator ( bool  invert)

◆ comp_ge_creator()

Comp_creator* comp_ge_creator ( bool  invert)

◆ comp_gt_creator()

Comp_creator* comp_gt_creator ( bool  invert)

◆ comp_le_creator()

Comp_creator* comp_le_creator ( bool  invert)

◆ comp_lt_creator()

Comp_creator* comp_lt_creator ( bool  invert)

◆ comp_ne_creator()

Comp_creator* comp_ne_creator ( bool  invert)

◆ convert_right_join()

TABLE_LIST * SELECT_LEX::convert_right_join ( )

Convert a right join into equivalent left join.

The function takes the current join list t[0],t[1] ... and effectively converts it into the list t[1],t[0] ... Although the outer_join flag for the new nested table contains JOIN_TYPE_RIGHT, it will be handled as the inner table of a left join operation.

EXAMPLES

  SELECT * FROM t1 RIGHT JOIN t2 ON on_expr =>
    SELECT * FROM t2 LEFT JOIN t1 ON on_expr

  SELECT * FROM t1,t2 RIGHT JOIN t3 ON on_expr =>
    SELECT * FROM t1,t3 LEFT JOIN t2 ON on_expr

  SELECT * FROM t1,t2 RIGHT JOIN (t3,t4) ON on_expr =>
    SELECT * FROM t1,(t3,t4) LEFT JOIN t2 ON on_expr

  SELECT * FROM t1 LEFT JOIN t2 ON on_expr1 RIGHT JOIN t3  ON on_expr2 =>
    SELECT * FROM t3 LEFT JOIN (t1 LEFT JOIN t2 ON on_expr2) ON on_expr1
Returns
  • Pointer to the table representing the inner table, if success
  • 0, otherwise

◆ create_default_definer()

LEX_USER* create_default_definer ( THD thd)

Create default definer for the specified THD.

Parameters
[in]thdthread handler
Returns
  • On success, return a valid pointer to the created and initialized LEX_USER, which contains definer information.
  • On error, return 0.

◆ create_select_for_variable()

bool create_select_for_variable ( Parse_context pc,
const char *  var_name 
)

Create a select to return the same output as 'SELECT @var_name'.

Used for SHOW COUNT(*) [ WARNINGS | ERROR].

This will crash with a core dump if the variable doesn't exists.

Parameters
pcCurrent parse context
var_nameVariable name
Returns
false if success, true if error

◆ create_table_set_open_action_and_adjust_tables()

void create_table_set_open_action_and_adjust_tables ( LEX lex)

Set proper open mode and table type for element representing target table of CREATE TABLE statement, also adjust statement table list if necessary.

◆ deny_updates_if_read_only_option()

static bool deny_updates_if_read_only_option ( THD thd,
TABLE_LIST all_tables 
)
static

Determine if an attempt to update a non-temporary table while the read-only option was enabled has been made.

This is a helper function to mysql_execute_command.

Note
SQLCOM_UPDATE_MULTI is an exception and delt with elsewhere.
See also
mysql_execute_command
Returns
Status code
Return values
trueThe statement should be denied.
falseThe statement isn't updating any relevant tables.

◆ dispatch_command()

bool dispatch_command ( THD thd,
const COM_DATA com_data,
enum enum_server_command  command 
)

Perform one connection-level (COM_XXXX) command.

Parameters
thdconnection handle
commandtype of command to perform
com_datacom_data union to store the generated command
Return values
0ok
1request of thread shutdown, i. e. if command is COM_QUIT

Clear the set of flags that are expected to be cleared at the beginning of each command.

Enforce password expiration for all RPC commands, except the following:

COM_QUERY/COM_STMT_PREPARE and COM_STMT_EXECUTE do a more fine-grained check later. COM_STMT_CLOSE and COM_STMT_SEND_LONG_DATA don't return anything. COM_PING only discloses information that the server is running, and that's available through other means. COM_QUIT should work even for expired statements.

◆ do_command()

bool do_command ( THD thd)

Read one command from connection and execute it (query or simple command).

This function is called in loop from thread function.

For profiling to work, it must never be called recursively.

Return values
0success
1request of thread shutdown (see dispatch_command() description)

◆ end_nested_join()

TABLE_LIST * SELECT_LEX::end_nested_join ( )

End a nested join table list.

The function returns to the previous join nest level. If the current level contains only one member, the function moves it one level up, eliminating the nest.

Returns
  • Pointer to TABLE_LIST element added to the total table list, if success
  • 0, otherwise

◆ execute_init_command()

void execute_init_command ( THD thd,
LEX_STRING init_command,
mysql_rwlock_t var_lock 
)

◆ execute_show()

bool execute_show ( THD thd,
TABLE_LIST all_tables 
)

◆ find_common_table_expr()

bool SELECT_LEX::find_common_table_expr ( THD thd,
Table_ident table_name,
TABLE_LIST tl,
Parse_context pc,
bool found 
)
private

Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name, *tl', and the matched with-list-element.

Parameters
thdThread handler
[out]table_nameIdentifier
[in,out]tlTABLE_LIST for the identifier
pcCurrent parsing context, if available
[out]foundIs set to true if found.
Returns
true if error (OOM).

◆ free_items()

void free_items ( Item item)

◆ get_bin_collation()

const CHARSET_INFO* get_bin_collation ( const CHARSET_INFO cs)

◆ get_current_user()

LEX_USER* get_current_user ( THD thd,
LEX_USER user 
)

Retuns information about user or current user.

Parameters
[in]thdthread handler
[in]useruser
Returns
  • On success, return a valid pointer to initialized LEX_USER, which contains user information.
  • On error, return 0.

◆ get_default_definer()

void get_default_definer ( THD thd,
LEX_USER definer 
)

Set the specified definer to the default value, which is the current user in the thread.

Parameters
[in]thdthread handler
[out]definerdefiner

◆ init_nested_join()

bool SELECT_LEX::init_nested_join ( THD thd)

Initialize a new table list for a nested join.

The function initializes a structure of the TABLE_LIST type for a nested join. It sets up its nested join list as empty. The created structure is added to the front of the current join list in the SELECT_LEX object. Then the function changes the current nest level for joins to refer to the newly created empty list after having saved the info on the old level in the initialized structure.

Parameters
thdcurrent thread
Return values
0if success
1otherwise

◆ init_sql_command_flags()

void init_sql_command_flags ( void  )

ACL DDLs do not access data-dictionary tables. However, they still need to be marked to avoid autocommit. This is necessary because code which saves GTID state or slave state in the system tables at commit time does statement commit on low-level (see System_table_access::close_table()) and thus can pre-maturely commit DDL otherwise.

Some statements doesn't if the ACL CACHE is disabled using the –skip-grant-tables server option.

◆ is_explainable_query()

bool is_explainable_query ( enum enum_sql_command  command)

◆ is_log_table_write_query()

bool is_log_table_write_query ( enum enum_sql_command  command)

Check if a sql command is allowed to write to log tables.

Parameters
commandThe SQL command
Returns
true if writing is allowed

◆ is_timer_applicable_to_statement()

static bool is_timer_applicable_to_statement ( THD thd)
inlinestatic

Check whether max statement time is applicable to statement or not.

Parameters
thdThread (session) context.
Returns
true if max statement time is applicable to statement
false otherwise.

Following conditions are checked,

  • is SELECT statement.
  • timer support is implemented and it is initialized.
  • statement is not made by the slave threads.
  • timer is not set for statement
  • timer out value of is set
  • SELECT statement is not from any stored programs.

◆ is_update_query()

bool is_update_query ( enum enum_sql_command  command)

◆ kill_one_thread()

static uint kill_one_thread ( THD thd,
my_thread_id  id,
bool  only_kill_query 
)
static

kill on thread.

Parameters
thdThread class
idThread id
only_kill_queryShould it kill the query or the connection
Note
This is written such that we have a short lock on LOCK_thd_list

◆ killall_non_super_threads()

void killall_non_super_threads ( THD thd)

◆ lock_tables_open_and_lock_tables()

static bool lock_tables_open_and_lock_tables ( THD thd,
TABLE_LIST tables 
)
static

Auxiliary call that opens and locks tables for LOCK TABLES statement and initializes the list of locked tables.

Parameters
thdThread context.
tablesList of tables to be locked.
Returns
false in case of success, true in case of error.

◆ lookup()

bool PT_with_clause::lookup ( TABLE_LIST tl,
PT_common_table_expr **  found 
)

Looks up a table reference into the list of CTEs.

Parameters
tlTable reference to look up
[out]foundIs set to true/false if found or not
Returns
true if error

◆ make_subquery_node()

bool PT_common_table_expr::make_subquery_node ( THD thd,
PT_subquery **  node 
)
Parameters
thdThread handler
[out]nodePT_subquery
Returns
a PT_subquery to attach to a table reference for this CTE

◆ match_table_ref()

bool PT_common_table_expr::match_table_ref ( TABLE_LIST tl,
bool  in_self,
bool found 
)
Parameters
tlTable reference to match
in_selfIf this is a recursive reference
[out]foundIs set to true/false if matches or not
Returns
true if error

◆ my_yyoverflow()

bool my_yyoverflow ( short **  yyss,
YYSTYPE **  yyvs,
YYLTYPE **  yyls,
ulong yystacksize 
)

◆ mysql_execute_command()

int mysql_execute_command ( THD thd,
bool  first_level 
)

Execute command saved in thd and lex->sql_command.

Parameters
thdThread handle
first_level
Return values
falseOK
trueError

◆ mysql_parse()

void mysql_parse ( THD thd,
Parser_state parser_state 
)

Parse a query.

Parameters
thdCurrent session.
parser_stateParser state.

◆ mysql_reset_thd_for_next_command()

void mysql_reset_thd_for_next_command ( THD thd)

Reset the part of THD responsible for the state of command processing.

This needs to be called before execution of every statement (prepared or conventional). It is not called by substatements of routines.

◆ mysql_test_parse_for_slave()

bool mysql_test_parse_for_slave ( THD thd)

Usable by the replication SQL thread only: just parse a query to know if it can be ignored because of replicate-*-table rules.

Return values
0cannot be ignored
1can be ignored

◆ nest_last_join()

TABLE_LIST * SELECT_LEX::nest_last_join ( THD thd,
size_t  table_cnt = 2 
)

Nest last join operations.

The function nest last table_cnt join operations as if they were the components of a cross join operation.

Parameters
thdcurrent thread
table_cnt2 for regular joins: t1 JOIN t2. N for the MySQL join-like extension: (t1, t2, ... tN).
Returns
Pointer to TABLE_LIST element created for the new nested join
Return values
0Error

◆ parse_sql()

bool parse_sql ( THD thd,
Parser_state parser_state,
Object_creation_ctx creation_ctx 
)

Transform an SQL statement into an AST that is ready for resolving, using the supplied parser state and object creation context.

This is a wrapper() for THD::sql_parser() and should generally be used for AST construction.

The function may optionally generate a query digest, invoke this function as follows:

  THD *thd = ...;
  const char *query_text = ...;
  uint query_length = ...;
  Object_creation_ctx *ctx = ...;
  bool rc;

  Parser_state parser_state;
  if (parser_state.init(thd, query_text, query_length)
  {
    ... handle error
  }

  parser_state.m_input.m_compute_digest= true;

  rc= parse_sql(the, &parser_state, ctx);
  if (! rc)
  {
    unsigned char md5[MD5_HASH_SIZE];
    char digest_text[1024];
    bool truncated;
    const sql_digest_storage *digest= & thd->m_digest->m_digest_storage;

    compute_digest_md5(digest, & md5[0]);
    compute_digest_text(digest, & digest_text[0], sizeof(digest_text), &
truncated);
  }
Parameters
thdThread context.
parser_stateParser state.
creation_ctxObject creation context.
Returns
Error status.
Return values
falseon success.
trueon parsing error.

◆ prepare_index_and_data_dir_path()

bool prepare_index_and_data_dir_path ( THD thd,
const char **  data_file_name,
const char **  index_file_name,
const char *  table_name 
)

prepares the index and data directory path.

Parameters
thdThread handle
data_file_namePathname for data directory
index_file_namePathname for index directory
table_nameTable name to be appended to the pathname specified
Returns
false success
true An error occurred

◆ prepare_schema_table()

int prepare_schema_table ( THD thd,
LEX lex,
Table_ident table_ident,
enum enum_schema_tables  schema_table_idx 
)

Create a TABLE_LIST object for an INFORMATION_SCHEMA table.

This function is used in the parser to convert a SHOW or DESCRIBE table_name command to a SELECT from INFORMATION_SCHEMA. It prepares a SELECT_LEX and a TABLE_LIST object to represent the given command as a SELECT parse tree.

Parameters
thdthread handle
lexcurrent lex
table_identtable alias if it's used
schema_table_idxthe type of the INFORMATION_SCHEMA table to be created
Note
Due to the way this function works with memory and LEX it cannot be used outside the parser (parse tree transformations outside the parser break PS and SP).
Return values
0success
1out of memory or SHOW commands are not allowed in this version of the server.

◆ push_new_name_resolution_context()

bool push_new_name_resolution_context ( Parse_context pc,
TABLE_LIST left_op,
TABLE_LIST right_op 
)

Push a new name resolution context for a JOIN ...

ON clause to the context stack of a query block.

Create a new name resolution context for a JOIN ... ON clause, set the first and last leaves of the list of table references to be used for name resolution, and push the newly created context to the stack of contexts of the query.

Parameters
pccurrent parse context
left_opleft operand of the JOIN
right_oprigth operand of the JOIN
Return values
falseif all is OK
trueif a memory allocation error occurred

◆ reparse_common_table_expr()

static bool reparse_common_table_expr ( THD thd,
const LEX_STRING text,
uint  text_offset,
PT_subquery **  node 
)
static

Produces a PT_subquery object from a subquery's text.

Parameters
thdThread handler
textSubquery's text
text_offsetOffset in bytes of 'text' in the original statement
[out]nodeProduced PT_subquery object
Returns
true if error

◆ reset_for_next_command()

void THD::reset_for_next_command ( )

◆ set_lock_for_table()

void SELECT_LEX::set_lock_for_table ( const Lock_descriptor descriptor,
TABLE_LIST table 
)

◆ set_lock_for_tables()

void SELECT_LEX::set_lock_for_tables ( thr_lock_type  lock_type)

Set lock for all tables in current query block.

Parameters
lock_typeLock to set for tables.
Note
If the lock is a write lock, then tables->updating is set to true. This is to get tables_ok to know that the table is being updated by the query. Sets the type of metadata lock to request according to lock_type.

◆ show_precheck()

bool show_precheck ( THD thd,
LEX lex,
bool  lock 
)

Do special checking for SHOW statements.

Parameters
thdThread context.
lexLEX for SHOW statement.
lockIf true, lock metadata for schema objects
Returns
false if check is successful, true if error

◆ shutdown()

bool shutdown ( THD thd,
enum mysql_enum_shutdown_level  level 
)

Shutdown the mysqld server.

Parameters
thdThread (session) context.
levelShutdown level.
Return values
truesuccess
falseWhen user has insufficient privilege or unsupported shutdown level

◆ some_non_temp_table_to_be_updated()

bool some_non_temp_table_to_be_updated ( THD thd,
TABLE_LIST tables 
)

◆ sp_process_definer()

static bool sp_process_definer ( THD thd)
static

◆ sql_kill()

static void sql_kill ( THD thd,
my_thread_id  id,
bool  only_kill_query 
)
static

◆ sqlcom_can_generate_row_events()

bool sqlcom_can_generate_row_events ( enum enum_sql_command  command)

◆ sqlcom_needs_autocommit_off()

static bool sqlcom_needs_autocommit_off ( const LEX lex)
static

Check if statement (typically DDL) needs auto-commit mode temporarily turned off.

Note
This is necessary to prevent InnoDB from automatically committing InnoDB transaction each time data-dictionary tables are closed after being updated.

◆ stmt_causes_implicit_commit()

bool stmt_causes_implicit_commit ( const THD thd,
uint  mask 
)

Returns whether the command in thd->lex->sql_command should cause an implicit commit.

An active transaction should be implicitly commited if the statement requires so.

Parameters
thdThread handle.
maskBitmask used for the SQL command match.
Return values
trueThis statement shall cause an implicit commit.
falseThis statement shall not cause an implicit commit.

◆ test_if_data_home_dir()

int test_if_data_home_dir ( const char *  dir)

◆ try_acquire_high_prio_shared_mdl_lock()

static bool try_acquire_high_prio_shared_mdl_lock ( THD thd,
TABLE_LIST table,
bool  can_deadlock 
)
static

Try acquire high priority share metadata lock on a table (with optional wait for conflicting locks to go away).

Parameters
thdThread context.
tableTable list element for the table
can_deadlockIndicates that deadlocks are possible due to metadata locks, so to avoid them we should not wait in case if conflicting lock is present.
Note
This is an auxiliary function to be used in cases when we want to access table's description by looking up info in TABLE_SHARE without going through full-blown table open.
This function assumes that there are no other metadata lock requests in the current metadata locking context.
Return values
falseNo error, if lock was obtained TABLE_LIST::mdl_request::ticket is set to non-NULL value.
trueSome error occurred (probably thread was killed).

Variable Documentation

◆ command_name

const LEX_STRING command_name[]

◆ server_command_flags

uint server_command_flags[COM_END+1]

◆ sql_command_flags

uint sql_command_flags[SQLCOM_END+1]

Mark all commands that somehow changes a table.

This is used to check number of updates / hour.

sql_command is actually set to SQLCOM_END sometimes so we need the +1 to include it in the array.

See COMMAND_FLAG_xxx for different type of commands 2 - query that returns meaningful ROW_COUNT() - a number of modified rows