{"id":1901,"date":"2019-07-18T08:09:32","date_gmt":"2019-07-18T00:09:32","guid":{"rendered":"https:\/\/coderbee.net\/?p=1901"},"modified":"2019-07-18T07:05:18","modified_gmt":"2019-07-17T23:05:18","slug":"mysql-icp-%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/db\/20190718\/1901","title":{"rendered":"MySQL ICP \u7d22\u5f15\u6761\u4ef6\u4e0b\u63a8\u4f18\u5316"},"content":{"rendered":"<p>ICP \u4f18\u5316\u7684\u5168\u79f0\u662f Index Condition Pushdown Optimization \u3002<\/p>\n<p>ICP \u4f18\u5316\u9002\u7528\u4e8e MySQL \u5229\u7528\u7d22\u5f15\u4ece\u8868\u91cc\u68c0\u7d22\u6570\u636e\u7684\u573a\u666f\u3002<\/p>\n<h2>ICP \u9002\u7528\u7684\u573a\u666f<\/h2>\n<ul>\n<li>ICP \u7528\u4e8e\u8bbf\u95ee\u65b9\u6cd5\u662f <code>range\/ref\/eq_ref\/ref_or_null<\/code>\uff0c\u4e14\u9700\u8981\u8bbf\u95ee\u8868\u7684\u5b8c\u6574\u884c\u8bb0\u5f55\u3002<\/li>\n<li>ICP\u9002\u7528\u4e8e InnoDB \u548c MyISAM \u7684\u8868\uff0c\u5305\u62ec\u5206\u533a\u7684\u8868\u3002<\/li>\n<li>\u5bf9\u4e8e InnoDB \u8868\uff0cICP\u53ea\u9002\u7528\u4e8e\u4e8c\u7ea7\u7d22\u5f15\u3002ICP \u7684\u76ee\u6807\u662f\u51cf\u5c11\u8bbf\u95ee\u8868\u7684\u5b8c\u6574\u884c\u7684\u8bfb\u6570\u91cf\u4ece\u800c\u51cf\u5c11 I\/O \u64cd\u4f5c\u3002\u5bf9\u4e8e InnoDB \u7684\u805a\u7c07\u7d22\u5f15\uff0c\u5b8c\u6574\u7684\u8bb0\u5f55\u5df2\u7ecf\u8bfb\u8fdb InnoDB \u7684\u7f13\u5b58\uff0c\u4f7f\u7528 ICP \u4e0d\u80fd\u51cf\u5c11 I\/O \u3002<\/li>\n<li>ICP \u4e0d\u652f\u6301\u5efa\u7acb\u5728\u865a\u62df\u5217\u4e0a\u7684\u4e8c\u7ea7\u7d22\u5f15\u3002InnoDB \u652f\u6301\u5728\u865a\u62df\u5217\u4e0a\u5efa\u7acb\u4e8c\u7ea7\u7d22\u5f15\u3002<\/li>\n<li>\u5f15\u7528\u5b50\u67e5\u8be2\u3001\u5b58\u50a8\u51fd\u6570\u7684\u6761\u4ef6\u6ca1\u6cd5\u4e0b\u63a8\u3002<\/li>\n<li>Triggered conditions \u4e5f\u6ca1\u6cd5\u4e0b\u63a8\u3002<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h2>ICP \u539f\u7406<\/h2>\n<p>\u4ee5 InnoDB \u8868\u4e3a\u4f8b\u3002<\/p>\n<p>\u5728\u4e0d\u542f\u7528 ICP \u7684\u60c5\u51b5\u4e0b\u5229\u7528\u4e8c\u7ea7\u7d22\u5f15\u67e5\u627e\u6570\u636e\u7684\u8fc7\u7a0b\uff1a<br \/>\n1. \u7528\u4e8c\u7ea7\u7d22\u5f15\u67e5\u627e\u6570\u636e\u7684\u4e3b\u952e\uff1b<br \/>\n2. \u7528\u4e3b\u952e\u56de\u8868\u8bfb\u53d6\u5b8c\u6574\u7684\u884c\u8bb0\u5f55\uff1b<br \/>\n3. \u5229\u7528 where \u8bed\u53e5\u7684\u6761\u4ef6\u5bf9\u884c\u8bb0\u5f55\u8fdb\u884c\u8fc7\u6ee4\u3002<\/p>\n<p>\u542f\u7528 ICP \u7684\u60c5\u51b5\u4e0b\u5229\u7528\u4e8c\u7ea7\u7d22\u5f15\u67e5\u627e\u6570\u636e\u7684\u8fc7\u7a0b\u4e3a\uff1a<br \/>\n1. \u7528\u4e8c\u7ea7\u7d22\u5f15\u67e5\u627e\u6570\u636e\u7684\u4e3b\u952e\uff1b<br \/>\n2. \u5982\u679c\u4e8c\u7ea7\u7d22\u5f15\u8bb0\u5f55\u7684\u5143\u7ec4\u91cc\u7684\u5217\u51fa\u73b0\u5728 where \u6761\u4ef6\u91cc\uff0c\u90a3\u4e48\u5bf9\u5143\u7ec4\u8fdb\u884c\u8fc7\u6ee4\uff1b<br \/>\n3. \u5bf9\u7d22\u5f15\u5143\u7ec4\u7684\u4e3b\u952e\u56de\u8868\u8bfb\u53d6\u5b8c\u6574\u7684\u884c\u8bb0\u5f55\uff1b<br \/>\n4. \u5229\u7528 where \u8bed\u53e5\u7684\u5269\u4f59\u6761\u4ef6\u5bf9\u884c\u8bb0\u5f55\u8fdb\u884c\u8fc7\u6ee4\uff1b<\/p>\n<p>ICP \u9002\u7528\u7684\u4e00\u4e2a\u9690\u542b\u524d\u63d0\u662f\u4e8c\u7ea7\u7d22\u5f15\u5fc5\u987b\u662f\u7ec4\u5408\u7d22\u5f15\u3001\u4e14\u5728\u4f7f\u7528\u7d22\u5f15\u8fdb\u884c\u626b\u63cf\u65f6\u53ea\u80fd\u91c7\u7528\u6700\u5de6\u524d\u7f00\u5339\u914d\u539f\u5219\u3002\u7ec4\u5408\u7d22\u5f15\u540e\u9762\u7684\u5217\u51fa\u73b0\u5728 where \u6761\u4ef6\u91cc\uff0c\u56e0\u6b64\u53ef\u4ee5\u5148\u8fc7\u6ee4\u7d22\u5f15\u5143\u7ec4\u3001\u4ece\u800c\u51cf\u5c11\u56de\u8868\u8bfb\u7684\u6570\u91cf\u3002<\/p>\n<h2>\u4e3e\u4f8b<\/h2>\n<p>\u5bf9\u4e8e\u7ec4\u5408\u7d22\u5f15 <code>INDEX (zipcode, lastname, firstname)<\/code>\uff0c\u4e0b\u9762\u7684 SQL \u6839\u636e\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u53ea\u80fd\u4f7f\u7528\u5230\u7d22\u5f15\u7684\u7b2c\u4e00\u5217 <code>zipcode<\/code>\uff0c\u7d22\u5f15\u7684\u53e6\u4e00\u5217 <code>lastname<\/code> \u51fa\u73b0\u5728 where \u6761\u4ef6\u91cc\uff0c\u53ef\u4ee5\u91c7\u7528 ICP \u5bf9\u7d22\u5f15\u7684\u5143\u7ec4\u8fdb\u884c\u8fc7\u6ee4\uff0c\u5373\u5e94\u7528 <code>lastname LIKE '%etrunia%'<\/code> \u6761\u4ef6\uff1b\u7136\u540e\u518d\u56de\u8868\u8bfb\u53d6\u5b8c\u6210\u7684\u884c\u8bb0\u5f55\uff0c\u518d\u5bf9\u884c\u8bb0\u5f55\u5e94\u7528 <code>address LIKE '%Main Street%'<\/code> \u6761\u4ef6\u3002<\/p>\n<pre><code class=\"sql\">SELECT * FROM people\nWHERE zipcode='95054'\nAND lastname LIKE '%etrunia%'\nAND address LIKE '%Main Street%';\n<\/code><\/pre>\n<hr \/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ICP \u4f18\u5316\u7684\u5168\u79f0\u662f Index Condition Pushdown Opti &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/db\/20190718\/1901\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[316,149,317],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1901"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=1901"}],"version-history":[{"count":2,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1901\/revisions"}],"predecessor-version":[{"id":1903,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1901\/revisions\/1903"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=1901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=1901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=1901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}