
# 为子计划结果进行物化的Hint
#### 功能描述
为子计划结果进行物化，暂存查询记录。只在insert语句应用。
在使用insert into ... select 语句插入大量数据且有多行重复值时，因索引需多次对比而导致执行时间过长。使用此HINT对子计划的结果进行物化，暂存查询记录，减少索引比较次数，缩短语句执行时间。
#### 语法格式
```
material_subplan
```
#### 示例
建表并插入数据：
```
create table test(a int, b int) with(storage_type = ustore);
create index on test(a);
create table test_src(a int, b int);
insert into test_src values(generate_series(1,10), generate_series(1,100000));
```
正常的insert into...select语句：
```
insert 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
   ->  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)
```
