更新时间:2023-10-23 GMT+08:00

为子计划结果进行物化的Hint

功能描述

为子计划结果进行物化,暂存查询记录。只在insert语句应用。

语法格式

material_subplan

示例

正常的insert into...select语句:
insert into test select /*+ nestloop(test_src t1)*/ * from test_src where notexists(select 1 from test t1 where t1.a = test_src.a);
执行计划:
                       QUERY PLAN                        
---------------------------------------------------------
 Insert on test
   ->  Nested Loop Anti Join
         ->  Seq Scan on test_src
         ->  Index Only Scan using test_a_idx on test t1
               Index Cond: (a = test_src.a)
(5 rows)
使用material_subplan hint 算子:
insert /*+ material_subplan*/ into test select /*+ nestloop(test_src t1)*/ * from test_src where not exists(select 1 from test t1 where t1.a = test_src.a);
执行计划为:
                          QUERY PLAN                           
---------------------------------------------------------------
 Insert on test
   ->  Materialize
         ->  Nested Loop Anti Join
               ->  Seq Scan on test_src
               ->  Index Only Scan using test_a_idx on test t1
                     Index Cond: (a = test_src.a)
(6 rows)