Skip to Main Content
  • Questions
  • Insert with select subquery hangs for a long time

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question.

Asked: January 12, 2017 - 11:09 am UTC

Last updated: January 13, 2017 - 11:04 am UTC

Version: 11.2.0.1.0

Viewed 1000+ times

You Asked

Oracle database version:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for 64-bit Windows: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

This is the query,

insert /*+ append nologging */ into table_A A
select /*+ use_nl(table_B table_C) */ <some tables> from table_B B
where exists (
select 1 from table_C C
where
B.column1 = C.column1 and
B.column2 = C.column2 and
B.column3 = C.column3 and
B.column4 = C.column4
);


table_A and table_B are temporary tables, which gets dropped once this insert query is executed.
table_A is empty at first.
table_B will have more than 5 lakhs data and
table_C will have millions of data (say more than 7 million rows)

This insert query is in one java task. Sometimes this java task gets hanged while executing this insert query.
At that time if we stop and restart the task, it will work without any hang issue.Thins hang issue occurs randomly.

This select query finds any row from table_B that already exists in table_C. If so then this duplicate data will be loaded into table_A.

This hang issue occurs randomly. Sometimes even if the duplicate record is about 4 or 5 lakh insert works fine.

and Chris said...

To answer questions like this we really need to see a trace file for the "hanging" session. Otherwise we're just guessing!

For instructions on how to trace your session and use TKPROF to turn it into something readable, read:

https://blogs.oracle.com/sql/entry/how_to_create_an_execution#tkprof

Make sure you capture waits when tracing - these could be important. Once you've traced the slow and fast versions of your insert, run tkprof on the files. Post your findings here and we'll see what we can do to help.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Hints

Need more information on hints? Check out the complete hint descriptions