MySQL  8.0.16
Source Code Documentation
Sql_cmd Class Referenceabstract

Representation of an SQL command. More...

#include <sql_cmd.h>

Inheritance diagram for Sql_cmd:
resourcegroups::Sql_cmd_alter_resource_group resourcegroups::Sql_cmd_create_resource_group resourcegroups::Sql_cmd_drop_resource_group resourcegroups::Sql_cmd_set_resource_group Sql_cmd_alter_instance Sql_cmd_alter_undo_tablespace Sql_cmd_alter_user_default_role Sql_cmd_change_repl_filter Sql_cmd_clone Sql_cmd_common_server Sql_cmd_common_signal Sql_cmd_create_role Sql_cmd_create_srs Sql_cmd_create_undo_tablespace Sql_cmd_ddl Sql_cmd_ddl_table Sql_cmd_ddl_trigger_common Sql_cmd_dml Sql_cmd_drop_role Sql_cmd_drop_srs Sql_cmd_drop_undo_tablespace Sql_cmd_explain_other_thread Sql_cmd_get_diagnostics Sql_cmd_grant_roles Sql_cmd_handler_close Sql_cmd_handler_open Sql_cmd_handler_read Sql_cmd_import_table Sql_cmd_install_component Sql_cmd_install_plugin Sql_cmd_load_table Sql_cmd_lock_instance Sql_cmd_logfile_group Sql_cmd_restart_server Sql_cmd_revoke_roles Sql_cmd_set_role Sql_cmd_show Sql_cmd_show_grants Sql_cmd_shutdown Sql_cmd_tablespace Sql_cmd_truncate_table Sql_cmd_uninstall_component Sql_cmd_uninstall_plugin Sql_cmd_unlock_instance Sql_cmd_xa_commit Sql_cmd_xa_end Sql_cmd_xa_prepare Sql_cmd_xa_recover Sql_cmd_xa_rollback Sql_cmd_xa_start

Public Member Functions

virtual enum_sql_command sql_command_code () const =0
 Return the command code for this statement. More...
 
bool is_prepared () const
 
virtual bool prepare (THD *thd)
 Prepare this SQL statement. More...
 
virtual bool execute (THD *thd)=0
 Execute this SQL statement. More...
 
virtual void cleanup (THD *thd)
 Command-specific reinitialization before execution of prepared statement. More...
 
void set_owner (Prepared_statement *stmt)
 Set the owning prepared statement. More...
 
Prepared_statementget_owner ()
 Get the owning prepared statement. More...
 
virtual bool is_dml () const
 
virtual bool is_single_table_plan () const
 
virtual void unprepare (THD *thd)
 Temporary function used to "unprepare" a prepared statement after preparation, so that a subsequent execute statement will reprepare it. More...
 
virtual bool accept (THD *thd, Select_lex_visitor *visitor)
 
virtual const MYSQL_LEX_STRINGeligible_secondary_storage_engine () const
 Is this statement of a type and on a form that makes it eligible for execution in a secondary storage engine? More...
 
void disable_secondary_storage_engine ()
 Disable use of secondary storage engines in this statement. More...
 
bool secondary_storage_engine_disabled () const
 Has use of secondary storage engines been disabled for this statement? More...
 
void use_secondary_storage_engine (const handlerton *hton)
 Mark the current statement as using a secondary storage engine. More...
 
bool using_secondary_storage_engine () const
 Is this statement using a secondary storage engine? More...
 
const handlertonsecondary_engine () const
 Get the handlerton of the secondary engine that is used for executing this statement, or nullptr if a secondary engine is not used. More...
 

Protected Member Functions

 Sql_cmd ()
 
virtual ~Sql_cmd ()
 
bool needs_explicit_preparation () const
 
void set_prepared ()
 Set this statement as prepared. More...
 

Protected Attributes

bool prepare_only
 

Private Member Functions

 Sql_cmd (const Sql_cmd &)
 
void operator= (Sql_cmd &)
 

Private Attributes

Prepared_statementm_owner
 
bool m_prepared
 Owning prepared statement, nullptr if non-prep. More...
 
