We are trying insert records from a select query in to temporary table, some of the records is missing in the temporary table. The select statement is having multiple joins and union all which it little complex query. In simple terms the script contains 2 part 1st Part Insert in to temporary table 2nd part Select query with multiple joins, inline sub queries, unions and group by classes and conditions
Eg. If we execute select statement alone it returns some count for example => 60000 After inserting into the temp table, in temp table the count is around 42000 why is the difference?
It is simple bulk inserts... insert in to temp table select from xxx. also, there is no commit in between. The problem is all the records populated by the select statement are not inserted in to temp table. some records are not inserted.*
Also, we had some other observation. It only happens in its 2nd execution and not its first run. Hope there might be some cache problem
Even, we also did not believe that. We are wondering. In TOAD, we tested however at times it happens. In application jar file, after "insert in to temp select * from xxx" we take the i. record count of temp table and ii. record count of "select * from xxx" separately but both doesn't match. Match only at 1st time.
We got a solution, once we clear session cache (checkpoint, flush shared_pool and buffer_cache) it works fine for Re_Run.
However, we do not is this solution ok? and how clearing cache works in the background and failed insert. If it is true, something wrong configuration setup, i guess.
The code looks like
sql = "insert in to temptable select x,y,z,.... from xxx,abc,pqr..where...."; (logial but not real is very complex around 700 lines with multiple joins, inline sub queries, group by etc. )
stmt = conn.createStatement();
Actual issue is
rCount = xxxx = Count(temptable) < count(select x,y,z,.... from xxx,abc,pqr..where....)
why this diffference ? some records populated in the select but not inserted in to temp table