{"id":144051,"date":"2024-11-01T03:31:17","date_gmt":"2024-10-31T19:31:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/144051\/"},"modified":"2024-11-01T03:31:18","modified_gmt":"2024-10-31T19:31:18","slug":"sql-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a3%93%e7%b8%ae%e8%aa%9e%e5%8f%a5%e7%b0%a1%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/144051\/","title":{"rendered":"SQL \u6578\u64da\u5eab\u58d3\u7e2e\u8a9e\u53e5\u7c21\u4ecb"},"content":{"rendered":"<h1 id=\"sql-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a3%93%e7%b8%ae%e8%aa%9e%e5%8f%a5%e7%b0%a1%e4%bb%8b-YmeWpjxxKh\">SQL \u6578\u64da\u5eab\u58d3\u7e2e\u8a9e\u53e5\u7c21\u4ecb<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u5b58\u5132\u6548\u7387\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u9577\uff0c\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406\u548c\u5b58\u5132\u9019\u4e9b\u6578\u64da\u6210\u70ba\u4e86\u6bcf\u500b\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u9700\u8981\u9762\u5c0d\u7684\u6311\u6230\u3002SQL \u6578\u64da\u5eab\u58d3\u7e2e\u6280\u8853\u6b63\u662f\u70ba\u4e86\u89e3\u6c7a\u9019\u4e00\u554f\u984c\u800c\u8a95\u751f\u7684\u3002\u672c\u6587\u5c07\u4ecb\u7d39 SQL \u6578\u64da\u5eab\u58d3\u7e2e\u7684\u57fa\u672c\u6982\u5ff5\u3001\u512a\u52e2\u4ee5\u53ca\u5e38\u7528\u7684\u58d3\u7e2e\u8a9e\u53e5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-sql-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a3%93%e7%b8%ae%ef%bc%9f-YmeWpjxxKh\">\u4ec0\u9ebc\u662f SQL \u6578\u64da\u5eab\u58d3\u7e2e\uff1f<\/h2>\n<p>SQL \u6578\u64da\u5eab\u58d3\u7e2e\u662f\u6307\u901a\u904e\u7279\u5b9a\u7684\u7b97\u6cd5\u548c\u6280\u8853\uff0c\u6e1b\u5c11\u6578\u64da\u5728\u6578\u64da\u5eab\u4e2d\u4f54\u7528\u7684\u7a7a\u9593\u3002\u9019\u4e0d\u50c5\u53ef\u4ee5\u7bc0\u7701\u5b58\u5132\u6210\u672c\uff0c\u9084\u80fd\u63d0\u9ad8\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u6548\u7387\u3002\u6578\u64da\u58d3\u7e2e\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u5c64\u9762\u4e0a\u9032\u884c\uff0c\u5305\u62ec\u884c\u58d3\u7e2e\u3001\u5217\u58d3\u7e2e\u548c\u9801\u58d3\u7e2e\u7b49\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%a3%93%e7%b8%ae%e7%9a%84%e5%84%aa%e5%8b%a2-YmeWpjxxKh\">\u6578\u64da\u58d3\u7e2e\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u7bc0\u7701\u5b58\u5132\u7a7a\u9593\uff1a<\/strong>\u58d3\u7e2e\u6578\u64da\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u6578\u64da\u5eab\u6240\u9700\u7684\u5b58\u5132\u7a7a\u9593\uff0c\u5f9e\u800c\u964d\u4f4e\u786c\u9ad4\u6210\u672c\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u6027\u80fd\uff1a<\/strong>\u58d3\u7e2e\u5f8c\u7684\u6578\u64da\u5728\u50b3\u8f38\u904e\u7a0b\u4e2d\u6240\u9700\u7684\u5e36\u5bec\u66f4\u5c11\uff0c\u9019\u53ef\u4ee5\u63d0\u9ad8\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\u3002<\/li>\n<li><strong>\u6e1b\u5c11 I\/O \u64cd\u4f5c\uff1a<\/strong>\u58d3\u7e2e\u6578\u64da\u53ef\u4ee5\u6e1b\u5c11\u78c1\u789f I\/O \u64cd\u4f5c\u7684\u6b21\u6578\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u7cfb\u7d71\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%b8%b8%e7%94%a8%e7%9a%84-sql-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a3%93%e7%b8%ae%e8%aa%9e%e5%8f%a5-YmeWpjxxKh\">\u5e38\u7528\u7684 SQL \u6578\u64da\u5eab\u58d3\u7e2e\u8a9e\u53e5<\/h2>\n<p>\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff08DBMS\uff09\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u58d3\u7e2e\u529f\u80fd\u548c\u8a9e\u53e5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684 SQL \u6578\u64da\u5eab\u58d3\u7e2e\u8a9e\u53e5\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-mysql-%e7%9a%84%e5%a3%93%e7%b8%ae-YmeWpjxxKh\">1. MySQL \u7684\u58d3\u7e2e<\/h3>\n<p>\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>ROW_FORMAT=COMPRESSED<\/code> \u4f86\u5275\u5efa\u58d3\u7e2e\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>CREATE TABLE my_table (\n    id INT PRIMARY KEY,\n    data VARCHAR(255)\n) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;<\/code><\/pre>\n<p>\u9019\u6a23\u5275\u5efa\u7684\u8868\u5c07\u4f7f\u7528 InnoDB \u7684\u884c\u58d3\u7e2e\u529f\u80fd\u3002<\/p>\n<h3 id=\"2-sql-server-%e7%9a%84%e5%a3%93%e7%b8%ae-YmeWpjxxKh\">2. SQL Server \u7684\u58d3\u7e2e<\/h3>\n<p>\u5728 SQL Server \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>ALTER TABLE<\/code> \u8a9e\u53e5\u4f86\u555f\u7528\u884c\u6216\u9801\u58d3\u7e2e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>ALTER TABLE my_table\nREBUILD WITH (DATA_COMPRESSION = PAGE);<\/code><\/pre>\n<p>\u9019\u5c07\u5c0d\u6307\u5b9a\u7684\u8868\u9032\u884c\u9801\u58d3\u7e2e\uff0c\u5f9e\u800c\u6e1b\u5c11\u5b58\u5132\u7a7a\u9593\u7684\u4f7f\u7528\u3002<\/p>\n<h3 id=\"3-postgresql-%e7%9a%84%e5%a3%93%e7%b8%ae-YmeWpjxxKh\">3. PostgreSQL \u7684\u58d3\u7e2e<\/h3>\n<p>PostgreSQL \u81ea\u5e36\u7684 TOAST\uff08The Oversized-Attribute Storage Technique\uff09\u6a5f\u5236\u53ef\u4ee5\u81ea\u52d5\u58d3\u7e2e\u5927\u65bc\u4e00\u5b9a\u5927\u5c0f\u7684\u6578\u64da\u985e\u578b\u3002\u7528\u6236\u7121\u9700\u624b\u52d5\u8a2d\u7f6e\uff0c\u7cfb\u7d71\u6703\u81ea\u52d5\u8655\u7406\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-YmeWpjxxKh\">\u7d50\u8ad6<\/h2>\n<p>SQL \u6578\u64da\u5eab\u58d3\u7e2e\u662f\u4e00\u9805\u91cd\u8981\u7684\u6280\u8853\uff0c\u80fd\u5920\u5e6b\u52a9\u4f01\u696d\u6709\u6548\u7ba1\u7406\u548c\u5b58\u5132\u5927\u91cf\u6578\u64da\u3002\u901a\u904e\u4f7f\u7528\u9069\u7576\u7684\u58d3\u7e2e\u8a9e\u53e5\uff0c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u5b58\u5132\u6548\u7387\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u6301\u7e8c\u589e\u9577\uff0c\u638c\u63e1\u6578\u64da\u58d3\u7e2e\u6280\u8853\u5c07\u6210\u70ba\u6bcf\u4f4d\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u7684\u91cd\u8981\u6280\u80fd\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\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u9700\u6c42\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u548c\u512a\u5316\u60a8\u7684\u6578\u64da\u5eab\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3SQL\u6578\u64da\u5eab\u58d3\u7e2e\u8a9e\u53e5\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u5176\u5728\u6578\u64da\u7ba1\u7406\u4e2d\u7684\u61c9\u7528\uff0c\u63d0\u5347\u5b58\u5132\u6548\u7387\u8207\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-144051","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144051","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=144051"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144051\/revisions"}],"predecessor-version":[{"id":144052,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144051\/revisions\/144052"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=144051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=144051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=144051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}