bool m_secondary_engine_enabled {true}
 True when statement has been prepared. More...
 
const handlertonm_secondary_engine {nullptr}
 The secondary storage engine to use for execution of this statement, if any, or nullptr if the primary engine is used. More...
 

Detailed Description

Representation of an SQL command.

This class is an interface between the parser and the runtime. The parser builds the appropriate derived classes of Sql_cmd to represent a SQL statement in the parsed tree. The execute() method in the derived classes of Sql_cmd contain the runtime implementation. Note that this interface is used for SQL statements recently implemented, the code for older statements tend to load the LEX structure with more attributes instead. Implement new statements by sub-classing Sql_cmd, as this improves code modularity (see the 'big switch' in dispatch_command()), and decreases the total size of the LEX structure (therefore saving memory in stored programs). The recommended name of a derived class of Sql_cmd is Sql_cmd_<derived>.

Notice that the Sql_cmd class should not be confused with the Statement class. Statement is a class that is used to manage an SQL command or a set of SQL commands. When the SQL statement text is analyzed, the parser will create one or more Sql_cmd objects to represent the actual SQL commands.

Constructor & Destructor Documentation

◆ Sql_cmd() [1/2]

Sql_cmd::Sql_cmd ( const Sql_cmd )
private

◆ Sql_cmd() [2/2]

Sql_cmd::Sql_cmd ( )
inlineprotected

◆ ~Sql_cmd()

virtual Sql_cmd::~Sql_cmd ( )
inlineprotectedvirtual

Member Function Documentation

◆ accept()

virtual bool Sql_cmd::accept ( THD thd,
Select_lex_visitor visitor 
)
inlinevirtual

◆ cleanup()

virtual void Sql_cmd::cleanup ( THD thd)
inlinevirtual

Command-specific reinitialization before execution of prepared statement.

See also
reinit_stmt_before_use()
Note
Currently this function is overloaded for INSERT/REPLACE stmts only.
Parameters
thdCurrent THD.

Reimplemented in Sql_cmd_insert_base.

◆ disable_secondary_storage_engine()

void Sql_cmd::disable_secondary_storage_engine ( )
inline

Disable use of secondary storage engines in this statement.

After a call to this function, the statement will not try to use a secondary storage engine until it is reprepared.

◆ eligible_secondary_storage_engine()

virtual const MYSQL_LEX_STRING* Sql_cmd::eligible_secondary_storage_engine ( ) const
inlinevirtual

Is this statement of a type and on a form that makes it eligible for execution in a secondary storage engine?

Returns
the name of the secondary storage engine, or nullptr if the statement is not eligible for execution in a secondary storage engine

Reimplemented in Sql_cmd_select, and Sql_cmd_do.

◆ execute()

virtual bool Sql_cmd::execute ( THD thd)
pure virtual

Execute this SQL statement.

Parameters
thdthe current thread.
Returns
false if success, true if error

