{"id":31953,"date":"2023-05-27T15:57:42","date_gmt":"2023-05-27T07:57:42","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=31953"},"modified":"2023-07-31T01:57:17","modified_gmt":"2023-07-30T17:57:17","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88mysql-innoddb%e4%b8%ad%e7%bb%84%e5%90%88%e7%b4%a2%e5%bc%95%e4%b8%ad%e8%8c%83%e5%9b%b4%e6%9f%a5%e8%af%a2%e5%90%8e%e7%9a%84%e6%9d%a1%e4%bb%b6%e7%b4%a2%e5%bc%95%e4%bc%9a","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/31953.html","title":{"rendered":"\u4e3a\u4ec0\u4e48mysql innodDB\u4e2d\u7ec4\u5408\u7d22\u5f15\u4e2d\u8303\u56f4\u67e5\u8be2\u540e\u7684\u6761\u4ef6\u7d22\u5f15\u4f1a\u5931\u6548"},"content":{"rendered":"<blockquote class=\"wp-block-quote\">\n<p>mysql innodDB\u4e2d\u7ec4\u5408\u7d22\u5f15\u4e2d\u8303\u56f4\u67e5\u8be2\u540e\u7684\u6761\u4ef6\u7d22\u5f15\u4f1a\u5931\u6548\u7684\u539f\u56e0\uff1a\u8303\u56f4\u67e5\u8be2\u64cd\u4f5c\u65f6MySQL\u9700\u8981\u5bf9\u7ec4\u5408\u7d22\u5f15\u4e2d\u7684\u975e\u8303\u56f4\u67e5\u8be2\u6761\u4ef6\u9010\u4e2a\u8fdb\u884c\u68c0\u67e5\uff0c\u7531\u4e8e\u8303\u56f4\u67e5\u8be2\u64cd\u4f5c\u4e0d\u8fde\u7eed\uff0c\u4f1a\u8d85\u8fc7MySQL\u7684\u6700\u5927\u884c\u6570\u9650\u5236\uff0c\u5bfc\u81f4MySQL\u653e\u5f03\u4f7f\u7528\u8fd9\u4e2a\u7ec4\u5408\u7d22\u5f15\u3002<\/p>\n<\/blockquote>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" alt=\"\" class=\"wp-image-31954\" decoding=\"async\" height=\"576\" sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701-1024x576.jpg?x-oss-process=image\/auto-orient,1\/format,webp\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701-1024x576.jpg?x-oss-process=image\/auto-orient,1\/format,webp 1024w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701-300x169.jpg 300w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701-768x432.jpg 768w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701-270x152.jpg 270w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701-1536x865.jpg 1536w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/052701.jpg 1993w\" width=\"1024\"\/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">\u4e00\u3001mysql innodDB\u4e2d\u7ec4\u5408\u7d22\u5f15\u4e2d\u8303\u56f4\u67e5\u8be2\u540e\u7684\u6761\u4ef6\u7d22\u5f15\u4f1a\u5931\u6548\u7684\u539f\u56e0<\/h2>\n<p>\u8868\u5efa\u7acb\u8054\u5408\u7d22\u5f15(a,b,c)\uff0c\u67e5\u8be2\u6761\u4ef6a=1,b&gt;2,c=3\uff0c\u6b64\u65f6c\u6761\u4ef6\u7684\u7d22\u5f15\u4f1a\u5931\u6548\u3002\u7b80\u5355\u70b9\u6765\u8bf4\uff0c\u8be5\u7ec4\u5408\u7d22\u5f15\u662f\u4e00\u4e2a\u4ee5a\u5b57\u6bb5\u6392\u5e8f\u800cb\u4e0ec\u76f8\u5bf9\u6709\u5e8f\u7684B+\u6811\uff0c\u5f15\u64ce\u53ef\u4ee5\u901a\u8fc7\u4e8c\u5206\u67e5\u627e\u5b9a\u4f4d\u5230a=1\u7684\u6570\u636e\uff0cb\u5728a=1\u786e\u5b9a\u5f97\u60c5\u51b5\u4e0b\u662f\u6709\u5e8f\u7684\uff08\u6240\u4ee5b\u7684\u6709\u5e8f\u662f\u76f8\u5bf9\u7684\uff09\uff0c\u4f9d\u7136\u53ef\u4ee5\u901a\u8fc7\u4e8c\u5206\u67e5\u627e\u53d6\u51fa\u6240\u6709b\u5927\u4e8e2\u7684\u6570\u636e\uff0c\u4f46\u8fd9\u4e9b\u6570\u636e\u7684b\u5b57\u6bb5\u53ef\u80fd\u6709\u5f88\u591a\u4e2a\u4e0d\u540c\u7684\u503c\uff0c\u6240\u4ee5c\u5b57\u6bb5\u662f\u65e0\u5e8f\u7684\uff0c\u65e0\u6cd5\u7528\u4e8c\u5206\u67e5\u627e\u6765\u67e5\u8be2c=3\u7684\u6570\u636e\uff0c\u6545c\u7528\u4e0d\u5230\u7d22\u5f15\u3002<\/p>\n<p>\u5f53\u8fdb\u884c\u8303\u56f4\u67e5\u8be2\u64cd\u4f5c\u65f6\uff0cMySQL\u9700\u8981\u5bf9\u7ec4\u5408\u7d22\u5f15\u4e2d\u7684\u975e\u8303\u56f4\u67e5\u8be2\u6761\u4ef6\u9010\u4e2a\u8fdb\u884c\u68c0\u67e5\uff0c\u4ee5\u8fc7\u6ee4\u6389\u4e0d\u7b26\u5408\u8981\u6c42\u7684\u8bb0\u5f55\uff0c\u76f4\u81f3\u626b\u63cf\u5230\u8303\u56f4\u67e5\u8be2\u6761\u4ef6\u65f6\uff0c\u7531\u4e8e\u8303\u56f4\u67e5\u8be2\u64cd\u4f5c\u5177\u6709\u4e0d\u8fde\u7eed\u7684\u7279\u70b9\uff0c\u56e0\u6b64\u8fd9\u4e2a\u8303\u56f4\u67e5\u8be2\u6761\u4ef6\u4e4b\u540e\u7684\u8bb0\u5f55\u6570\u636e\u91cf\u4f1a\u53d8\u5f97\u975e\u5e38\u5927\uff0c\u901a\u5e38\u4f1a\u8d85\u8fc7MySQL\u7684\u6700\u5927\u884c\u6570\u9650\u5236\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86MySQL\u653e\u5f03\u4f7f\u7528\u8fd9\u4e2a\u7ec4\u5408\u7d22\u5f15\uff0c\u800c\u6539\u4e3a\u5168\u8868\u626b\u63cf\uff08full table scan\uff09\u6765\u83b7\u53d6\u7ed3\u679c\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u8303\u56f4\u67e5\u8be2\u64cd\u4f5c\u5bb9\u6613\u5bfc\u81f4MySQL\u67e5\u8be2\u6027\u80fd\u964d\u4f4e\u7684\u539f\u56e0\u4e4b\u4e00\u3002<\/p>\n<p>\u4f8b\u5982\u5b58\u5728\u7d22\u5f15\u6570\u636e\u5982\uff1a(a=1,b=3,c=3)\uff0c(a=1,b=4,c=0)\uff0c(a=1,b=4,c=3)\uff0c(a=1,b=4,c=0)\u3002\u4e0a\u8ff0\u6570\u636e\u5747\u6ee1\u8db3a=1&amp;b&gt;2\uff0c\u4f46\u662fc\u7684\u6570\u636e\u5374\u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u6240\u4ee5\u6ca1\u6709\u529e\u6cd5\u901a\u8fc7c\u7d22\u5f15\u8fdb\u884c\u8fc7\u6ee4\uff0c\u6240\u4ee5\u5b57\u6bb5c\u5e76\u4e0d\u80fd\u591f\u53c2\u4e0e\u5230\u7d22\u5f15\u5237\u9009\u4e2d\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u7ec4\u5408\u7d22\u5f15<\/h2>\n<h3 class=\"wp-block-heading\">1\u3001\u7ec4\u5408\u7d22\u5f15\u7684\u4f7f\u7528<\/h3>\n<p>\u672c\u6587\u4e2d\u7ec4\u5408\u7d22\u5f15\u7684\u5b9a\u4e49\u4e3a\uff08MySQL\uff09\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>ALTER TABLE table_name ADD INDEX (col1,col2,col3);<\/code><\/pre>\n<h3 class=\"wp-block-heading\">2\u3001\u7ec4\u5408\u7d22\u5f15\u7684\u672c\u8d28<\/h3>\n<p>\u5f53\u521b\u5efa(col1,col2,col3)\u7ec4\u5408\u7d22\u5f15\u65f6\uff0c\u76f8\u5f53\u4e8e\u521b\u5efa\u4e86(col)\u5355\u5217\u7d22\u5f15\uff0c(clo1,clo2)\u7ec4\u5408\u7d22\u5f15\u4ee5\u53ca(col1,col2,col3)\u7ec4\u5408\u7d22\u5f15\u60f3\u8981\u7d22\u5f15\u751f\u6548\uff0c\u53ea\u80fd\u4f7f\u7528col1\u548ccol1,col2\u548ccol1,col2,col3\u4e09\u79cd\u7ec4\u5408\uff1b\u5f53\u7136\uff0ccol1,col3\u7ec4\u5408\u4e5f\u53ef\u4ee5\uff0c\u4f46\u5b9e\u9645\u4e0a\u53ea\u7528\u5230\u4e86col1\u7684\u7d22\u5f15\uff0ccol3\u5e76\u6ca1\u6709\u7528\u5230\u3002<\/p>\n<h3 class=\"wp-block-heading\">3\u3001\u793a\u4f8b<\/h3>\n<p>\u7ec4\u5408\u7d22\u5f15\u76f8\u5f53\u4e8e\u4e00\u4e2a\u6309\u7167\u59d3\u6c0f\u2014\u2014\u540d\u5b57\u7684\u4e00\u4e2a\u7535\u8bdd\u7c3f\uff0c\u53ea\u80fd\u5148\u786e\u5b9a\u59d3\u6c0f\u624d\u53ef\u4ee5\u547d\u4e2d\u7d22\u5f15\uff0c\u4e0b\u5217\u53ef\u4ee5\u6b63\u786e\u547d\u4e2d\u7ec4\u5408\u7d22\u5f15\u7684\u8bed\u53e5\uff08 = \u548cIN\u76f4\u63a5\u7684\u5b57\u6bb5\u90fd\u53ef\u4ee5\u4e71\u5e8f\uff0cMySQL\u7684\u67e5\u8be2\u4f18\u5316\u5668\u53ef\u4ee5\u4f18\u5316\u6210\u7d22\u5f15\u8bc6\u522b\u7684\u5f62\u5f0f\uff09<\/p>\n<p>\u4f7f\u7528\u5230\u7d22\u5f15\u7684\u60c5\u51b5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>col_a = \"some value\"\n\ncol_a = \"some value\" and col_b = \"some value\"\n\ncol_a = \"some value\" and col_c = \"some value\"\n\ncol_a = \"some value\" and col_b = \"some value\" and col_c = \"some value\"\n\ncol_a = \"some value\" and col_c = \"some value\" and col_b = \"some value\"\n\ncol_b = \"some value\" and col_a = \"some value\" and col_c = \"some value\"\n\ncol_b = \"some value\" and col_c = \"some value\" and col_a = \"some value\"\n\ncol_c = \"some value\" and col_a = \"some value\" and col_b = \"some value\"\n\ncol_c = \"some value\" and col_b = \"some value\" and col_a = \"some value\"<\/code><\/pre>\n<p>\u672a\u4f7f\u7528\u7d22\u5f15\u7684\u60c5\u51b5\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>col_b = \"some value\"\n\ncol_c = \"some value\"\n\ncol_b = \"some value\" and col_c = \"some value\"\n\ncol_c = \"some value\" and col_b = \"some value\"<\/code><\/pre>\n<p>\u603b\u7ed3\uff0c\u7ec4\u5408\u7d22\u5f15\u4ece\u6700\u5de6\u5f00\u59cb\u7ec4\u5408\uff0c\u53ea\u8981\u5305\u542b\u540d\u5217\u524d\u8305\u5217\u7684\u67e5\u8be2\u90fd\u4f1a\u7528\u5230\u8be5\u7ec4\u5408\u7d22\u5f15\u3002<\/p>\n<h3 class=\"wp-block-heading\">4\u3001\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u7ec4\u5408\u7d22\u5f15<\/h3>\n<ul>\n<li><strong>\u51cf\u5c11\u5f00\u9500<\/strong>\uff1a\u5efa\u4e00\u4e2a\u8054\u5408\u7d22\u5f15(col1,col2,col3)\uff0c\u5b9e\u9645\u76f8\u5f53\u4e8e\u5efa\u4e86(col1),(col1,col2),(col1,col2,col3)\u4e09\u4e2a\u7d22\u5f15\u3002\u6bcf\u591a\u4e00\u4e2a\u7d22\u5f15\uff0c\u90fd\u4f1a\u589e\u52a0\u5199\u64cd\u4f5c\u7684\u5f00\u9500\u548c\u78c1\u76d8\u7a7a\u95f4\u7684\u5f00\u9500\u3002\u5bf9\u4e8e\u5927\u91cf\u6570\u636e\u7684\u8868\uff0c\u4f7f\u7528\u7ec4\u5408\u7d22\u5f15\u4f1a\u5927\u5927\u7684\u51cf\u5c11\u5f00\u9500\u3002<\/li>\n<li><strong>\u8986\u76d6\u7d22\u5f15<\/strong>\uff1a\u5bf9\u7ec4\u5408\u7d22\u5f15(col1,col2,col3)\uff0c\u5982\u679c\u6709\u5982\u4e0b\u7684sql: select col1,col2,col3 from test where col1=1 and col2=2\u3002\u90a3\u4e48MySQL\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u904d\u5386\u7d22\u5f15\u53d6\u5f97\u6570\u636e\uff0c\u800c\u65e0\u9700\u56de\u8868\uff0c\u8fd9\u51cf\u5c11\u4e86\u5f88\u591a\u7684\u968f\u673aio\u64cd\u4f5c\u3002\u51cf\u5c11io\u64cd\u4f5c\uff0c\u7279\u522b\u7684\u968f\u673aio\u5176\u5b9e\u662fdba\u4e3b\u8981\u7684\u4f18\u5316\u7b56\u7565\u3002\u6240\u4ee5\uff0c\u5728\u771f\u6b63\u7684\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8986\u76d6\u7d22\u5f15\u662f\u4e3b\u8981\u7684\u63d0\u5347\u6027\u80fd\u7684\u4f18\u5316\u624b\u6bb5\u4e4b\u4e00\u3002<\/li>\n<li><strong>\u6548\u7387\u9ad8<\/strong>\uff1a\u7d22\u5f15\u5217\u8d8a\u591a\uff0c\u901a\u8fc7\u7d22\u5f15\u7b5b\u9009\u51fa\u7684\u6570\u636e\u8d8a\u5c11\u3002<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">5\u3001SQL\u4e2d\u7ec4\u5408\u7d22\u5f15\u548c\u666e\u901a\u7d22\u5f15\u533a\u522b<\/h3>\n<p>\u7ec4\u5408\u7d22\u5f15\u4e2d\u5217\u7684\u987a\u5e8f\u975e\u5e38\u91cd\u8981\uff0c<strong>\u4ece\u5de6\u539f\u5219<\/strong>\uff1aa,ab,ba,abc\u3002<\/p>\n<p>\u5355\u4e2a\u7d22\u5f15\uff1a\u4e00\u4e2a\u4e00\u4e2a\u8d77\u4f5c\u7528\uff0c\u4e5f\u5c31\u662f\u8bf4\u6709\u4e09\u4e2a\u5355\u4e2a\u7d22\u5f15\uff0c\u54ea\u4e2a\u6761\u4ef6\u67e5\u8be2\u5728\u524d\u54ea\u4e2a\u8d77\u4f5c\u7528\uff0c\u5176\u4ed6\u4e0d\u8d77\u4f5c\u7528\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong>\uff1a<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u5217\u8868\u641c\u7d22\u9700\u8981\u591a\u4e2a\u5217\u67e5\u8be2\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528\u8054\u5408\u7d22\u5f15\uff0c\u90fd\u662fand\u7684\u5173\u7cfb\u3002\u4ec0\u4e48\u65f6\u5019\u9700\u8981\u521b\u5efa\u7d22\u5f15\uff1a<\/p>\n<ul>\n<li>where\u6761\u4ef6\u4f1a\u7ecf\u5e38\u51fa\u73b0\u7684\uff0c\u5e76\u4e14\u5f53\u524d\u8868\u7684\u6570\u91cf\u6bd4\u8f83\u5927\u3002<\/li>\n<li>where\u6761\u4ef6\u4e2d\u662f\u7528and\u800c\u975eor\u7684\u65f6\u5019\u3002<\/li>\n<li>\u7ec4\u5408\u7d22\u5f15\u6bd4\u5355\u4e2a\u7d22\u5f15\u66f4\u9002\u5408\uff0c\u56e0\u4e3a\u7d22\u5f15\u5360\u7528\u4e00\u5b9a\u78c1\u76d8\u7a7a\u95f4\uff0c\u4e5f\u5c31\u8bf4\u660e\u6709\u4e00\u5b9a\u7684\u5f00\u9500\uff0c\u5982\u679c\u591a\u4e2a\u5355\u4e2a\u7d22\u5f15\u6bd4\u8f83\u591a\uff0c\u90a3\u4e48\u591a\u8d44\u6e90\u7684\u6d6a\u8d39\u4e5f\u6bd4\u8f83\u591a\uff0c\u7ec4\u5408\u7d22\u5f15\u76f8\u5f53\u4e8e\u5bf9\u591a\u4e2a\u5217\u5efa\u7d22\u5f15\uff0c\u5e76\u4e14\u53ea\u5efa\u4e00\u6b21\uff0cand\u6761\u4ef6\u4e0b\u975e\u5e38\u9002\u5408\u3002<\/li>\n<\/ul>\n<p><strong><em>\u5ef6\u4f38\u9605\u8bfb1\uff1aMySQL\u7b80\u4ecb<\/em><\/strong><\/p>\n<p>MySQL\u662f\u4e00\u4e2a\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u7531\u745e\u5178MySQL AB \u516c\u53f8\u5f00\u53d1\uff0c\u5c5e\u4e8e Oracle \u65d7\u4e0b\u4ea7\u54c1\u3002MySQL \u662f\u6700\u6d41\u884c\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u4e4b\u4e00\uff0c\u5728 WEB \u5e94\u7528\u65b9\u9762\uff0cMySQL\u662f\u8f83\u597d\u7684 RDBMS (Relational Database Management System\uff0c\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf) \u5e94\u7528\u8f6f\u4ef6\u4e4b\u4e00\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"mysql innodDB\u4e2d\u7ec4\u5408\u7d22\u5f15\u4e2d\u8303\u56f4\u67e5\u8be2\u540e\u7684\u6761\u4ef6\u7d22\u5f15\u4f1a\u5931\u6548\u7684\u539f\u56e0\uff1a\u8303\u56f4\u67e5\u8be2\u64cd\u4f5c\u65f6MySQL\u9700\u8981\u5bf9\u7ec4\u5408\u7d22\u5f15 [&hellip;]","protected":false},"author":1,"featured_media":31954,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[119],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/31953"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=31953"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/31953\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/31954"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=31953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=31953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=31953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}