{"id":60929,"date":"2024-10-13T07:00:14","date_gmt":"2024-10-12T23:00:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/60929\/"},"modified":"2024-10-13T07:00:14","modified_gmt":"2024-10-12T23:00:14","slug":"db2%e7%89%a9%e5%8c%96%e8%a6%96%e5%9c%96%e4%b9%8bmqt%e7%89%a9%e5%8c%96%e6%9f%a5%e8%a9%a2%e8%a1%a8%e6%ad%a3%e7%a2%ba%e6%87%89%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/60929\/","title":{"rendered":"DB2\u7269\u5316\u8996\u5716\u4e4bMQT\u7269\u5316\u67e5\u8a62\u8868\u6b63\u78ba\u61c9\u7528"},"content":{"rendered":"<h1 id=\"db2%e7%89%a9%e5%8c%96%e8%a6%96%e5%9c%96%e4%b9%8bmqt%e7%89%a9%e5%8c%96%e6%9f%a5%e8%a9%a2%e8%a1%a8%e6%ad%a3%e7%a2%ba%e6%87%89%e7%94%a8-bZZxMwoJze\">DB2\u7269\u5316\u8996\u5716\u4e4bMQT\u7269\u5316\u67e5\u8a62\u8868\u6b63\u78ba\u61c9\u7528<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7269\u5316\u8996\u5716\uff08Materialized View\uff09\u662f\u4e00\u7a2e\u91cd\u8981\u7684\u6280\u8853\uff0c\u7279\u5225\u662f\u5728IBM DB2\u4e2d\uff0cMQT\uff08Materialized Query Table\uff09\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9ad8\u6548\u7684\u6578\u64da\u67e5\u8a62\u65b9\u5f0f\u3002\u672c\u6587\u5c07\u63a2\u8a0eDB2\u4e2dMQT\u7684\u6b63\u78ba\u61c9\u7528\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u7406\u89e3\u5176\u529f\u80fd\u53ca\u512a\u52e2\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmqt%ef%bc%9f-bZZxMwoJze\">\u4ec0\u9ebc\u662fMQT\uff1f<\/h2>\n<p>MQT\u662fDB2\u7684\u4e00\u7a2e\u7269\u5316\u8996\u5716\uff0c\u5141\u8a31\u7528\u6236\u5c07\u67e5\u8a62\u7d50\u679c\u5b58\u5132\u5728\u6578\u64da\u5eab\u4e2d\uff0c\u5f9e\u800c\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002\u8207\u50b3\u7d71\u7684\u8996\u5716\u4e0d\u540c\uff0cMQT\u6703\u5c07\u67e5\u8a62\u7d50\u679c\u5be6\u969b\u5b58\u5132\u5728\u78c1\u789f\u4e0a\uff0c\u9019\u6a23\u5728\u5f8c\u7e8c\u7684\u67e5\u8a62\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u5f9e\u9019\u4e9b\u9810\u8a08\u7b97\u7684\u7d50\u679c\u4e2d\u7372\u53d6\u6578\u64da\uff0c\u800c\u4e0d\u5fc5\u6bcf\u6b21\u90fd\u91cd\u65b0\u8a08\u7b97\u3002<\/p>\n<h2 id=\"mqt%e7%9a%84%e5%84%aa%e5%8b%a2-bZZxMwoJze\">MQT\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong>MQT\u80fd\u986f\u8457\u6e1b\u5c11\u67e5\u8a62\u6642\u9593\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u8a08\u7b97\u8ca0\u64d4\uff1a<\/strong>\u901a\u904e\u9810\u8a08\u7b97\u548c\u5b58\u5132\u67e5\u8a62\u7d50\u679c\uff0c\u6e1b\u5c11\u4e86\u6578\u64da\u5eab\u7684\u8a08\u7b97\u8ca0\u64d4\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u5b9a\u7fa9\u4e0d\u540c\u7684MQT\uff0c\u4ee5\u9069\u61c9\u5404\u7a2e\u67e5\u8a62\u5834\u666f\u3002<\/li>\n<\/ul>\n<h2 id=\"mqt%e7%9a%84%e5%89%b5%e5%bb%ba%e8%88%87%e7%ae%a1%e7%90%86-bZZxMwoJze\">MQT\u7684\u5275\u5efa\u8207\u7ba1\u7406<\/h2>\n<p>\u5728DB2\u4e2d\u5275\u5efaMQT\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE TABLE my_mqt AS (\n    SELECT column1, column2, SUM(column3) AS total\n    FROM my_table\n    GROUP BY column1, column2\n) DATA INITIALLY DEFERRED REFRESH IMMEDIATE;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70bamy_mqt\u7684MQT\uff0c\u8a72MQT\u5b58\u5132\u4e86my_table\u4e2dcolumn1\u548ccolumn2\u7684\u7d44\u5408\u53ca\u5176\u5c0d\u61c9\u7684\u7e3d\u548c\u3002\u9019\u88e1\u7684\u201cDATA INITIALLY DEFERRED\u201d\u8868\u793a\u5728\u5275\u5efaMQT\u6642\u4e0d\u7acb\u5373\u586b\u5145\u6578\u64da\uff0c\u800c\u201cREFRESH IMMEDIATE\u201d\u5247\u8868\u793a\u5728\u6578\u64da\u66f4\u65b0\u6642\u7acb\u5373\u5237\u65b0MQT\u3002<\/p>\n<h3 id=\"mqt%e7%9a%84%e5%88%b7%e6%96%b0%e7%ad%96%e7%95%a5-bZZxMwoJze\">MQT\u7684\u5237\u65b0\u7b56\u7565<\/h3>\n<p>MQT\u7684\u5237\u65b0\u7b56\u7565\u662f\u5176\u7ba1\u7406\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u65b9\u9762\u3002DB2\u652f\u6301\u591a\u7a2e\u5237\u65b0\u7b56\u7565\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5373\u6642\u5237\u65b0\uff1a<\/strong>\u6bcf\u7576\u57fa\u8868\u6578\u64da\u767c\u751f\u8b8a\u5316\u6642\uff0cMQT\u6703\u7acb\u5373\u66f4\u65b0\u3002<\/li>\n<li><strong>\u5b9a\u671f\u5237\u65b0\uff1a<\/strong>\u6839\u64da\u9810\u5b9a\u7684\u6642\u9593\u9593\u9694\u81ea\u52d5\u5237\u65b0MQT\u3002<\/li>\n<li><strong>\u624b\u52d5\u5237\u65b0\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u8981\u624b\u52d5\u89f8\u767cMQT\u7684\u5237\u65b0\u3002<\/li>\n<\/ul>\n<h2 id=\"mqt%e7%9a%84%e6%9f%a5%e8%a9%a2%e7%a4%ba%e4%be%8b-bZZxMwoJze\">MQT\u7684\u67e5\u8a62\u793a\u4f8b<\/h2>\n<p>\u4f7f\u7528MQT\u9032\u884c\u67e5\u8a62\u7684\u57fa\u672c\u8a9e\u6cd5\u8207\u666e\u901a\u8868\u76f8\u540c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT * FROM my_mqt WHERE column1 = 'value';<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u5c07\u76f4\u63a5\u5f9eMQT\u4e2d\u7372\u53d6\u6578\u64da\uff0c\u5f9e\u800c\u63d0\u9ad8\u67e5\u8a62\u6548\u7387\u3002<\/p>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-bZZxMwoJze\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u4f7f\u7528MQT\u6642\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\uff1a<\/p>\n<ul>\n<li>\u6839\u64da\u67e5\u8a62\u983b\u7387\u548c\u6578\u64da\u66f4\u65b0\u983b\u7387\u9078\u64c7\u5408\u9069\u7684\u5237\u65b0\u7b56\u7565\u3002<\/li>\n<li>\u5b9a\u671f\u76e3\u63a7MQT\u7684\u6027\u80fd\uff0c\u78ba\u4fdd\u5176\u80fd\u5920\u6709\u6548\u5730\u63d0\u5347\u67e5\u8a62\u6548\u7387\u3002<\/li>\n<li>\u907f\u514d\u904e\u5ea6\u5275\u5efaMQT\uff0c\u4ee5\u514d\u9020\u6210\u6578\u64da\u5eab\u7ba1\u7406\u7684\u8907\u96dc\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-bZZxMwoJze\">\u7d50\u8ad6<\/h2>\n<p>MQT\u4f5c\u70baDB2\u4e2d\u7684\u4e00\u9805\u5f37\u5927\u529f\u80fd\uff0c\u80fd\u5920\u986f\u8457\u63d0\u5347\u67e5\u8a62\u6027\u80fd\u4e26\u6e1b\u5c11\u8a08\u7b97\u8ca0\u64d4\u3002\u901a\u904e\u6b63\u78ba\u7684\u5275\u5efa\u548c\u7ba1\u7406\u7b56\u7565\uff0c\u7528\u6236\u53ef\u4ee5\u5145\u5206\u767c\u63eeMQT\u7684\u512a\u52e2\uff0c\u5f9e\u800c\u5728\u6578\u64da\u8655\u7406\u4e0a\u7372\u5f97\u66f4\u597d\u7684\u6548\u679c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u67e5\u8a62\u7684\u61c9\u7528\u5834\u666f\uff0cMQT\u7121\u7591\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u53ca\u5176\u61c9\u7528\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22DB2\u7269\u5316\u8996\u5716\u53caMQT\u7269\u5316\u67e5\u8a62\u8868\u7684\u6b63\u78ba\u61c9\u7528\uff0c\u63d0\u5347\u67e5\u8a62\u6548\u80fd\u8207\u6578\u64da\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-60929","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60929","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=60929"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60929\/revisions"}],"predecessor-version":[{"id":60930,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60929\/revisions\/60930"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=60929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=60929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=60929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}