Hint for Materializing a Sub-plan Result
Function
You can materialize a sub-plan result to temporarily store the query record. This hint is used only in the INSERT statement.
When the INSERT INTO ... SELECT statement is used to insert a large amount of data with multiple duplicate rows, the index needs to be compared for multiple times. As a result, the execution takes a long time. This hint is used to materialize the results of subplans and temporarily store query records to reduce the number of index comparisons and shorten the statement execution time.
Syntax
material_subplan
Examples
Create a table and insert data into the table.
create table test_mt_sub(a int, b int) with(storage_type = ustore); create index on test_mt_sub(a); create table test_src_mt_sub(a int, b int); insert into test_src_mt_sub values(generate_series(1,10), generate_series(1,100000));
insert into test_mt_sub select /*+ nestloop(test_src_mt_sub t1)*/ * from test_src_mt_sub where notexists(select 1 from test_mt_sub t1 where t1.a = test_src_mt_sub.a);
QUERY PLAN ----------------------------------------------------------------------- Insert on test_mt_sub -> Nested Loop Anti Join -> Seq Scan on test_src_mt_sub -> Index Only Scan using test_mt_sub_a_idx on test_mt_sub t1 Index Cond: (a = test_src_mt_sub.a) (5 rows)
insert /*+ material_subplan*/ into test_mt_sub select /*+ nestloop(test_src_mt_sub t1)*/ * from test_src_mt_sub where not exists(select 1 from test_mt_sub t1 where t1.a = test_src_mt_sub.a);
QUERY PLAN ----------------------------------------------------------------------------- Insert on test_mt_sub -> Materialize -> Nested Loop Anti Join -> Seq Scan on test_src_mt_sub -> Index Only Scan using test_mt_sub_a_idx on test_mt_sub t1 Index Cond: (a = test_src_mt_sub.a) (6 rows)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot