Hint for Materializing a Sub-plan Result
Description
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(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 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)
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)
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