为什么表更新时要清空查询缓存

为什么表更新时要清空查询缓存
为什么表更新时要清空查询缓存
为什么表更新时要清空查询缓存
为什么表更新时要清空查询缓存

这是因为 MySQL 自带的缓存机制,将查询结果进行缓存,如果 table 数据未发生变化,再次使用同一条 SQL 进行查询时,直接从上次的查询结果缓存中读取数据,而不是重新分析、执行 SQL。

如果 table 数据发生变化,所有与之相关的缓存都会被释放刷新,这样就不会出现数据脏读问题。

The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an i dentical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. The query cache is shared among sessions, so a result set generated by one client can be sent in response to the same query issued by another client.

img