{"id":171495,"date":"2024-11-07T03:13:20","date_gmt":"2024-11-06T19:13:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/171495\/"},"modified":"2024-11-07T03:13:20","modified_gmt":"2024-11-06T19:13:20","slug":"%e6%b7%ba%e6%9e%90sql-server%e4%b8%89%e5%a4%a7%e7%ae%97%e6%b3%95%e7%9a%84i-o%e6%88%90%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/171495\/","title":{"rendered":"\u6dfa\u6790SQL Server\u4e09\u5927\u7b97\u6cd5\u7684I\/O\u6210\u672c"},"content":{"rendered":"<h1 id=\"%e6%b7%ba%e6%9e%90sql-server%e4%b8%89%e5%a4%a7%e7%ae%97%e6%b3%95%e7%9a%84i-o%e6%88%90%e6%9c%ac-DPCXVhiMJM\">\u6dfa\u6790SQL Server\u4e09\u5927\u7b97\u6cd5\u7684I\/O\u6210\u672c<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0cI\/O\u6210\u672c\u662f\u5f71\u97ff\u6027\u80fd\u7684\u91cd\u8981\u56e0\u7d20\u4e4b\u4e00\u3002SQL Server\u4f5c\u70ba\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5176\u67e5\u8a62\u512a\u5316\u5668\u4f7f\u7528\u591a\u7a2e\u7b97\u6cd5\u4f86\u6c7a\u5b9a\u6700\u4f73\u7684\u67e5\u8a62\u57f7\u884c\u8a08\u5283\u3002\u672c\u6587\u5c07\u6dfa\u6790SQL Server\u7684\u4e09\u5927\u7b97\u6cd5\u53ca\u5176\u5c0dI\/O\u6210\u672c\u7684\u5f71\u97ff\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u512a\u5316\u6578\u64da\u5eab\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%9f%ba%e6%96%bc%e6%88%90%e6%9c%ac%e7%9a%84%e5%84%aa%e5%8c%96%e7%ae%97%e6%b3%95-DPCXVhiMJM\">\u4e00\u3001\u57fa\u65bc\u6210\u672c\u7684\u512a\u5316\u7b97\u6cd5<\/h2>\n<p>SQL Server\u7684\u67e5\u8a62\u512a\u5316\u5668\u4e3b\u8981\u4f9d\u8cf4\u65bc\u57fa\u65bc\u6210\u672c\u7684\u512a\u5316\u7b97\u6cd5\uff08Cost-Based Optimization, CBO\uff09\u3002\u9019\u7a2e\u7b97\u6cd5\u901a\u904e\u8a55\u4f30\u4e0d\u540c\u57f7\u884c\u8a08\u5283\u7684\u9810\u671f\u6210\u672c\u4f86\u9078\u64c7\u6700\u4f73\u8a08\u5283\u3002\u6210\u672c\u901a\u5e38\u7531\u4ee5\u4e0b\u5e7e\u500b\u56e0\u7d20\u7d44\u6210\uff1a<\/p>\n<ul>\n<li>CPU\u6642\u9593<\/li>\n<li>I\/O\u64cd\u4f5c\u6b21\u6578<\/li>\n<li>\u5167\u5b58\u4f7f\u7528\u91cf<\/li>\n<\/ul>\n<p>\u5728\u9019\u500b\u904e\u7a0b\u4e2d\uff0cI\/O\u6210\u672c\u662f\u6700\u91cd\u8981\u7684\u8003\u91cf\u4e4b\u4e00\u3002\u7576\u67e5\u8a62\u6d89\u53ca\u5927\u91cf\u6578\u64da\u6642\uff0c\u78c1\u789fI\/O\u7684\u958b\u92b7\u6703\u986f\u8457\u5f71\u97ff\u6574\u9ad4\u6027\u80fd\u3002\u512a\u5316\u5668\u6703\u6839\u64da\u7d71\u8a08\u4fe1\u606f\u4f86\u9810\u6e2c\u6bcf\u500b\u64cd\u4f5c\u7684I\/O\u6210\u672c\uff0c\u4e26\u9078\u64c7\u6700\u5c0f\u5316\u9019\u4e9b\u6210\u672c\u7684\u57f7\u884c\u8a08\u5283\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b-DPCXVhiMJM\">\u793a\u4f8b<\/h3>\n<pre><code>SELECT * FROM Orders WHERE OrderDate &gt; '2023-01-01'<\/code><\/pre>\n<p>\u5728\u9019\u500b\u67e5\u8a62\u4e2d\uff0c\u512a\u5316\u5668\u6703\u8003\u616e\u5230Orders\u8868\u7684\u5927\u5c0f\u3001\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u6cc1\u4ee5\u53caOrderDate\u5217\u7684\u5206\u4f48\u60c5\u6cc1\uff0c\u4ee5\u8a08\u7b97I\/O\u6210\u672c\u3002<\/p>\n<h2 id=\"%e4%ba%8c%e3%80%81%e5%9f%ba%e6%96%bc%e8%a6%8f%e5%89%87%e7%9a%84%e5%84%aa%e5%8c%96%e7%ae%97%e6%b3%95-DPCXVhiMJM\">\u4e8c\u3001\u57fa\u65bc\u898f\u5247\u7684\u512a\u5316\u7b97\u6cd5<\/h2>\n<p>\u9664\u4e86\u57fa\u65bc\u6210\u672c\u7684\u512a\u5316\u7b97\u6cd5\uff0cSQL Server\u9084\u4f7f\u7528\u57fa\u65bc\u898f\u5247\u7684\u512a\u5316\u7b97\u6cd5\uff08Rule-Based Optimization, RBO\uff09\u3002\u9019\u7a2e\u7b97\u6cd5\u6839\u64da\u4e00\u7d44\u9810\u5b9a\u7fa9\u7684\u898f\u5247\u4f86\u9078\u64c7\u57f7\u884c\u8a08\u5283\uff0c\u800c\u4e0d\u662f\u8a08\u7b97\u6210\u672c\u3002\u96d6\u7136RBO\u5728\u65e9\u671f\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u5ee3\u6cdb\u4f7f\u7528\uff0c\u4f46\u5728\u73fe\u4ee3SQL Server\u4e2d\u5df2\u7d93\u4e0d\u518d\u662f\u4e3b\u8981\u7684\u512a\u5316\u65b9\u6cd5\u3002<\/p>\n<p>RBO\u7684\u4e3b\u8981\u7f3a\u9ede\u5728\u65bc\u5b83\u7121\u6cd5\u6839\u64da\u5be6\u969b\u6578\u64da\u7684\u7279\u5fb5\u4f86\u8abf\u6574\u57f7\u884c\u8a08\u5283\uff0c\u56e0\u6b64\u5728\u8655\u7406\u8907\u96dc\u67e5\u8a62\u6642\uff0c\u53ef\u80fd\u7121\u6cd5\u9054\u5230\u6700\u4f73\u6027\u80fd\u3002\u5118\u7ba1\u5982\u6b64\uff0c\u4e86\u89e3RBO\u7684\u57fa\u672c\u539f\u7406\u4ecd\u7136\u5c0d\u65bc\u7406\u89e3SQL Server\u7684\u6f14\u8b8a\u904e\u7a0b\u6709\u5e6b\u52a9\u3002<\/p>\n<h2 id=\"%e4%b8%89%e3%80%81%e6%9f%a5%e8%a9%a2%e9%87%8d%e5%af%ab%e7%ae%97%e6%b3%95-DPCXVhiMJM\">\u4e09\u3001\u67e5\u8a62\u91cd\u5beb\u7b97\u6cd5<\/h2>\n<p>\u67e5\u8a62\u91cd\u5beb\u7b97\u6cd5\u662fSQL Server\u4e2d\u53e6\u4e00\u500b\u91cd\u8981\u7684\u512a\u5316\u6280\u8853\u3002\u9019\u7a2e\u7b97\u6cd5\u901a\u904e\u5c0d\u67e5\u8a62\u9032\u884c\u91cd\u5beb\u4f86\u6e1b\u5c11I\/O\u6210\u672c\u3002\u4f8b\u5982\uff0c\u5c07\u67d0\u4e9b\u5b50\u67e5\u8a62\u8f49\u63db\u70baJOIN\u64cd\u4f5c\uff0c\u6216\u662f\u5c07UNION\u64cd\u4f5c\u8f49\u63db\u70baUNION ALL\uff0c\u4ee5\u6e1b\u5c11\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u8655\u7406\u3002<\/p>\n<p>\u67e5\u8a62\u91cd\u5beb\u7684\u76ee\u7684\u662f\u7c21\u5316\u67e5\u8a62\u7d50\u69cb\uff0c\u5f9e\u800c\u63d0\u9ad8\u57f7\u884c\u6548\u7387\u3002\u9019\u7a2e\u65b9\u6cd5\u7279\u5225\u9069\u7528\u65bc\u8907\u96dc\u7684\u67e5\u8a62\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u986f\u8457\u964d\u4f4eI\/O\u64cd\u4f5c\u7684\u6b21\u6578\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b-DPCXVhiMJM\">\u793a\u4f8b<\/h3>\n<pre><code>SELECT * FROM Customers WHERE CustomerID IN (SELECT CustomerID FROM Orders)<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u53ef\u4ee5\u901a\u904e\u91cd\u5beb\u70baJOIN\u64cd\u4f5c\u4f86\u63d0\u9ad8\u6027\u80fd\uff1a<\/p>\n<pre><code>SELECT DISTINCT c.* FROM Customers c JOIN Orders o ON c.CustomerID = o.CustomerID<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-DPCXVhiMJM\">\u7e3d\u7d50<\/h2>\n<p>\u5728SQL Server\u4e2d\uff0cI\/O\u6210\u672c\u662f\u5f71\u97ff\u67e5\u8a62\u6027\u80fd\u7684\u95dc\u9375\u56e0\u7d20\u3002\u901a\u904e\u57fa\u65bc\u6210\u672c\u7684\u512a\u5316\u7b97\u6cd5\u3001\u57fa\u65bc\u898f\u5247\u7684\u512a\u5316\u7b97\u6cd5\u4ee5\u53ca\u67e5\u8a62\u91cd\u5beb\u7b97\u6cd5\uff0cSQL Server\u80fd\u5920\u6709\u6548\u5730\u9078\u64c7\u6700\u4f73\u7684\u57f7\u884c\u8a08\u5283\uff0c\u5f9e\u800c\u6700\u5c0f\u5316I\/O\u64cd\u4f5c\u7684\u958b\u92b7\u3002\u4e86\u89e3\u9019\u4e9b\u7b97\u6cd5\u7684\u904b\u4f5c\u539f\u7406\uff0c\u5c0d\u65bc\u6578\u64da\u5eab\u7ba1\u7406\u548c\u6027\u80fd\u512a\u5316\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u512a\u5316\u6578\u64da\u5eab\u6027\u80fd\uff0c\u63d0\u5347\u696d\u52d9\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6dfa\u6790SQL Server\u4e09\u5927\u7b97\u6cd5\u7684I\/O\u6210\u672c\uff0c\u63a2\u8a0e\u5176\u6027\u80fd\u5f71\u97ff\u53ca\u512a\u5316\u7b56\u7565\uff0c\u52a9\u529b\u6578\u64da\u5eab\u7ba1\u7406\u8207\u67e5\u8a62\u6548\u7387\u63d0\u5347\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-171495","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171495","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=171495"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171495\/revisions"}],"predecessor-version":[{"id":171496,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171495\/revisions\/171496"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=171495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=171495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=171495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}