{"id":188210,"date":"2024-11-11T20:45:24","date_gmt":"2024-11-11T12:45:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/188210\/"},"modified":"2024-11-11T20:45:25","modified_gmt":"2024-11-11T12:45:25","slug":"%e6%89%80%e7%94%a8mysql%e7%b4%a2%e5%bc%95%e9%a1%9e%e5%9e%8b%e7%9a%84%e6%87%89%e7%94%a8%e8%88%87%e5%89%b5%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/188210\/","title":{"rendered":"\u6240\u7528MySQL\u7d22\u5f15\u985e\u578b\u7684\u61c9\u7528\u8207\u5275\u5efa"},"content":{"rendered":"<h1 id=\"%e6%89%80%e7%94%a8mysql%e7%b4%a2%e5%bc%95%e9%a1%9e%e5%9e%8b%e7%9a%84%e6%87%89%e7%94%a8%e8%88%87%e5%89%b5%e5%bb%ba-lqvPzCKARG\">\u6240\u7528MySQL\u7d22\u5f15\u985e\u578b\u7684\u61c9\u7528\u8207\u5275\u5efa<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7d22\u5f15\u662f\u4e00\u7a2e\u91cd\u8981\u7684\u6578\u64da\u7d50\u69cb\uff0c\u7528\u65bc\u63d0\u9ad8\u67e5\u8a62\u6548\u7387\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u7d22\u5f15\u985e\u578b\uff0c\u6bcf\u7a2e\u7d22\u5f15\u90fd\u6709\u5176\u7279\u5b9a\u7684\u61c9\u7528\u5834\u666f\u548c\u5275\u5efa\u65b9\u6cd5\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eMySQL\u4e2d\u5e38\u898b\u7684\u7d22\u5f15\u985e\u578b\u53ca\u5176\u61c9\u7528\uff0c\u4e26\u63d0\u4f9b\u76f8\u61c9\u7684\u5275\u5efa\u793a\u4f8b\u3002<\/p>\n<h2 id=\"1-%e7%b4%a2%e5%bc%95%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-lqvPzCKARG\">1. \u7d22\u5f15\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u7d22\u5f15\u662f\u6578\u64da\u5eab\u8868\u4e2d\u4e00\u500b\u6216\u591a\u500b\u5217\u7684\u6578\u64da\u7d50\u69cb\uff0c\u65e8\u5728\u52a0\u901f\u67e5\u8a62\u64cd\u4f5c\u3002\u901a\u904e\u4f7f\u7528\u7d22\u5f15\uff0c\u6578\u64da\u5eab\u53ef\u4ee5\u66f4\u5feb\u5730\u5b9a\u4f4d\u5230\u6240\u9700\u7684\u6578\u64da\uff0c\u800c\u7121\u9700\u6383\u63cf\u6574\u500b\u8868\u3002\u9019\u5c0d\u65bc\u5927\u578b\u6578\u64da\u96c6\u5c24\u70ba\u91cd\u8981\uff0c\u56e0\u70ba\u5168\u8868\u6383\u63cf\u6703\u6d88\u8017\u5927\u91cf\u7684\u6642\u9593\u548c\u8cc7\u6e90\u3002<\/p>\n<h2 id=\"2-mysql%e4%b8%ad%e7%9a%84%e7%b4%a2%e5%bc%95%e9%a1%9e%e5%9e%8b-lqvPzCKARG\">2. MySQL\u4e2d\u7684\u7d22\u5f15\u985e\u578b<\/h2>\n<h3 id=\"2-1-b-tree%e7%b4%a2%e5%bc%95-lqvPzCKARG\">2.1 B-Tree\u7d22\u5f15<\/h3>\n<p>B-Tree\u7d22\u5f15\u662fMySQL\u4e2d\u6700\u5e38\u7528\u7684\u7d22\u5f15\u985e\u578b\u3002\u5b83\u9069\u7528\u65bc\u5927\u591a\u6578\u67e5\u8a62\uff0c\u7279\u5225\u662f\u7bc4\u570d\u67e5\u8a62\u548c\u6392\u5e8f\u64cd\u4f5c\u3002B-Tree\u7d22\u5f15\u7684\u7d50\u69cb\u4f7f\u5f97\u67e5\u8a62\u6548\u7387\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u52a0\u800c\u4fdd\u6301\u7a69\u5b9a\u3002<\/p>\n<pre><code>CREATE INDEX idx_name ON table_name (column_name);<\/code><\/pre>\n<h3 id=\"2-2-%e5%93%88%e5%b8%8c%e7%b4%a2%e5%bc%95-lqvPzCKARG\">2.2 \u54c8\u5e0c\u7d22\u5f15<\/h3>\n<p>\u54c8\u5e0c\u7d22\u5f15\u4e3b\u8981\u7528\u65bc\u7b49\u503c\u67e5\u8a62\u3002\u5b83\u901a\u904e\u5c07\u7d22\u5f15\u9375\u6620\u5c04\u5230\u54c8\u5e0c\u8868\u4e2d\u4f86\u52a0\u901f\u67e5\u8a62\uff0c\u4f46\u4e0d\u652f\u6301\u7bc4\u570d\u67e5\u8a62\u3002\u54c8\u5e0c\u7d22\u5f15\u7684\u67e5\u8a62\u901f\u5ea6\u975e\u5e38\u5feb\uff0c\u4f46\u5728\u6578\u64da\u66f4\u65b0\u6642\u53ef\u80fd\u6703\u5c0e\u81f4\u6027\u80fd\u4e0b\u964d\u3002<\/p>\n<pre><code>CREATE INDEX idx_name USING HASH ON table_name (column_name);<\/code><\/pre>\n<h3 id=\"2-3-%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95-lqvPzCKARG\">2.3 \u5168\u6587\u7d22\u5f15<\/h3>\n<p>\u5168\u6587\u7d22\u5f15\u5c08\u9580\u7528\u65bc\u6587\u672c\u641c\u7d22\uff0c\u9069\u5408\u65bc\u9700\u8981\u9032\u884c\u95dc\u9375\u5b57\u67e5\u8a62\u7684\u5834\u666f\u3002\u5b83\u53ef\u4ee5\u5728\u5927\u91cf\u6587\u672c\u6578\u64da\u4e2d\u5feb\u901f\u627e\u5230\u5339\u914d\u7684\u8a18\u9304\uff0c\u4e26\u652f\u6301\u81ea\u7136\u8a9e\u8a00\u67e5\u8a62\u3002<\/p>\n<pre><code>CREATE FULLTEXT INDEX idx_name ON table_name (column_name);<\/code><\/pre>\n<h3 id=\"2-4-%e7%a9%ba%e9%96%93%e7%b4%a2%e5%bc%95-lqvPzCKARG\">2.4 \u7a7a\u9593\u7d22\u5f15<\/h3>\n<p>\u7a7a\u9593\u7d22\u5f15\u4e3b\u8981\u7528\u65bc\u5730\u7406\u6578\u64da\u985e\u578b\uff0c\u652f\u6301\u7a7a\u9593\u67e5\u8a62\u3002\u9019\u985e\u7d22\u5f15\u5728\u8655\u7406\u5730\u7406\u4fe1\u606f\u7cfb\u7d71\uff08GIS\uff09\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>CREATE SPATIAL INDEX idx_name ON table_name (column_name);<\/code><\/pre>\n<h2 id=\"3-%e7%b4%a2%e5%bc%95%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-lqvPzCKARG\">3. \u7d22\u5f15\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<ul>\n<li><strong>\u67e5\u8a62\u512a\u5316\uff1a<\/strong>\u4f7f\u7528\u7d22\u5f15\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u5927\u578b\u6578\u64da\u96c6\u4e0a\u3002<\/li>\n<li><strong>\u6392\u5e8f\u64cd\u4f5c\uff1a<\/strong>\u7d22\u5f15\u53ef\u4ee5\u52a0\u901fORDER BY\u548cGROUP BY\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u552f\u4e00\u6027\u7d04\u675f\uff1a<\/strong>\u901a\u904e\u552f\u4e00\u7d22\u5f15\uff0c\u53ef\u4ee5\u78ba\u4fdd\u67d0\u5217\u7684\u6578\u64da\u552f\u4e00\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"4-%e5%89%b5%e5%bb%ba%e7%b4%a2%e5%bc%95%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-lqvPzCKARG\">4. \u5275\u5efa\u7d22\u5f15\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u5275\u5efa\u7d22\u5f15\u6642\uff0c\u9700\u8981\u8003\u616e\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u7d22\u5f15\u6703\u4f54\u7528\u984d\u5916\u7684\u5b58\u5132\u7a7a\u9593\uff0c\u56e0\u6b64\u61c9\u6839\u64da\u5be6\u969b\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u7d22\u5f15\u985e\u578b\u3002<\/li>\n<li>\u904e\u591a\u7684\u7d22\u5f15\u6703\u5f71\u97ff\u6578\u64da\u7684\u63d2\u5165\u3001\u66f4\u65b0\u548c\u522a\u9664\u6027\u80fd\uff0c\u56e0\u6b64\u61c9\u8b39\u614e\u4f7f\u7528\u3002<\/li>\n<li>\u5b9a\u671f\u6aa2\u67e5\u548c\u7dad\u8b77\u7d22\u5f15\uff0c\u4ee5\u78ba\u4fdd\u5176\u6027\u80fd\u548c\u6709\u6548\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-lqvPzCKARG\">\u7e3d\u7d50<\/h2>\n<p>MySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u7d22\u5f15\u985e\u578b\uff0c\u6bcf\u7a2e\u7d22\u5f15\u90fd\u6709\u5176\u7279\u5b9a\u7684\u61c9\u7528\u5834\u666f\u548c\u5275\u5efa\u65b9\u6cd5\u3002\u9078\u64c7\u5408\u9069\u7684\u7d22\u5f15\u985e\u578b\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u67e5\u8a62\u6027\u80fd\u3002\u5728\u4f7f\u7528\u7d22\u5f15\u6642\uff0c\u61c9\u6839\u64da\u5be6\u969b\u9700\u6c42\u9032\u884c\u5408\u7406\u914d\u7f6e\uff0c\u4ee5\u9054\u5230\u6700\u4f73\u6548\u679c\u3002\u5982\u679c\u60a8\u9700\u8981\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u6258\u7ba1\u60a8\u7684MySQL\u6578\u64da\u5eab\uff0c\u4eab\u53d7\u7a69\u5b9a\u548c\u5feb\u901f\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22MySQL\u7d22\u5f15\u985e\u578b\u7684\u61c9\u7528\u8207\u5275\u5efa\uff0c\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\uff0c\u512a\u5316\u67e5\u8a62\u901f\u5ea6\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-188210","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/188210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=188210"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/188210\/revisions"}],"predecessor-version":[{"id":188211,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/188210\/revisions\/188211"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=188210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=188210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=188210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}