{"id":6509,"date":"2024-08-29T20:25:54","date_gmt":"2024-08-29T12:25:54","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6509"},"modified":"2024-08-29T20:25:54","modified_gmt":"2024-08-29T12:25:54","slug":"innodb-%e5%bc%95%e6%93%8e%e4%b8%ad%e8%87%aa%e5%8a%a8%e5%88%9b%e5%bb%ba%e5%92%8c%e6%8c%89%e9%9c%80%e5%88%9b%e5%bb%ba%e7%9a%84%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6509","title":{"rendered":"InnoDB \u5f15\u64ce\u4e2d\u81ea\u52a8\u521b\u5efa\u548c\u6309\u9700\u521b\u5efa\u7684\u7d22\u5f15"},"content":{"rendered":"<blockquote>\n<p>\u975e\u539f\u521b\u3001ChatGPT \u95ee\u7b54\u751f\u6210<\/p>\n<\/blockquote>\n<p>\u5728 MySQL \u7684 InnoDB \u5f15\u64ce\u4e2d\uff0c\u7d22\u5f15\u6709\u4e9b\u662f\u9700\u8981\u624b\u52a8\u521b\u5efa\u7684\uff0c\u800c\u6709\u4e9b\u5219\u662f\u7531\u6570\u636e\u5e93\u5f15\u64ce\u81ea\u52a8\u6dfb\u52a0\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6982\u8ff0\uff1a<\/p>\n<h3>1. <strong>\u624b\u52a8\u521b\u5efa\u7684\u7d22\u5f15<\/strong><\/h3>\n<p>\u8fd9\u4e9b\u7d22\u5f15\u662f\u5f00\u53d1\u8005\u6839\u636e\u5e94\u7528\u9700\u6c42\u624b\u52a8\u521b\u5efa\u7684\uff0c\u7528\u4e8e\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n<ul>\n<li>\n<p><strong>\u4e3b\u952e\u7d22\u5f15\uff08Primary Key Index\uff09<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u4f60\u5728\u521b\u5efa\u8868\u65f6\u5b9a\u4e49\u4e86\u4e00\u4e2a\u4e3b\u952e\uff08PRIMARY KEY\uff09\uff0cInnoDB \u4f1a\u81ea\u52a8\u4e3a\u4e3b\u952e\u521b\u5efa\u4e00\u4e2a\u805a\u7c07\u7d22\u5f15\u3002<\/li>\n<li>\u5982\u679c\u8868\u6ca1\u6709\u4e3b\u952e\uff0cInnoDB \u4f1a\u81ea\u52a8\u9009\u62e9\u4e00\u4e2a\u552f\u4e00\u975e\u7a7a\u7684\u5217\u521b\u5efa\u4e3a\u4e3b\u952e\u7d22\u5f15\uff0c\u6216\u8005\u5185\u90e8\u751f\u6210\u4e00\u4e2a\u9690\u5f0f\u7684\u4e3b\u952e\u5217\uff086 \u5b57\u8282\u5927\u5c0f\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u552f\u4e00\u7d22\u5f15\uff08Unique Index\uff09<\/strong><\/p>\n<ul>\n<li>\u9700\u8981\u624b\u52a8\u521b\u5efa\uff0c\u901a\u8fc7 <code>UNIQUE<\/code> \u5173\u952e\u5b57\u6307\u5b9a\u3002<\/li>\n<li>\u552f\u4e00\u7d22\u5f15\u4fdd\u8bc1\u5217\u4e2d\u7684\u6570\u636e\u662f\u552f\u4e00\u7684\uff0c\u5e76\u80fd\u52a0\u901f\u57fa\u4e8e\u8be5\u5217\u7684\u67e5\u8be2\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u666e\u901a\u7d22\u5f15\uff08Non-Unique Index\uff09<\/strong><\/p>\n<ul>\n<li>\u9700\u8981\u624b\u52a8\u521b\u5efa\uff0c\u901a\u8fc7 <code>INDEX<\/code> \u6216 <code>KEY<\/code> \u5173\u952e\u5b57\u6307\u5b9a\u3002<\/li>\n<li>\u666e\u901a\u7d22\u5f15\u7528\u4e8e\u52a0\u901f\u57fa\u4e8e\u8be5\u5217\u7684\u67e5\u8be2\uff0c\u4f46\u4e0d\u4fdd\u8bc1\u6570\u636e\u7684\u552f\u4e00\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7ec4\u5408\u7d22\u5f15\uff08Composite Index\uff09<\/strong><\/p>\n<ul>\n<li>\u9700\u8981\u624b\u52a8\u521b\u5efa\uff0c\u901a\u8fc7\u5728\u591a\u4e2a\u5217\u4e0a\u521b\u5efa\u4e00\u4e2a\u8054\u5408\u7d22\u5f15\u6765\u52a0\u901f\u6d89\u53ca\u591a\u5217\u7684\u67e5\u8be2\u3002<\/li>\n<li>\u5e38\u7528\u4e8e\u67e5\u8be2\u6761\u4ef6\u6d89\u53ca\u591a\u4e2a\u5217\u65f6\uff0c\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5168\u6587\u7d22\u5f15\uff08Full-Text Index\uff09<\/strong><\/p>\n<ul>\n<li>\u5728\u7279\u5b9a\u7684\u6587\u672c\u5b57\u6bb5\u4e0a\u624b\u52a8\u521b\u5efa\uff0c\u7528\u4e8e\u5168\u6587\u641c\u7d22\u3002<\/li>\n<li>\u5728\u521b\u5efa\u65f6\u4f7f\u7528 <code>FULLTEXT<\/code> \u5173\u952e\u5b57\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u524d\u7f00\u7d22\u5f15\uff08Prefix Index\uff09<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u957f\u5b57\u7b26\u4e32\u5b57\u6bb5\uff0c\u624b\u52a8\u521b\u5efa\u7d22\u5f15\u65f6\u53ef\u4ee5\u6307\u5b9a\u53ea\u4f7f\u7528\u524d\u51e0\u4f4d\u5b57\u7b26\u6765\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li>\u901a\u8fc7\u6307\u5b9a\u524d\u7f00\u957f\u5ea6\u6765\u51cf\u5c11\u7d22\u5f15\u7684\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>2. <strong>\u81ea\u52a8\u521b\u5efa\u7684\u7d22\u5f15<\/strong><\/h3>\n<p>\u8fd9\u4e9b\u7d22\u5f15\u7531\u6570\u636e\u5e93\u5f15\u64ce\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u81ea\u52a8\u521b\u5efa\u3002<\/p>\n<ul>\n<li>\n<p><strong>\u4e3b\u952e\u7d22\u5f15\uff08Primary Key Index\uff09<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u8868\u6ca1\u6709\u663e\u5f0f\u5b9a\u4e49\u4e3b\u952e\uff0cInnoDB \u4f1a\u9009\u62e9\u7b2c\u4e00\u4e2a\u552f\u4e00\u975e\u7a7a\u7684\u7d22\u5f15\u4f5c\u4e3a\u4e3b\u952e\u7d22\u5f15\u3002<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u552f\u4e00\u975e\u7a7a\u7684\u7d22\u5f15\uff0cInnoDB \u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u9690\u5f0f\u4e3b\u952e\uff086 \u5b57\u8282\u5927\u5c0f\u7684 row_id\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5916\u952e\u7d22\u5f15\uff08Foreign Key Index\uff09<\/strong><\/p>\n<ul>\n<li>\u5728\u5b9a\u4e49\u5916\u952e\u7ea6\u675f\u65f6\uff0cInnoDB \u81ea\u52a8\u5728\u5916\u952e\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\uff0c\u4ee5\u786e\u4fdd\u5916\u952e\u7ea6\u675f\u7684\u6709\u6548\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\uff08Adaptive Hash Index, AHI\uff09<\/strong><\/p>\n<ul>\n<li>\u8fd9\u662f InnoDB \u81ea\u52a8\u751f\u6210\u7684\u4e00\u79cd\u7279\u6b8a\u7684\u54c8\u5e0c\u7d22\u5f15\uff0c\u7528\u4e8e\u52a0\u901f\u67d0\u4e9b\u70ed\u70b9\u6570\u636e\u7684\u67e5\u8be2\u3002<\/li>\n<li>AHI \u662f\u52a8\u6001\u521b\u5efa\u548c\u7ba1\u7406\u7684\uff0c\u901a\u5e38\u4e0d\u9700\u8981\u5f00\u53d1\u8005\u7684\u5e72\u9884\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>3. <strong>\u81ea\u52a8\u751f\u6210\u4f46\u53ef\u4ee5\u624b\u52a8\u8c03\u6574\u7684\u7d22\u5f15<\/strong><\/h3>\n<ul>\n<li><strong>\u805a\u7c07\u7d22\u5f15\uff08Clustered Index\uff09<\/strong>\n<ul>\n<li>\u5982\u679c\u624b\u52a8\u5b9a\u4e49\u4e86\u4e3b\u952e\uff0cInnoDB \u4f1a\u81ea\u52a8\u5c06\u5176\u4f5c\u4e3a\u805a\u7c07\u7d22\u5f15\u3002<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u5b9a\u4e49\u4e3b\u952e\uff0cInnoDB \u4f1a\u81ea\u52a8\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u5217\u4f5c\u4e3a\u805a\u7c07\u7d22\u5f15\uff0c\u6216\u8005\u751f\u6210\u4e00\u4e2a\u5185\u90e8\u7684\u805a\u7c07\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u5c0f\u7ed3<\/h3>\n<ul>\n<li><strong>\u9700\u8981\u624b\u52a8\u521b\u5efa\u7684\u7d22\u5f15<\/strong>\uff1a\u5305\u62ec\u552f\u4e00\u7d22\u5f15\u3001\u666e\u901a\u7d22\u5f15\u3001\u7ec4\u5408\u7d22\u5f15\u3001\u5168\u6587\u7d22\u5f15\u3001\u524d\u7f00\u7d22\u5f15\u7b49\uff0c\u4e3b\u8981\u662f\u4e3a\u7279\u5b9a\u67e5\u8be2\u4f18\u5316\u800c\u8bbe\u8ba1\u7684\u3002<\/li>\n<li><strong>\u6570\u636e\u5e93\u5f15\u64ce\u81ea\u52a8\u6dfb\u52a0\u7684\u7d22\u5f15<\/strong>\uff1a\u5305\u62ec\u4e3b\u952e\u7d22\u5f15\uff08\u5728\u672a\u663e\u5f0f\u5b9a\u4e49\u4e3b\u952e\u65f6\uff09\u3001\u5916\u952e\u7d22\u5f15\u3001\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\u7b49\u3002\u8fd9\u4e9b\u7d22\u5f15\u662f\u4e3a\u4e86\u7ef4\u62a4\u6570\u636e\u5b8c\u6574\u6027\u6216\u63d0\u9ad8\u6027\u80fd\uff0c\u6570\u636e\u5e93\u5f15\u64ce\u4f1a\u81ea\u52a8\u751f\u6210\u3002<\/li>\n<\/ul>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u624b\u52a8\u521b\u5efa\u7684\u7d22\u5f15\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u67e5\u8be2\u6a21\u5f0f\u548c\u6027\u80fd\u9700\u6c42\u8fdb\u884c\u8bbe\u8ba1\u548c\u8c03\u6574\uff0c\u800c\u81ea\u52a8\u521b\u5efa\u7684\u7d22\u5f15\u5219\u662f\u6570\u636e\u5e93\u5f15\u64ce\u7684\u9ed8\u8ba4\u884c\u4e3a\uff0c\u901a\u5e38\u4e0d\u9700\u8981\u989d\u5916\u7684\u5e72\u9884\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u975e\u539f\u521b\u3001ChatGPT \u95ee\u7b54\u751f\u6210 \u5728 MySQL \u7684 InnoDB \u5f15\u64ce\u4e2d\uff0c\u7d22\u5f15\u6709\u4e9b\u662f\u9700\u8981\u624b\u52a8\u521b\u5efa\u7684\uff0c\u800c\u6709\u4e9b\u5219&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6509\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[152],"class_list":["post-6509","post","type-post","status-publish","format-standard","hentry","category-123","tag-innodb"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6509"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6509\/revisions"}],"predecessor-version":[{"id":6510,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6509\/revisions\/6510"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}