Home » SQL & PL/SQL » SQL & PL/SQL » Setting LIMIT value while using Bulk Collect (Oracle 11gR2)
Setting LIMIT value while using Bulk Collect [message #648562] Thu, 25 February 2016 09:18 Go to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
I wanted to know if we have any technique by which we can calculate the value which needed to be set for a LIMIT clause of bulk collect operation.
for example below lets say our cursor has 10 Million records..What is the value which we can set for LIMIT clause. Is there any way we can calculate it.

decalre
cursor c_emp is <some select query>

var  <variable> ;

begin
     open c_emp;
       loop
           fetch c_emp bulk collect into var limit 2;
           exit when c_emp%NOTFOUND;
      end loop;
     close c_emp;
  end;
Re: Setting LIMIT value while using Bulk Collect [message #648565 is a reply to message #648562] Thu, 25 February 2016 09:26 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
NEVER do in PL/SQL, that which can be done in plain SQL.

https://www.google.com/webhp?hl=en&tab=ww#hl=en&q=oracle+bulk+collect+limit
Re: Setting LIMIT value while using Bulk Collect [message #648567 is a reply to message #648562] Thu, 25 February 2016 09:37 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

The tests many have done, including me, show that, depending on process memory you can afford, network and work load (including number of concurrent sessions), the optimum is somewhere between 100 and 1000 (this later being the really upper value).
I use and do not exceed 100 which is a good compromise (and is what Oracle also chose to do behind the scene in PL/SQL).

Now you are free to make your own tests and post the results.

[Edit: add Oracle internal PL/SQL value]

[Updated on: Thu, 25 February 2016 09:39]

Report message to a moderator

Re: Setting LIMIT value while using Bulk Collect [message #648571 is a reply to message #648567] Thu, 25 February 2016 10:12 Go to previous messageGo to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
Thanks Michel... I had an idea about memory utlization but wanted wanted to know incase if we have any calculation available.
Re: Setting LIMIT value while using Bulk Collect [message #648572 is a reply to message #648571] Thu, 25 February 2016 10:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

The memory you will use is simple: <value of LIMIT> * <(avg) size of a row>.

Re: Setting LIMIT value while using Bulk Collect [message #648599 is a reply to message #648572] Fri, 26 February 2016 03:13 Go to previous messageGo to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
So will it be ok to say Value of Limit = Memory(PGA) / (avg) size of a row.
Can we assume this as a rough value for Limit.
Re: Setting LIMIT value while using Bulk Collect [message #648601 is a reply to message #648599] Fri, 26 February 2016 03:49 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
That's the maximum you can set it to before you crash the process due to lack of memory.
Considering that memory might be needed for other things as well you shouldn't contemplate setting limit anywhere close to that value.
Plus maximum != best for performance.

I'd stick to Michel's advice above.
Previous Topic: retrieve first changed row
Next Topic: character string buffer too small error in function
Goto Forum:
  


Current Time: Fri Apr 19 15:46:51 CDT 2024