content_image/764901.jpg content_image/764902.jpg
<img src='content_image/764901.jpg'>

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 the prepared_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 the performance_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 the setup_instruments  table. 

<img src='content_image/764902.jpg'>

The Performance Schema manages the contents of the prepared_statements_instances  table as follows: 

## •Statement preparation 

A COM_STMT_PREPARE  or SQLCOM_PREPARE  command creates a prepared statement in the server. If the statement is successfully instrumented, a new row is added to the prepared_statements_instances  table. If the statement cannot be instrumented, Performance_schema_prepared_statements_lost  status variable is incremented. 

## •Prepared statement execution 

Execution of a COM_STMT_EXECUTE  or SQLCOM_PREPARE  command for an instrumented prepared statement instance updates the corresponding prepared_statements_instances  table row. 

## •Prepared statement deallocation 

Execution of a COM_STMT_CLOSE  or SQLCOM_DEALLOCATE_PREPARE  command for an instrumented prepared statement instance removes the corresponding prepared_statements_instances  table row. To avoid resource leaks, removal occurs even if the prepared statement instruments described previously are disabled. 

The prepared_statements_instances  table has these columns: 

## • OBJECT_INSTANCE_BEGIN 

The address in memory of the instrumented prepared statement. 

## • STATEMENT_ID 

The internal statement ID assigned by the server. The text and binary protocols both use statement IDs. 

## • STATEMENT_NAME 

