content_image/770129.jpg
KEY ‘NAME‘ (‘NAME‘), KEY ‘WRITE_LOCKED_BY_THREAD_ID‘ (‘WRITE_LOCKED_BY_THREAD_ID‘) ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci 

To see the execution plan for a Performance Schema query and whether it uses any indexes, use EXPLAIN : 

mysql> EXPLAIN SELECT * FROM performance_schema.accounts WHERE (USER,HOST) = (’root’,’localhost’)\G 

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

The EXPLAIN  output indicates that the optimizer uses the accounts  table ACCOUNT  index that comprises the USER  and HOST  columns. 

Performance Schema indexes are virtual: They are a construct of the Performance Schema storage engine and use no memory or disk storage. The Performance Schema reports index information to the optimizer so that it can construct efficient execution plans. The Performance Schema in turn uses optimizer information about what to look for (for example, a particular key value), so that it can perform efficient lookups without building actual index structures. This implementation provides two important benefits: 

•It entirely avoids the maintenance cost normally incurred for tables that undergo frequent updates. 

•It reduces at an early stage of query execution the amount of data retrieved. For conditions on the indexed columns, the Performance Schema efficiently returns only table rows that satisfy the query conditions. Without an index, the Performance Schema would return all rows in the table, requiring that the optimizer later evaluate the conditions against each row to produce the final result. 

Performance Schema indexes are predefined and cannot be dropped, added, or altered. 

Performance Schema indexes are similar to hash indexes. For example: 

•They are used only for equality comparisons that use the =  or <=>  operators. 

•They are unordered. If a query result must have specific row ordering characteristics, include an ORDER BY  clause. 

For additional information about hash indexes, see Section 8.3.9, “Comparison of B-Tree and Hash Indexes” . 

## 8.2.5 Optimizing Data Change Statements 

This section explains how to speed up data change statements: INSERT , UPDATE , and DELETE . Traditional OLTP applications and modern web applications typically do many small data change operations, where concurrency is vital. Data analysis and reporting applications typically run data change operations that affect many rows at once, where the main considerations is the I/O to write large amounts of data and keep indexes up-to-date. For inserting and updating large volumes of data (known in the industry as ETL, for “extract-transform-load” ), sometimes you use other SQL statements or external commands, that mimic the effects of INSERT , UPDATE , and DELETE  statements. 

