8. Query cache

1. Query caching
Many database products can cache the execution plan of a query. For the same type of SQL, you can skip the SQL parsing and execution plan division. MySQL can also be implemented in certain scenarios, but MySQL has another different type of cache to cache the results of the completed select query, that is, the query cache.
MySQL stores the cache in a reference table, similar to the data structure of HashMap, Key query SQL statement, Value query result. When a query is initiated, SQL statements are used to query in the cache, and if a hit is made, the result set in the cache is immediately returned.

2. Enabling or disabling query caching
Use the following command to check whether MySQL is enabling query caching.

show variables like '%query_cache%';

As shown in the figure below, the value of have_query_cache is YES, indicating that query caching is supported.
Insert picture description here

MySQL8.0 has removed the query cache function.
You can use sql_no_cache to disable caching of query results in select, for example: select sql_no_cache * from user;

Insert picture description here

Guess you like

Origin blog.csdn.net/Jgx1214/article/details/107496093