Question

I have a complex Oracle view which takes around ~ 2 - 3 seconds to execute.

I'm trying to insert values from the Oracle view into a table.

I'm using JdbcTemplate BatchUpdate() to insert multiple values into the table.

In BatchUpdate(), PreparedStatement is used to set values.

Will using a Oracle view, cause any performance issue?

By using PreparedStatement, SQL statements are precompiled. But in case of VIEW, will the view be executed each time the insert query is fired ?

Was it helpful?

Solution

Views are just SQL-statements. They are not slower or faster than the underlying SQL-query.

However, when using complex views (multi-table joins and aggregation) built on-top of other complex views the optimizer may get confused and tries to outsmart itself, leading to really bad execution plans. The problems tend to be even worse if you don't have constraints, referential integrity in place.

A final note is that if you are merely pulling data out of the database to stuff it back in, you would probably achieve better performance doing the entire operation in the database instead. For an example, let's say you pull "order lines" from the database and then updates the "order header" with an "Order Total Qty". In this case you should probably do something like below instead:

merge
 into order_header h
using (select order_id, sum(order_qty) as order_total_qty
         from order_line
        group by order_id
       ) l
   on (h.order_id = l.order_id)
when matched then
   update
      set h.order_total_qty = l.order_total_qty;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top