Implemented in Sql_cmd_secondary_load_unload, Sql_cmd_discard_import_tablespace, Sql_cmd_change_repl_filter, Sql_cmd_alter_table, Sql_cmd_show, Sql_cmd_clone, Sql_cmd_alter_instance, Sql_cmd_show_grants, Sql_cmd_logfile_group, Sql_cmd_alter_user_default_role, Sql_cmd_drop_undo_tablespace, Sql_cmd_revoke_roles, Sql_cmd_grant_roles, Sql_cmd_alter_undo_tablespace, Sql_cmd_drop_role, Sql_cmd_drop_trigger, Sql_cmd_create_undo_tablespace, Sql_cmd_create_role, Sql_cmd_create_trigger, Sql_cmd_drop_server, Sql_cmd_set_role, Sql_cmd_alter_tablespace_rename, Sql_cmd_alter_server, Sql_cmd_alter_tablespace_drop_datafile, Sql_cmd_shutdown, Sql_cmd_repair_table, Sql_cmd_alter_tablespace_add_datafile, Sql_cmd_explain_other_thread, Sql_cmd_create_server, Sql_cmd_optimize_table, Sql_cmd_xa_rollback, Sql_cmd_resignal, Sql_cmd_alter_tablespace, Sql_cmd_check_table, Sql_cmd_signal, Sql_cmd_xa_commit, Sql_cmd_drop_tablespace, resourcegroups::Sql_cmd_set_resource_group, Sql_cmd_uninstall_plugin, Sql_cmd_create_tablespace, Sql_cmd_xa_recover, Sql_cmd_load_index, Sql_cmd_alter_table_truncate_partition, resourcegroups::Sql_cmd_drop_resource_group, Sql_cmd_cache_index, Sql_cmd_xa_prepare, Sql_cmd_drop_srs, Sql_cmd_install_plugin, Sql_cmd_handler_close, Sql_cmd_alter_table_repair_partition, resourcegroups::Sql_cmd_alter_resource_group, Sql_cmd_alter_table_optimize_partition, Sql_cmd_xa_end, Sql_cmd_create_or_drop_index_base, Sql_cmd_analyze_table, Sql_cmd_load_table, Sql_cmd_uninstall_component, Sql_cmd_handler_read, Sql_cmd_alter_table_check_partition, Sql_cmd_create_srs, Sql_cmd_xa_start, Sql_cmd_create_table, Sql_cmd_unlock_instance, resourcegroups::Sql_cmd_create_resource_group, Sql_cmd_alter_table_analyze_partition, Sql_cmd_import_table, Sql_cmd_get_diagnostics, Sql_cmd_truncate_table, Sql_cmd_dml, Sql_cmd_install_component, Sql_cmd_handler_open, Sql_cmd_lock_instance, Sql_cmd_alter_table_exchange_partition, and Sql_cmd_restart_server.

◆ get_owner()

Prepared_statement* Sql_cmd::get_owner ( )
inline

Get the owning prepared statement.

◆ is_dml()

virtual bool Sql_cmd::is_dml ( ) const
inlinevirtual
Returns
true if SQL command is a DML statement

Reimplemented in Sql_cmd_dml, and Sql_cmd_ddl.

◆ is_prepared()

bool Sql_cmd::is_prepared ( ) const
inline
Returns
true if this statement is prepared

◆ is_single_table_plan()

virtual bool Sql_cmd::is_single_table_plan ( ) const
inlinevirtual
Returns
true if implemented as single table plan, DML statement only

Reimplemented in Sql_cmd_insert_values, Sql_cmd_update, Sql_cmd_delete, and Sql_cmd_dml.

◆ needs_explicit_preparation()

bool Sql_cmd::needs_explicit_preparation ( ) const
inlineprotected
Returns
true if object represents a preparable statement, ie. a query that is prepared with a PREPARE statement and executed with an EXECUTE statement. False is returned for regular statements (non-preparable statements) that are executed directly.

◆ operator=()

void Sql_cmd::operator= ( Sql_cmd )
private

◆ prepare()

virtual bool Sql_cmd::prepare ( THD thd)
inlinevirtual

Prepare this SQL statement.

Parameters
thdthe current thread
Returns
false if success, true if error

Reimplemented in Sql_cmd_show, resourcegroups::Sql_cmd_set_resource_group, Sql_cmd_create_table, and Sql_cmd_dml.

◆ secondary_engine()

const handlerton* Sql_cmd::secondary_engine ( ) const
inline

Get the handlerton of the secondary engine that is used for executing this statement, or nullptr if a secondary engine is not used.

◆ secondary_storage_engine_disabled()

bool Sql_cmd::secondary_storage_engine_disabled ( ) const
inline

Has use of secondary storage engines been disabled for this statement?

◆ set_owner()

void Sql_cmd::set_owner ( Prepared_statement stmt)
inline

Set the owning prepared statement.

◆ set_prepared()

void Sql_cmd::set_prepared ( )
inlineprotected

Set this statement as prepared.

◆ sql_command_code()

virtual enum_sql_command Sql_cmd::sql_command_code ( ) const
pure virtual

Return the command code for this statement.

