{"id":669,"date":"2009-08-25T18:56:52","date_gmt":"2009-08-25T10:56:52","guid":{"rendered":"http:\/\/orczhou.com\/?p=669"},"modified":"2010-01-14T11:27:05","modified_gmt":"2010-01-14T03:27:05","slug":"query-cache-1","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2009\/08\/query-cache-1\/","title":{"rendered":"Query Cache\uff0c\u770b\u4e0a\u53bb\u5f88\u7f8e"},"content":{"rendered":"<p>\u5f53\u4f60\u7684\u6570\u636e\u5e93\u6253\u5f00\u4e86Query Cache\uff08\u7b80\u79f0QC\uff09\u529f\u80fd\u540e\uff0c\u6570\u636e\u5e93\u5728\u6267\u884cSELECT\u8bed\u53e5\u65f6\uff0c\u4f1a\u5c06\u5176\u7ed3\u679c\u653e\u5230QC\u4e2d\uff0c\u5f53\u4e0b\u4e00\u6b21\u5904\u7406\u540c\u6837\u7684SELECT\u8bf7\u6c42\u65f6\uff0c\u6570\u636e\u5e93\u5c31\u4f1a\u4eceQC\u53d6\u5f97\u7ed3\u679c\uff0c\u800c\u4e0d\u9700\u8981\u53bb\u6570\u636e\u8868\u4e2d\u67e5\u8be2\u3002<\/p>\n<p><!--more--><\/p>\n<p><a title=\"Query-Cache-1 by orczhou, on Flickr\" href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/3854812215\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm4.static.flickr.com\/3498\/3854812215_c316040392_o.png\" alt=\"Query-Cache-1\" width=\"505\" height=\"321\" \/><\/a><\/p>\n<p>\u5728\u8fd9\u4e2a\u201cCache\u4e3a\u738b\u201d\u7684\u65f6\u4ee3\uff0c\u6211\u4eec\u603b\u662f\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u53bb\u7f13\u5b58\u6211\u4eec\u7684\u7ed3\u679c\u4ece\u800c\u63d0\u9ad8\u54cd\u5e94\u6548\u7387\uff0c\u4f46\u4e00\u4e2a\u7f13\u5b58\u673a\u5236\u662f\u5426\u6709\u6548\uff0c\u6548\u679c\u5982\u4f55\uff0c\u5374\u662f\u4e00\u4e2a\u9700\u8981\u597d\u597d\u601d\u8003\u7684\u95ee\u9898\u3002\u5728MySQL\u4e2d\u7684Query Cache\u5c31\u662f\u4e00\u4e2a\u9002\u7528\u8f83\u5c11\u60c5\u51b5\u7684\u7f13\u5b58\u673a\u5236\u3002\u5728\u4e0a\u56fe\u4e2d\uff0c\u5982\u679c\u7f13\u5b58\u547d\u4e2d\u7387\u975e\u5e38\u9ad8\u7684\u8bdd\uff0c\u6709\u6d4b\u8bd5\u8868\u660e\u5728\u6781\u7aef\u60c5\u51b5\u4e0b\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387238%<sup>[1]<\/sup>\u3002\u4f46\u5b9e\u9645\u60c5\u51b5\u5982\u4f55\uff1f<strong>Query Cache\u6709\u5982\u4e0b\u89c4\u5219\uff0c\u5982\u679c\u6570\u636e\u8868\u88ab\u66f4\u6539\uff0c\u90a3\u4e48\u548c\u8fd9\u4e2a\u6570\u636e\u8868\u76f8\u5173\u7684\u5168\u90e8Cache\u5168\u90e8\u90fd\u4f1a\u65e0\u6548\uff0c\u5e76\u5220\u9664\u4e4b\u3002\u8fd9\u91cc\u201c\u6570\u636e\u8868\u66f4\u6539\u201d\u5305\u62ec: <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/insert.html\"><strong>INSERT<\/strong><\/a><strong>, <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/update.html\"><strong>UPDATE<\/strong><\/a><strong>, <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/delete.html\"><strong>DELETE<\/strong><\/a><strong>, <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/truncate.html\"><strong>TRUNCATE<\/strong><\/a><strong>, <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/alter-table.html\"><strong>ALTER TABLE<\/strong><\/a><strong>, <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/drop-table.html\"><strong>DROP TABLE<\/strong><\/a><strong>, or <\/strong><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/drop-database.html\"><strong>DROP DATABASE<\/strong><\/a><strong>\u7b49\u3002<\/strong>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u6570\u636e\u8868posts\u8bbf\u95ee\u9891\u7e41\uff0c\u90a3\u4e48\u610f\u5473\u7740\u5b83\u7684\u5f88\u591a\u6570\u636e\u4f1a\u88abQC\u7f13\u5b58\u8d77\u6765\uff0c\u4f46\u662f\u6bcf\u4e00\u6b21posts\u6570\u636e\u8868\u7684\u66f4\u65b0\uff0c\u65e0\u8bba\u66f4\u65b0\u662f\u4e0d\u662f\u5f71\u54cd\u5230\u4e86cache\u7684\u6570\u636e\uff0c\u90fd\u4f1a\u5c06\u5168\u90e8\u548cposts\u8868\u76f8\u5173\u7684cache\u6e05\u9664\u3002\u5982\u679c\u4f60\u7684\u6570\u636e\u8868\u66f4\u65b0\u9891\u7e41\u7684\u8bdd\uff0c\u90a3\u4e48Query Cache\u5c06\u4f1a\u6210\u4e3a\u7cfb\u7edf\u7684\u8d1f\u62c5\u3002\u6709\u5b9e\u9a8c\u8868\u660e\uff0c\u7cdf\u7cd5\u65f6\uff0cQC\u4f1a\u964d\u4f4e\u7cfb\u7edf13%<sup>[1]<\/sup>\u7684\u5904\u7406\u80fd\u529b\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u5e94\u7528\u5bf9\u6570\u636e\u5e93\u7684\u66f4\u65b0\u5f88\u5c11\uff0c\u90a3\u4e48QC\u5c06\u4f1a\u4f5c\u7528\u663e\u8457\u3002\u6bd4\u8f83\u5178\u578b\u7684\u5982\u535a\u5ba2\u7cfb\u7edf\uff0c\u4e00\u822c\u535a\u5ba2\u66f4\u65b0\u76f8\u5bf9\u8f83\u6162\uff0c\u6570\u636e\u8868\u76f8\u5bf9\u7a33\u5b9a\u4e0d\u53d8\uff0c\u8fd9\u65f6\u5019QC\u7684\u4f5c\u7528\u4f1a\u6bd4\u8f83\u660e\u663e\u3002<\/p>\n<p>\u518d\u5982\uff0c\u4e00\u4e2a\u66f4\u65b0\u9891\u7e41\u7684BBS\u7cfb\u7edf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9e\u9645\u8fd0\u884c\u7684\u8bba\u575b\u6570\u636e\u5e93\u7684\u72b6\u6001\u53c2\u6570\uff1a<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"300\">\n<tbody>\n<tr>\n<td width=\"150\" valign=\"top\">QCache_hit<\/td>\n<td width=\"150\" valign=\"top\">5280438<\/td>\n<\/tr>\n<tr>\n<td width=\"150\" valign=\"top\">QCache_insert<\/td>\n<td width=\"150\" valign=\"top\">8008948<\/td>\n<\/tr>\n<tr>\n<td width=\"150\" valign=\"top\">Qcache_not_cache<\/td>\n<td width=\"150\" valign=\"top\">95372<\/td>\n<\/tr>\n<tr>\n<td width=\"150\" valign=\"top\">Com select<\/td>\n<td width=\"150\" valign=\"top\">8104159<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u6570\u636e\u5e93\u4e00\u5171\u5f80QC\u4e2d\u5199\u5165\u4e86\u7ea6800W\u6b21\u7f13\u5b58\uff0c\u4f46\u662f\u5b9e\u9645\u547d\u4e2d\u7684\u53ea\u6709\u7ea6500W\u6b21\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u4e00\u4e2a\u7f13\u5b58\u7684\u4f7f\u7528\u7387\u7ea6\u4e3a0.66\u6b21\u3002\u5f88\u96be\u8bf4\uff0c\u8be5\u7f13\u5b58\u7684\u4f5c\u7528\u662f\u5426\u5927\u4e8eQC\u7cfb\u7edf\u6240\u5e26\u6765\u7684\u5f00\u9500\u3002\u4f46\u662f\u6709\u4e00\u70b9\u662f\u5f88\u80af\u5b9a\u7684\uff0cQC\u7f13\u5b58\u7684\u4f5c\u7528\u662f\u5f88\u5fae\u5c0f\u7684\uff0c\u5982\u679c\u5e94\u7528\u5c42\u80fd\u591f\u5b9e\u73b0\u7f13\u5b58\uff0c\u5c06\u53ef\u4ee5\u5ffd\u7565QC\u7684\u6548\u679c\u3002<\/p>\n<p style=\"text-align: left;\">&#8212;&#8212;&#8212;&#8212;-\u4e0b\u9762\u662f\u5173\u4e8eQC\u7684\u4e00\u4e9b\u5176\u4ed6\u7ec6\u8282&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"text-align: left;\">\u4e00\u3001Query Cache\u76f8\u5173\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-system-variables.html#sysvar_query_cache_size\">query_cache_size<\/a> QC\u5360\u7528\u7a7a\u95f4\u5927\u5c0f\uff0c\u901a\u8fc7\u5c06\u5176\u8bbe\u7f6e\u4e3a0\u5173\u95edQC\u529f\u80fd<\/li>\n<li>query_cache_type 0\u8868\u793a\u5173\u95edQC\uff1b1\u8868\u793a\u6b63\u5e38\u7f13\u5b58\uff1b2\u8868\u793aSQL_CACHE\u624d\u7f13\u5b58<\/li>\n<li>query_cache_limit \u6700\u5927\u7f13\u5b58\u7ed3\u679c\u96c6<\/li>\n<li>query_cache_min_res_unit \u624b\u518c\u4e0a\u8bf4\uff0cQC\u4f1a\u6309\u7167\u8fd9\u4e2a\u503c\u5206\u914d\u7f13\u5b58block\u7684\u5927\u5c0f\u3002<\/li>\n<li><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-status-variables.html#statvar_Qcache_lowmem_prunes\">Qcache_lowmem_prunes<\/a> \u8fd9\u662f\u4e00\u4e2a\u72b6\u6001\u53d8\u91cf(show status)\uff0c\u5f53\u7f13\u5b58\u7a7a\u95f4\u4e0d\u591f\u9700\u8981\u91ca\u653e\u65e7\u7684\u7f13\u5b58\u65f6\uff0c\u8be5\u503c\u4f1a\u81ea\u589e\u3002<\/li>\n<\/ul>\n<p style=\"text-align: left;\">\u4e8c\u3001Query Cache\u89c2\u5bdf\uff1a<\/p>\n<pre class=\"brush:sql\">CREATE TABLE t1(id INT,var1 varchar(10));\r\n\t\/\/Com_select:8\tQcache_hits:1\r\nINSERT INTO t1 VALUES(1,\u2019WWW\u2019);\r\n\t\/\/Com_select:8\tQcache_hits:1\r\nSELECT * FROM t1 WHERE id=1;\r\n\t\/\/Com_select:9\tQcache_hits:1\r\nSELECT * FROM t1 WHERE id=1;\r\n\t\/\/Com_select:9\tQcache_hits:2 Qcache_queries_in_cache:1\r\nINSERT INTO t1 VALUES(2,\u2019RRRR\u2019);\r\n\t\/\/Com_select:9\tQcache_hits:2 Qcache_queries_in_cache:0\r\nSELECT * FROM t1 WHERE id=1; \/\/INSERT\u540eCache\u5931\u6548\r\n\t\/\/Com_select:10  Qcache_hits:2 Qcache_queries_in_cache:1<\/pre>\n<p>\u53c2\u8003\uff1a<\/p>\n<ol>\n<li><a title=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/query-cache.html\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/query-cache.html\">http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/query-cache.html<\/a><\/li>\n<li><a title=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/query-cache.html\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/query-cache.html\"><\/a><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-system-variables.html#sysvar_query_cache_min_res_unit\">http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-system-variables.html<\/a><\/li>\n<li><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-system-variables.html#sysvar_query_cache_min_res_unit\"><\/a><a href=\"http:\/\/www.mysqlperformanceblog.com\/2006\/07\/27\/mysql-query-cache\/\">http:\/\/www.mysqlperformanceblog.com\/2006\/07\/27\/mysql-query-cache\/<\/a><\/li>\n<\/ol>\n<p>(\u5168\u6587\u5b8c)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u7684\u6570\u636e\u5e93\u6253\u5f00\u4e86Query Cache\uff08\u7b80\u79f0QC\uff09\u529f\u80fd\u540e\uff0c\u6570\u636e\u5e93\u5728\u6267\u884cSELECT\u8bed\u53e5\u65f6\uff0c\u4f1a\u5c06\u5176\u7ed3\u679c\u653e\u5230QC\u4e2d\uff0c\u5f53\u4e0b\u4e00\u6b21\u5904\u7406\u540c\u6837\u7684SELECT\u8bf7\u6c42\u65f6\uff0c\u6570\u636e\u5e93\u5c31\u4f1a\u4eceQC\u53d6\u5f97\u7ed3\u679c\uff0c\u800c\u4e0d\u9700\u8981\u53bb\u6570\u636e\u8868\u4e2d\u67e5\u8be2\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[26,45],"class_list":["post-669","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-query-cache","tag-45"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=669"}],"version-history":[{"count":24,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/669\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/669\/revisions\/692"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}