PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
MySQL and Linux/Unix
MySQL and macOS
MySQL Partitioning
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL Restrictions and Limitations
Security in MySQL
MySQL and Solaris
Building MySQL from Source
Starting and Stopping MySQL
MySQL Tutorial
MySQL and Windows
MySQL NDB Cluster 7.5
The Performance Schema provides instrumentation for prepared statements, for which there are two protocols:
The binary protocol. This is accessed through the MySQL C API and maps onto underlying server commands as shown in the following table.
C API Function Corresponding Server Command mysql_stmt_prepare()COM_STMT_PREPAREmysql_stmt_execute()COM_STMT_EXECUTEmysql_stmt_close()COM_STMT_CLOSEThe text protocol. This is accessed using SQL statements and maps onto underlying server commands as shown in the following table.
SQL Statement Corresponding Server Command PREPARESQLCOM_PREPAREEXECUTESQLCOM_EXECUTEDEALLOCATE PREPARE,DROP PREPARESQLCOM_DEALLOCATE PREPARE
Performance Schema prepared statement instrumentation covers both protocols. The following discussion refers to the server commands rather than the C API functions or SQL statements.
Information about prepared statements is available in theprepared_statements_instances table. This table enables inspection of prepared statements used in the server and provides aggregated statistics about them. To control the size of this table, set theperformance_schema_max_prepared_statements_instances system variable at server startup.
Collection of prepared statement information depends on the statement instruments shown in the following table. These instruments are enabled by default. To modify them, update thesetup_instruments table.
| Instrument | Server Command |
|---|---|
statement/com/Prepare | COM_STMT_PREPARE |
statement/com/Execute | COM_STMT_EXECUTE |
statement/sql/prepare_sql | SQLCOM_PREPARE |
statement/sql/execute_sql | SQLCOM_EXECUTE |
The Performance Schema manages the contents of theprepared_statements_instances table as follows:
Statement preparation
A
COM_STMT_PREPAREorSQLCOM_PREPAREcommand creates a prepared statement in the server. If the statement is successfully instrumented, a new row is added to theprepared_statements_instancestable. If the statement cannot be instrumented,Performance_schema_prepared_statements_loststatus variable is incremented.Prepared statement execution
Execution of a
COM_STMT_EXECUTEorSQLCOM_PREPAREcommand for an instrumented prepared statement instance updates the correspondingprepared_statements_instancestable row.Prepared statement deallocation
Execution of a
COM_STMT_CLOSEorSQLCOM_DEALLOCATE_PREPAREcommand for an instrumented prepared statement instance removes the correspondingprepared_statements_instancestable row. To avoid resource leaks, removal occurs even if the prepared statement instruments described previously are disabled.
Theprepared_statements_instances table has these columns:
OBJECT_INSTANCE_BEGINThe address in memory of the instrumented prepared statement.
STATEMENT_IDThe internal statement ID assigned by the server. The text and binary protocols both use statement IDs.
STATEMENT_NAMEFor the binary protocol, this column is
NULL. For the text protocol, this column is the external statement name assigned by the user. For example, for the following SQL statement, the name of the prepared statement isstmt:PREPARE stmt FROM 'SELECT 1';SQL_TEXTThe prepared statement text, with
?placeholder markers.OWNER_THREAD_ID,OWNER_EVENT_IDThese columns indicate the event that created the prepared statement.
OWNER_OBJECT_TYPE,OWNER_OBJECT_SCHEMA,OWNER_OBJECT_NAMEFor a prepared statement created by a client session, these columns are
NULL. For a prepared statement created by a stored program, these columns point to the stored program. A typical user error is forgetting to deallocate prepared statements. These columns can be used to find stored programs that leak prepared statements:SELECT OWNER_OBJECT_TYPE, OWNER_OBJECT_SCHEMA, OWNER_OBJECT_NAME, STATEMENT_NAME, SQL_TEXTFROM performance_schema.prepared_statements_instancesWHERE OWNER_OBJECT_TYPE IS NOT NULL;TIMER_PREPAREThe time spent executing the statement preparation itself.
COUNT_REPREPAREThe number of times the statement was reprepared internally (seeSection 8.10.4, “Caching of Prepared Statements and Stored Programs”). Timing statistics for repreparation are not available because it is counted as part of statement execution, not as a separate operation.
COUNT_EXECUTE,SUM_TIMER_EXECUTE,MIN_TIMER_EXECUTE,AVG_TIMER_EXECUTE,MAX_TIMER_EXECUTEAggregated statistics for executions of the prepared statement.
SUM_xxxThe remaining
SUM_columns are the same as for the statement summary tables (seeSection 25.12.15.3, “Statement Summary Tables”).xxx
TRUNCATE TABLE resets the statistics columns of theprepared_statements_instances table.
PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
MySQL and Linux/Unix
MySQL and macOS
MySQL Partitioning
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL Restrictions and Limitations
Security in MySQL
MySQL and Solaris
Building MySQL from Source
Starting and Stopping MySQL
MySQL Tutorial
MySQL and Windows
MySQL NDB Cluster 7.5