Implemented in Sql_cmd_change_repl_filter, Sql_cmd_common_alter_table, Sql_cmd_show, Sql_cmd_clone, Sql_cmd_alter_instance, Sql_cmd_show_grants, Sql_cmd_logfile_group, Sql_cmd_alter_user_default_role, Sql_cmd_drop_undo_tablespace, Sql_cmd_revoke_roles, Sql_cmd_insert_select, Sql_cmd_grant_roles, Sql_cmd_alter_undo_tablespace, Sql_cmd_insert_values, Sql_cmd_drop_role, Sql_cmd_create_undo_tablespace, Sql_cmd_drop_trigger, Sql_cmd_create_role, Sql_cmd_create_trigger, Sql_cmd_set_role, Sql_cmd_drop_server, Sql_cmd_shutdown, Sql_cmd_alter_server, Sql_cmd_repair_table, Sql_cmd_optimize_table, Sql_cmd_explain_other_thread, Sql_cmd_create_server, Sql_cmd_xa_rollback, Sql_cmd_resignal, Sql_cmd_check_table, Sql_cmd_signal, Sql_cmd_xa_commit, Sql_cmd_update, resourcegroups::Sql_cmd_set_resource_group, Sql_cmd_xa_recover, Sql_cmd_load_index, Sql_cmd_uninstall_plugin, Sql_cmd_alter_table_truncate_partition, resourcegroups::Sql_cmd_drop_resource_group, Sql_cmd_delete, Sql_cmd_cache_index, Sql_cmd_drop_srs, Sql_cmd_tablespace, Sql_cmd_alter_table_repair_partition, Sql_cmd_xa_prepare, Sql_cmd_handler_close, Sql_cmd_drop_index, Sql_cmd_install_plugin, Sql_cmd_alter_table_optimize_partition, Sql_cmd_create_index, resourcegroups::Sql_cmd_alter_resource_group, Sql_cmd_xa_end, Sql_cmd_analyze_table, Sql_cmd_load_table, Sql_cmd_alter_table_check_partition, Sql_cmd_handler_read, Sql_cmd_select, Sql_cmd_create_srs, Sql_cmd_xa_start, Sql_cmd_unlock_instance, Sql_cmd_create_table, Sql_cmd_uninstall_component, Sql_cmd_import_table, Sql_cmd_alter_table_analyze_partition, resourcegroups::Sql_cmd_create_resource_group, Sql_cmd_truncate_table, Sql_cmd_get_diagnostics, Sql_cmd_handler_open, Sql_cmd_lock_instance, Sql_cmd_restart_server, Sql_cmd_install_component, Sql_cmd_do, and Sql_cmd_call.

◆ unprepare()

virtual void Sql_cmd::unprepare ( THD thd)
inlinevirtual

Temporary function used to "unprepare" a prepared statement after preparation, so that a subsequent execute statement will reprepare it.

This is done because UNIT::cleanup() will un-resolve all resolved QBs.

◆ use_secondary_storage_engine()

void Sql_cmd::use_secondary_storage_engine ( const handlerton hton)
inline

Mark the current statement as using a secondary storage engine.

This function must be called before the statement starts opening tables in a secondary engine.

◆ using_secondary_storage_engine()

bool Sql_cmd::using_secondary_storage_engine ( ) const
inline

Is this statement using a secondary storage engine?

Member Data Documentation

◆ m_owner

Prepared_statement* Sql_cmd::m_owner
private

◆ m_prepared

bool Sql_cmd::m_prepared
private

Owning prepared statement, nullptr if non-prep.

◆ m_secondary_engine

const handlerton* Sql_cmd::m_secondary_engine {nullptr}
private

The secondary storage engine to use for execution of this statement, if any, or nullptr if the primary engine is used.

This property is reset at the start of each execution.

◆ m_secondary_engine_enabled

bool Sql_cmd::m_secondary_engine_enabled {true}
private

True when statement has been prepared.

Tells if a secondary storage engine can be used for this statement. If it is false, use of a secondary storage engine will not be considered for executing this statement.

◆ prepare_only

bool Sql_cmd::prepare_only
protected

The documentation for this class was generated from the following file: