{"id":5543,"date":"2024-11-14T12:21:25","date_gmt":"2024-11-14T04:21:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5543\/"},"modified":"2024-11-14T12:21:25","modified_gmt":"2024-11-14T04:21:25","slug":"mysql%e6%80%8e%e4%b9%88%e5%bb%ba%e7%ab%8b%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5543\/","title":{"rendered":"mysql\u600e\u4e48\u5efa\u7acb\u7d22\u5f15"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 mysql \u5efa\u7acb\u7d22\u5f15\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 create index \u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u65b0\u7d22\u5f15\uff0c\u4f8b\u5982\uff1acreate index user_idx on users (username);\u3002\u4f7f\u7528 alter table \u8bed\u53e5\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u7d22\u5f15\uff0c\u4f8b\u5982\uff1aalter table products add index product_category_idx (category);\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052908542336138.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u5efa\u7acb\u7d22\u5f15\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u5efa\u7acb\u7d22\u5f15\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u5efa\u7acb\u7d22\u5f15<\/strong><\/p>\n<p>\u7d22\u5f15\u662f MySQL \u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002\u901a\u8fc7\u5feb\u901f\u5b9a\u4f4d\u6240\u9700\u6570\u636e\uff0c\u7d22\u5f15\u907f\u514d\u4e86\u5bf9\u6574\u4e2a\u8868\u8fdb\u884c\u5168\u8868\u626b\u63cf\u3002<\/p>\n<p><strong>\u5efa\u7acb\u7d22\u5f15\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u53ef\u4ee5\u5efa\u7acb\u7d22\u5f15\uff1a<\/p>\n<ul>\n<li> <strong>CREATE INDEX \u8bed\u53e5\uff1a<\/strong>\u7528\u4e8e\u521b\u5efa\u65b0\u7d22\u5f15\u3002<\/li>\n<li> <strong>ALTER TABLE \u8bed\u53e5\uff1a<\/strong>\u7528\u4e8e\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<p><strong>CREATE INDEX \u8bed\u53e5<\/strong><\/p>\n<pre>CREATE INDEX index_name ON table_name (column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;user_idx&#8221; \u7684\u7d22\u5f15\uff0c\u7528\u4e8e\u8868 &#8220;users&#8221; \u7684 &#8220;username&#8221; \u5217\uff1a<\/p>\n<pre>CREATE INDEX user_idx ON users (username);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>ALTER TABLE \u8bed\u53e5<\/strong><\/p>\n<pre>ALTER TABLE table_name ADD INDEX index_name (column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u5411\u8868 &#8220;products&#8221; \u6dfb\u52a0\u4e00\u4e2a\u540d\u4e3a &#8220;product_category_idx&#8221; \u7684\u7d22\u5f15\uff0c\u7528\u4e8e &#8220;category&#8221; \u5217\uff1a<\/p>\n<pre>ALTER TABLE products ADD INDEX product_category_idx (category);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7d22\u5f15\u7c7b\u578b<\/strong><\/p>\n<p>MySQL \u652f\u6301\u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>B-Tree \u7d22\u5f15\uff1a<\/strong>\u9002\u7528\u4e8e\u5927\u91cf\u6570\u636e\u548c\u8303\u56f4\u67e5\u8be2\u3002<\/li>\n<li> <strong>\u54c8\u5e0c\u7d22\u5f15\uff1a<\/strong>\u9002\u7528\u4e8e\u5c0f\u578b\u6570\u636e\u548c\u7cbe\u786e\u5339\u914d\u67e5\u8be2\u3002<\/li>\n<li> <strong>\u5168\u6587\u7d22\u5f15\uff1a<\/strong>\u9002\u7528\u4e8e\u6587\u672c\u641c\u7d22\u3002<\/li>\n<\/ul>\n<p><strong>\u9009\u62e9\u6b63\u786e\u7684\u7d22\u5f15<\/strong><\/p>\n<p>\u9009\u62e9\u6b63\u786e\u7684\u7d22\u5f15\u7c7b\u578b\u548c\u5217\u5bf9\u4e8e\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u63d0\u793a\uff1a<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u9891\u7e41\u4f7f\u7528\u7684\u5217\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li>\u5bf9\u4e8e\u8303\u56f4\u67e5\u8be2\u6216\u6392\u5e8f\u521b\u5efa B-Tree \u7d22\u5f15\u3002<\/li>\n<li>\u5bf9\u4e8e\u7cbe\u786e\u5339\u914d\u67e5\u8be2\u521b\u5efa\u54c8\u5e0c\u7d22\u5f15\u3002<\/li>\n<li>\u5bf9\u4e8e\u5168\u6587\u641c\u7d22\u521b\u5efa\u5168\u6587\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5efa\u7acb\u7d22\u5f15\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 mysql \u5efa\u7acb\u7d22\u5f15\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 create index \u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u65b0\u7d22\u5f15\uff0c\u4f8b\u5982\uff1acreate index user_idx on users (username);\u3002\u4f7f\u7528 alter table \u8bed\u53e5\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u7d22\u5f15\uff0c\u4f8b\u5982\uff1aalter table products add index product_category_idx (category);\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u5efa\u7acb\u7d22\u5f15 \u7d22\u5f15\u662f MySQL \u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002\u901a\u8fc7\u5feb\u901f\u5b9a\u4f4d\u6240\u9700\u6570\u636e\uff0c\u7d22\u5f15\u907f\u514d\u4e86\u5bf9\u6574\u4e2a\u8868\u8fdb\u884c\u5168\u8868\u626b\u63cf\u3002 \u5efa\u7acb\u7d22\u5f15\u7684\u65b9\u6cd5 \u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u53ef\u4ee5\u5efa\u7acb\u7d22\u5f15\uff1a CREATE INDEX \u8bed\u53e5\uff1a\u7528\u4e8e\u521b\u5efa\u65b0\u7d22\u5f15\u3002 ALTER TABLE \u8bed\u53e5\uff1a\u7528\u4e8e\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u7d22\u5f15\u3002 CREATE INDEX \u8bed\u53e5 CREATE INDEX index_name ON table_name (column_name); \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;user_idx&#8221; \u7684\u7d22\u5f15\uff0c\u7528\u4e8e\u8868 &#8220;users&#8221; \u7684 &#8220;username&#8221; \u5217\uff1a CREATE INDEX user_idx ON [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5543","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5543"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5543\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}