Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Manoj Kumar.

Asked: June 03, 2019 - 3:03 pm UTC

Last updated: June 11, 2019 - 5:49 am UTC

Version: 11.2

Viewed 1000+ times

You Asked

Hi,

We have set of Mainframe programs which connects to Oracle database and queries set of tables. Our application and DB servers are in 2 different locations (which we cannot change at the moment), which i believe is causing considerable delays when application executes query(select/update/delete/Insert) in a loop. We have verified the queries in Oracle and it seems pretty good (Basic select by querying primary key column)

We have used ANSI Dynamic approach for bulk processing Insert/Update/Delete and we see significant improvement in performance. Also, we are using Prefetch option while selecting bulk data, which is also helping us to improve performance.

Do we have a similar method using which can improve performance of SELECT queries in loop.? Or Could you please suggest what is the best way to improve the performance.

Note : Currently querying 17K records (Looping through 17K primary key values), takes around 20mts to complete. We have verified queries from Oracle end they run within few milli seconds in Oracle.

oracle version : 11gR2

Please let me know if you need more information

Thanks for your help


and Connor said...

I'm interpreting this as you cannot retrieve the 17k records in "bulk", ie, you have to have issue 17,000 queries.

If that is the case, then all I can suggest is pseudo-batching with PLSQL.

So you would call a PLSQL routine which does (say) 100 individual calls, and returns them as out parameters, ie

select x from t where id = 1;
select y from t1 where pk = 10;
select z from t2 where col = 99;
...
...


becomes

procedure P(p_id int, p_pk int, p_col int, 
            out_id date, out_y int, out_z varchar2) is
begin
select x into out_x from t where id = p_id;
select y into out_y from t1 where pk = p_pk;
select z into out_z from t2 where col = p_col;
...
...
end;


which can then reduce the number of round trips

Rating

  (1 rating)

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

Comments

May be I should give an example

Manoj, June 05, 2019 - 3:13 pm UTC

Our programs has an input file and based on the data in input file, it selects data from a table. Select query program runs is same and only change is the key used in where clause.

select col1, col2, col3 from tableName where keycol = :b1

And program populates bind variable based on the data from input file.

Also, key value can be different during each execution of program and that depends on the input file data. So i am not sure if i can use the method that you have suggested.

Does Oracle 11g provide any other solution for reducing the roundtrip?

Thanks for your help.
Connor McDonald
June 11, 2019 - 5:49 am UTC

Our programs has an input file and based on the data in input file, it selects data from a table. Select query program runs is same and only change is the key used in where clause.

select col1, col2, col3 from tableName where keycol = :b1


In that case, why not reference the input as an external table, and then the operation would be:

select col1, col2, col3 from tableName where keycol in 
 ( select val from my_external_table );


and you would collect all the data in one query pass

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library