SELECT SQ_CACHE * FROM TABLE where ID=1
问题:
- 如果向表中添加新行,是否仍会保留缓存?
- 如果更新以外的行
ID=1
仍然保持我的缓存? - 我知道如果同一行更新缓存丢失。
SELECT SQ_CACHE * FROM TABLE where ID=1
问题:
ID=1
仍然保持我的缓存?* Aside from some corner-cases or bugs maybe.
The "short" answer (note: specific to MySQL) would be: AFAIK MySQL caches on table level granularity; so any change on that table would invalidate all cached results for that table. Other than that, only deterministic queries will get cached, transactions might bypass/invalidate caches, the query cache doesn't support prepared statements, queries must be absolutely exactly be the same for the cache to kick in at all (so an extra space in a query would cause a cache miss) and subqueries aren't supported. And then there are still other factors involved. Maybe some things have changed in more recent versions but these are, some (not all!) of the factors that used to be involved. Correct me if I'm wrong.