{"id":183148,"date":"2024-11-10T02:24:20","date_gmt":"2024-11-09T18:24:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183148\/"},"modified":"2024-11-10T02:24:21","modified_gmt":"2024-11-09T18:24:21","slug":"%e5%af%a6%e7%8f%besql-server-%e7%b4%a2%e5%bc%95%e5%ba%95%e5%b1%a4%e8%88%87%e6%93%8d%e4%bd%9c%e4%b8%ad%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183148\/","title":{"rendered":"\u5be6\u73feSQL Server \u7d22\u5f15\u5e95\u5c64\u8207\u64cd\u4f5c\u4e2d\u7684\u6ce8\u610f\u4e8b\u9805"},"content":{"rendered":"<h1 id=\"%e5%af%a6%e7%8f%besql-server-%e7%b4%a2%e5%bc%95%e5%ba%95%e5%b1%a4%e8%88%87%e6%93%8d%e4%bd%9c%e4%b8%ad%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-HwhbjRCLYL\">\u5be6\u73feSQL Server \u7d22\u5f15\u5e95\u5c64\u8207\u64cd\u4f5c\u4e2d\u7684\u6ce8\u610f\u4e8b\u9805<\/h1>\n<p>\u5728\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7d22\u5f15\u662f\u4e00\u7a2e\u91cd\u8981\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002\u5c0d\u65bc\u4f7f\u7528SQL Server\u7684\u958b\u767c\u8005\u548c\u8cc7\u6599\u5eab\u7ba1\u7406\u54e1\u4f86\u8aaa\uff0c\u4e86\u89e3\u7d22\u5f15\u7684\u5e95\u5c64\u5be6\u73fe\u53ca\u5176\u64cd\u4f5c\u4e2d\u7684\u6ce8\u610f\u4e8b\u9805\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eSQL Server\u7d22\u5f15\u7684\u5de5\u4f5c\u539f\u7406\u3001\u985e\u578b\u4ee5\u53ca\u5728\u64cd\u4f5c\u904e\u7a0b\u4e2d\u9700\u8981\u6ce8\u610f\u7684\u5e7e\u500b\u95dc\u9375\u9ede\u3002<\/p>\n<h2 id=\"sql-server%e7%b4%a2%e5%bc%95%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-HwhbjRCLYL\">SQL Server\u7d22\u5f15\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u7d22\u5f15\u5728SQL Server\u4e2d\u985e\u4f3c\u65bc\u66f8\u7c4d\u7684\u76ee\u9304\uff0c\u80fd\u5920\u5e6b\u52a9\u8cc7\u6599\u5eab\u5feb\u901f\u5b9a\u4f4d\u5230\u6240\u9700\u7684\u8cc7\u6599\u3002\u7d22\u5f15\u7684\u4e3b\u8981\u76ee\u7684\u662f\u63d0\u9ad8\u67e5\u8a62\u6548\u7387\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u8cc7\u6599\u6642\u3002SQL Server\u652f\u6301\u591a\u7a2e\u7d22\u5f15\u985e\u578b\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u805a\u96c6\u7d22\u5f15\uff08Clustered Index\uff09<\/strong>\uff1a\u8cc7\u6599\u8868\u7684\u8cc7\u6599\u884c\u6309\u7167\u7d22\u5f15\u7684\u9806\u5e8f\u5b58\u5132\uff0c\u901a\u5e38\u6bcf\u500b\u8cc7\u6599\u8868\u53ea\u80fd\u6709\u4e00\u500b\u805a\u96c6\u7d22\u5f15\u3002<\/li>\n<li><strong>\u975e\u805a\u96c6\u7d22\u5f15\uff08Non-Clustered Index\uff09<\/strong>\uff1a\u8cc7\u6599\u884c\u7684\u5b58\u5132\u9806\u5e8f\u4e0d\u53d7\u7d22\u5f15\u5f71\u97ff\uff0c\u7d22\u5f15\u672c\u8eab\u6703\u5b58\u5132\u6307\u5411\u8cc7\u6599\u884c\u7684\u6307\u6a19\u3002<\/li>\n<li><strong>\u552f\u4e00\u7d22\u5f15\uff08Unique Index\uff09<\/strong>\uff1a\u78ba\u4fdd\u7d22\u5f15\u5217\u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u552f\u4e00\u7684\uff0c\u9019\u5c0d\u65bc\u9632\u6b62\u91cd\u8907\u8cc7\u6599\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li><strong>\u5168\u6587\u7d22\u5f15\uff08Full-Text Index\uff09<\/strong>\uff1a\u5c08\u9580\u7528\u65bc\u5c0d\u6587\u672c\u8cc7\u6599\u9032\u884c\u9ad8\u6548\u67e5\u8a62\uff0c\u9069\u5408\u65bc\u9700\u8981\u9032\u884c\u95dc\u9375\u5b57\u641c\u7d22\u7684\u5834\u666f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b4%a2%e5%bc%95%e7%9a%84%e5%ba%95%e5%b1%a4%e5%af%a6%e7%8f%be-HwhbjRCLYL\">\u7d22\u5f15\u7684\u5e95\u5c64\u5be6\u73fe<\/h2>\n<p>\u5728SQL Server\u4e2d\uff0c\u7d22\u5f15\u7684\u5e95\u5c64\u5be6\u73fe\u4e3b\u8981\u4f9d\u8cf4\u65bcB\u6a39\uff08B-Tree\uff09\u7d50\u69cb\u3002\u9019\u7a2e\u7d50\u69cb\u80fd\u5920\u6709\u6548\u5730\u652f\u6301\u5feb\u901f\u67e5\u8a62\u548c\u7bc4\u570d\u67e5\u8a62\u3002\u805a\u96c6\u7d22\u5f15\u7684\u6839\u7bc0\u9ede\u3001\u5167\u90e8\u7bc0\u9ede\u548c\u8449\u5b50\u7bc0\u9ede\u7d44\u6210\u4e86\u6574\u500b\u7d22\u5f15\u7684\u7d50\u69cb\uff0c\u5176\u4e2d\u8449\u5b50\u7bc0\u9ede\u5305\u542b\u4e86\u5be6\u969b\u7684\u8cc7\u6599\u884c\u3002<\/p>\n<p>\u975e\u805a\u96c6\u7d22\u5f15\u5247\u6703\u5728\u7d22\u5f15\u4e2d\u5b58\u5132\u6307\u5411\u8cc7\u6599\u884c\u7684\u6307\u6a19\uff0c\u9019\u6a23\u5728\u67e5\u8a62\u6642\uff0cSQL Server\u53ef\u4ee5\u901a\u904e\u7d22\u5f15\u5feb\u901f\u5b9a\u4f4d\u5230\u8cc7\u6599\u884c\uff0c\u800c\u4e0d\u5fc5\u6383\u63cf\u6574\u500b\u8cc7\u6599\u8868\u3002<\/p>\n<h2 id=\"%e6%93%8d%e4%bd%9c%e4%b8%ad%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-HwhbjRCLYL\">\u64cd\u4f5c\u4e2d\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<h3 id=\"1-%e7%b4%a2%e5%bc%95%e7%9a%84%e9%81%b8%e6%93%87-HwhbjRCLYL\">1. \u7d22\u5f15\u7684\u9078\u64c7<\/h3>\n<p>\u5728\u8a2d\u8a08\u8cc7\u6599\u5eab\u6642\uff0c\u9078\u64c7\u5408\u9069\u7684\u7d22\u5f15\u985e\u578b\u81f3\u95dc\u91cd\u8981\u3002\u958b\u767c\u8005\u61c9\u6839\u64da\u67e5\u8a62\u7684\u7279\u6027\u4f86\u9078\u64c7\u7d22\u5f15\u3002\u4f8b\u5982\uff0c\u5c0d\u65bc\u7d93\u5e38\u9032\u884c\u7bc4\u570d\u67e5\u8a62\u7684\u5217\uff0c\u805a\u96c6\u7d22\u5f15\u53ef\u80fd\u662f\u66f4\u597d\u7684\u9078\u64c7\uff1b\u800c\u5c0d\u65bc\u9700\u8981\u5feb\u901f\u67e5\u627e\u7684\u5217\uff0c\u975e\u805a\u96c6\u7d22\u5f15\u5247\u66f4\u70ba\u5408\u9069\u3002<\/p>\n<h3 id=\"2-%e7%b4%a2%e5%bc%95%e7%9a%84%e7%b6%ad%e8%ad%b7-HwhbjRCLYL\">2. \u7d22\u5f15\u7684\u7dad\u8b77<\/h3>\n<p>\u96a8\u8457\u8cc7\u6599\u7684\u589e\u9577\u548c\u8b8a\u66f4\uff0c\u7d22\u5f15\u53ef\u80fd\u6703\u8b8a\u5f97\u4e0d\u518d\u9ad8\u6548\u3002\u5b9a\u671f\u9032\u884c\u7d22\u5f15\u91cd\u5efa\u548c\u91cd\u7d44\u662f\u5fc5\u8981\u7684\uff0c\u4ee5\u78ba\u4fdd\u7d22\u5f15\u7684\u6027\u80fd\u3002SQL Server\u63d0\u4f9b\u4e86\u591a\u7a2e\u5de5\u5177\u548c\u547d\u4ee4\u4f86\u5e6b\u52a9\u7ba1\u7406\u7d22\u5f15\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>ALTER INDEX ALL ON TableName REBUILD;<\/code><\/pre>\n<h3 id=\"3-%e9%81%bf%e5%85%8d%e9%81%8e%e5%a4%9a%e7%9a%84%e7%b4%a2%e5%bc%95-HwhbjRCLYL\">3. \u907f\u514d\u904e\u591a\u7684\u7d22\u5f15<\/h3>\n<p>\u96d6\u7136\u7d22\u5f15\u80fd\u5920\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\uff0c\u4f46\u904e\u591a\u7684\u7d22\u5f15\u6703\u5c0e\u81f4\u5beb\u5165\u6027\u80fd\u4e0b\u964d\uff0c\u56e0\u70ba\u6bcf\u6b21\u63d2\u5165\u3001\u66f4\u65b0\u6216\u522a\u9664\u64cd\u4f5c\u90fd\u9700\u8981\u66f4\u65b0\u7d22\u5f15\u3002\u56e0\u6b64\uff0c\u61c9\u8a72\u6839\u64da\u5be6\u969b\u9700\u6c42\u4f86\u5e73\u8861\u7d22\u5f15\u7684\u6578\u91cf\u548c\u6027\u80fd\u3002<\/p>\n<h3 id=\"4-%e7%9b%a3%e6%8e%a7%e7%b4%a2%e5%bc%95%e6%80%a7%e8%83%bd-HwhbjRCLYL\">4. \u76e3\u63a7\u7d22\u5f15\u6027\u80fd<\/h3>\n<p>\u4f7f\u7528SQL Server\u7684\u52d5\u614b\u7ba1\u7406\u8996\u5716\uff08DMVs\uff09\u4f86\u76e3\u63a7\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u6cc1\uff0c\u53ef\u4ee5\u5e6b\u52a9\u8b58\u5225\u4e0d\u5e38\u7528\u7684\u7d22\u5f15\uff0c\u5f9e\u800c\u9032\u884c\u512a\u5316\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\u4f86\u67e5\u770b\u7d22\u5f15\u7684\u4f7f\u7528\u983b\u7387\uff1a<\/p>\n<pre><code>SELECT * FROM sys.dm_db_index_usage_stats;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HwhbjRCLYL\">\u7e3d\u7d50<\/h2>\n<p>\u5728SQL Server\u4e2d\uff0c\u7d22\u5f15\u7684\u8a2d\u8a08\u548c\u7ba1\u7406\u5c0d\u65bc\u8cc7\u6599\u5eab\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u4e86\u89e3\u7d22\u5f15\u7684\u5e95\u5c64\u5be6\u73fe\u53ca\u5176\u64cd\u4f5c\u4e2d\u7684\u6ce8\u610f\u4e8b\u9805\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u548c\u8cc7\u6599\u5eab\u7ba1\u7406\u54e1\u66f4\u6709\u6548\u5730\u4f7f\u7528\u7d22\u5f15\uff0c\u5f9e\u800c\u63d0\u9ad8\u67e5\u8a62\u6548\u7387\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u8cc7\u6599\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">VPS<\/a>\u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u4e00\u500b\u91cd\u8981\u7684\u8003\u91cf\uff0c\u7279\u5225\u662f\u5728\u9999\u6e2f\u9019\u6a23\u7684\u5e02\u5834\u4e2d\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u80fd\u5920\u70ba\u696d\u52d9\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3SQL Server\u7d22\u5f15\u7684\u5e95\u5c64\u7d50\u69cb\u53ca\u64cd\u4f5c\u6ce8\u610f\u4e8b\u9805\uff0c\u63d0\u5347\u67e5\u8a62\u6548\u80fd\uff0c\u907f\u514d\u5e38\u898b\u932f\u8aa4\uff0c\u512a\u5316\u6578\u64da\u5eab\u6027\u80fd\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-183148","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183148","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=183148"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183148\/revisions"}],"predecessor-version":[{"id":183149,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183148\/revisions\/183149"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}