MySQL中SQL

47次阅读
没有评论

共计 1298 个字符,预计需要花费 4 分钟才能阅读完成。

这篇文章主要介绍了 MySQL 中 SQL_NO_CACHE 怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让丸趣 TV 小编带着大家一起了解一下。

SQL_CACHE 意思是说,查询的时候使用缓存。

SQL_NO_CACHE 解释如下:

1. 对当前 query 不使用数据库已有缓存来查询,则当前 query 花费时间会多点

2. 对当前 query 的产生的结果集不缓存至系统 query cache 里,则下次相同 query 花费时间会多点

当我们想用 SQL_NO_CACHE 来禁止结果缓存时发现结果和我们的预期不一样,查询执行的结果仍然是缓存后的结果。其实,SQL_NO_CACHE 的真正作用是禁止缓存查询结果,但并不意味着 cache 不作为结果返回给 query。

SQL_NO_CACHE 的官方解释如下:

SQL_NO_CACHE means that the query result is not cached. It does not mean that the cache is not used to answer the query.

You may use RESET QUERY CACHE to remove all queries from the cache and then your next query should be slow again. Same effect if you change the table, because this makes all cached queries invalid.

以下是实验过程:

mysql use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql  select count(*) from fp_data;
+———-+
| count(*) |
+———-+
|   158404 |
+———-+
1 row in set (0.05 sec)

mysql select count(*) from fp_data;
+———-+
| count(*) |
+———-+
|   158404 |
+———-+
1 row in set (0.03 sec)

mysql select SQL_CACHE count(*) from fp_data;
+———-+
| count(*) |
+———-+
|   158411 |
+———-+
1 row in set (0.03 sec)

mysql select SQL_NO_CACHE count(*) from fp_data;
+———-+
| count(*) |
+———-+
|   158404 |
+———-+
1 row in set (0.02 sec)

感谢你能够认真阅读完这篇文章,希望丸趣 TV 小编分享的“MySQL 中 SQL_NO_CACHE 怎么用”这篇文章对大家有帮助,同时也希望大家多多支持丸趣 TV,关注丸趣 TV 行业资讯频道,更多相关知识等着你来学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-27发表,共计1298字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)