{"id":41,"date":"2025-08-23T15:20:52","date_gmt":"2025-08-23T07:20:52","guid":{"rendered":"https:\/\/www.shoubashou.com\/?p=41"},"modified":"2025-08-23T15:20:52","modified_gmt":"2025-08-23T07:20:52","slug":"oceanbase-sql-%e6%99%9a%e6%9c%9f%e7%89%a9%e5%8c%96-%e6%89%a7%e8%a1%8c%e8%ae%a1%e5%88%92","status":"publish","type":"post","link":"https:\/\/www.shoubashou.com\/?p=41","title":{"rendered":"oceanbase SQL \u665a\u671f\u7269\u5316 \u6267\u884c\u8ba1\u5212"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4ec0\u4e48\u662f\u665a\u671f\u7269\u5316<\/h1>\n\n\n\n<p><strong>\u665a\u671f\u7269\u5316\uff08Late Materialization\uff09<\/strong>&nbsp;\u662f OceanBase \u6570\u636e\u5e93\u4e2d\u7684\u4e00\u79cd\u67e5\u8be2\u6267\u884c\u4f18\u5316\u6280\u672f\uff0c\u4e3b\u8981\u7528\u4e8e\u5305\u542b&nbsp;<code>ORDER BY<\/code>&nbsp;\u548c&nbsp;<code>LIMIT<\/code>&nbsp;\u7684\u67e5\u8be2\u573a\u666f\uff0c\u7279\u522b\u662f\u5728\u6d89\u53ca\u5927\u5bbd\u8868\u6216\u5305\u542b LOB \u7b49\u5927\u578b\u6570\u636e\u7c7b\u578b\u5b57\u6bb5\u7684\u8868\u65f6\uff0c\u80fd\u591f\u663e\u8457\u51cf\u5c11\u6570\u636e\u626b\u63cf\u91cf\u548c I\/O \u5f00\u9500\uff0c\u63d0\u5347\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6838\u5fc3\u539f\u7406<\/h2>\n\n\n\n<p>\u665a\u671f\u7269\u5316\u7684\u6838\u5fc3\u601d\u60f3\u662f\uff1a<strong>\u5ef6\u8fdf\u56de\u8868\uff08Delayed Lookup\uff09<\/strong>\uff0c\u5373\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u5148\u901a\u8fc7\u7d22\u5f15\u5b8c\u6210\u6570\u636e\u7684\u8fc7\u6ee4\u548c\u6392\u5e8f\u64cd\u4f5c\uff0c\u4ec5\u4fdd\u7559\u6700\u7ec8\u9700\u8981\u8fd4\u56de\u7684\u5c11\u91cf\u884c\uff08\u7531&nbsp;<code>LIMIT<\/code>&nbsp;\u51b3\u5b9a\uff09\uff0c\u518d\u6839\u636e\u8fd9\u4e9b\u884c\u7684\u4e3b\u952e\u53bb\u4e3b\u8868\u4e2d\u83b7\u53d6\u5b8c\u6574\u7684\u5217\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u8fd9\u907f\u514d\u4e86\u5728\u65e9\u671f\u9636\u6bb5\u5c31\u8fdb\u884c\u5168\u5217\u56de\u8868\uff0c\u4ece\u800c\u5927\u5e45\u51cf\u5c11\u4e86\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u8bfb\u53d6\u548c\u5904\u7406\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6267\u884c\u6d41\u7a0b\u5bf9\u6bd4<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u2705 \u542f\u7528\u665a\u671f\u7269\u5316\uff08\u63a8\u8350\uff09<\/h4>\n\n\n\n<p>\u4ee5\u5982\u4e0b\u67e5\u8be2\u4e3a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT <em>\/*+index(t idx) *\/<\/em> * FROM t1 t WHERE c1 &gt; 0 ORDER BY c2 LIMIT 10;\n<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u8ba1\u5212\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>|ID|OPERATOR        |NAME    |EST. ROWS|COST |\n|0 |NESTED-LOOP JOIN|        |10       |14855|\n|1 | TOP-N SORT     |        |10       |14842|\n|2 |  TABLE SCAN    |t(idx)  |93114    |11972|\n|3 | TABLE GET      |t1_alias|1        |2    |\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b65\u9aa4 2<\/strong>\uff1a\u4ec5\u626b\u63cf\u7d22\u5f15\u00a0<code>idx(c1, c2, c3)<\/code>\uff0c\u83b7\u53d6\u6ee1\u8db3\u00a0<code>c1 > 0<\/code>\u00a0\u7684\u4e3b\u952e\u00a0<code>pk<\/code>\u00a0\u548c\u6392\u5e8f\u5217\u00a0<code>c2<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u6b65\u9aa4 1<\/strong>\uff1a\u5bf9\u4e3b\u952e\u6309\u00a0<code>c2<\/code>\u00a0\u6392\u5e8f\uff0c\u5e76\u4fdd\u7559\u524d 10 \u6761\u3002<\/li>\n\n\n\n<li><strong>\u6b65\u9aa4 3<\/strong>\uff1a\u901a\u8fc7\u4e3b\u952e\u9010\u884c\u56de\u8868\uff08<code>TABLE GET<\/code>\uff09\u83b7\u53d6\u5b8c\u6574\u5217\uff08\u5982\u00a0<code>c3<\/code>,\u00a0<code>c4<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u70b9<\/strong>\uff1a\u53ea\u56de\u8868 10 \u6b21\uff0c\u6781\u5927\u51cf\u5c11 I\/O\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u274c \u7981\u7528\u665a\u671f\u7269\u5316<\/h4>\n\n\n\n<p>\u4f7f\u7528 Hint \u7981\u7528\u8be5\u4f18\u5316\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT <em>\/*+index(t idx) no_use_late_materialization*\/<\/em> * FROM t1 t WHERE c1 &gt; 0 ORDER BY c2 LIMIT 10;\n<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u8ba1\u5212\u53d8\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>|ID|OPERATOR   |NAME  |EST. ROWS|COST  |\n|0 |TOP-N SORT |      |10       |265257|\n|1 | TABLE SCAN|t(idx)|93114    |262387|\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b65\u9aa4 1<\/strong>\uff1a\u6bcf\u6b21\u901a\u8fc7\u7d22\u5f15\u627e\u5230\u8bb0\u5f55\u540e\uff0c\u7acb\u5373\u56de\u8868\u83b7\u53d6\u6240\u6709\u5217\uff08<code>*<\/code>\uff09\uff0c\u5bfc\u81f4\u9700\u56de\u8868 93114 \u6b21\u3002<\/li>\n\n\n\n<li><strong>\u7f3a\u70b9<\/strong>\uff1a\u5927\u91cf\u5197\u4f59\u6570\u636e\u88ab\u8bfb\u53d6\u548c\u6392\u5e8f\uff0c\u8d44\u6e90\u6d88\u8017\u6781\u9ad8\uff08COST \u63d0\u5347\u8fd1 18 \u500d\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u9002\u7528\u573a\u666f<\/h2>\n\n\n\n<p>\u665a\u671f\u7269\u5316\u7279\u522b\u9002\u7528\u4e8e\u4ee5\u4e0b\u60c5\u51b5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u8be2\u5305\u542b\u00a0<code>ORDER BY + LIMIT<\/code>\u3002<\/li>\n\n\n\n<li>\u8868\u4e3a\u5927\u5bbd\u8868\u6216\u5305\u542b LOB\u3001TEXT \u7b49\u5927\u5b57\u6bb5\u3002<\/li>\n\n\n\n<li>\u8fc7\u6ee4\u6761\u4ef6\u548c\u6392\u5e8f\u5217\u53ef\u88ab\u590d\u5408\u7d22\u5f15\u8986\u76d6\u3002<\/li>\n\n\n\n<li>\u53ea\u9700\u8fd4\u56de\u5c11\u91cf\u7ed3\u679c\uff08\u5982\u5206\u9875\u67e5\u8be2\u7684\u524d\u51e0\u9875\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u63a7\u5236\u65b9\u5f0f<\/h2>\n\n\n\n<p>OceanBase \u4f18\u5316\u5668\u4f1a\u81ea\u52a8\u5224\u65ad\u662f\u5426\u542f\u7528\u665a\u671f\u7269\u5316\u3002\u5982\u9700\u7981\u7528\uff0c\u53ef\u901a\u8fc7 Hint \u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/*+ no_use_late_materialization *\/<\/em>\n<\/code><\/pre>\n\n\n\n<p>\u53cd\u4e4b\uff0c\u82e5\u5e0c\u671b\u5f3a\u5236\u542f\u7528\uff08\u901a\u5e38\u65e0\u9700\u6307\u5b9a\uff09\uff0c\u4f18\u5316\u5668\u9ed8\u8ba4\u4f1a\u5728\u5408\u9002\u573a\u666f\u4e0b\u81ea\u52a8\u5e94\u7528\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<p>\u665a\u671f\u7269\u5316\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u6267\u884c\u7b56\u7565\uff0c\u901a\u8fc7\u201c\u5148\u8fc7\u6ee4\u6392\u5e8f\u3001\u540e\u56de\u8868\u53d6\u6570\u201d\u7684\u65b9\u5f0f\uff0c\u663e\u8457\u964d\u4f4e\u4e86\u9ad8\u9009\u62e9\u6027\u67e5\u8be2\u4e2d\u7684\u6570\u636e\u5904\u7406\u91cf\u3002\u5b83\u662f OceanBase \u67e5\u8be2\u4f18\u5316\u5668\u5728\u5904\u7406\u5206\u9875\u67e5\u8be2\u3001\u6392\u884c\u699c\u7c7b\u573a\u666f\u65f6\u7684\u91cd\u8981\u4f18\u5316\u624b\u6bb5\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p>\u66f4\u591a\u7ec6\u8282\u53ef\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/www.oceanbase.com\/docs\/common-oceanbase-database-cn-1000000002016124\" target=\"_blank\" rel=\"noreferrer noopener\">\u6392\u5e8f limit \u573a\u666f\u6027\u80fd\u4f18\u5316 &#8211; \u51cf\u5c11\u626b\u63cf\/\u8ba1\u7b97\u5f00\u9500<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u665a\u671f\u7269\u5316 \u665a\u671f\u7269\u5316\uff08Late Materialization\uff09&nbsp;\u662f OceanBase \u6570\u636e\u5e93 &hellip; <a href=\"https:\/\/www.shoubashou.com\/?p=41\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">oceanbase SQL \u665a\u671f\u7269\u5316 \u6267\u884c\u8ba1\u5212<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-oceanbase"],"_links":{"self":[{"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41"}],"version-history":[{"count":1,"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shoubashou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}