The docs states that
" Sort_area_size is the memory used to for sort." This is understood
What i don't understand 1005 is the below
"After the sort is complete, but before the rows are returned, Oracle
releases all of the memory allocated for the sort, except the amount
specified by the
SORT_AREA_RETAINED_SIZE parameter. After the last row is returned,
Oracle
releases the remainder of the memory."
Q1. <<After the sort is complete, but before the rows are returned,
Oracle
releases all of the memory allocated for the sort>> I really don't get
this. What happens to the sorted rows? How does it provides the sorted
rows ?
Q2. what does SORT_AREA_RETAINED_SIZE? does it stores some of the
sorted rows or what?
Please clarify?
fitzjarrell@cox.net - 29 Nov 2005 17:59 GMT
> The docs states that
> " Sort_area_size is the memory used to for sort." This is understood
>
> What i don't understand 1005 is the below
What I don't understand is the above sentence.
> "After the sort is complete, but before the rows are returned, Oracle
> releases all of the memory allocated for the sort, except the amount
[quoted text clipped - 8 lines]
> this. What happens to the sorted rows? How does it provides the sorted
> rows ?
You 'don't get this' because you've taken the quote out of context by
removing the text 'except the amount specified by the
SORT_AREA_RETAINED_SIZE parameter.' Not ALL of the sort area is
released; the amount configured in SORT_AREA_RETAINED_SIZE is,
amazingly, retained until the last row is returned. By default
SORT_AREA_SIZE is set to 65536; SORT_AREA_RETAINED_SIZE is equal to at
least 2 database blocks and can be set to as high as the entire value
for SORT_AREA_SIZE.
> Q2. what does SORT_AREA_RETAINED_SIZE? does it stores some of the
> sorted rows or what?
You clearly need to read the Concepts Guide and dig deep into the
manuals at tahiti.oracle.com. SORT_AREA_SIZE is a maximum value for
the allocated sort area for a user session. The sort area is allocated
in units of database blocks, allocated as needed, until reaching
SORT_AREA_SIZE at which time no further allocations are performed.
SORT_AREA_RETAINED_SIZE is just that, the portion of the sort area
retained after a sort is completed but before the rows are returned to
the calling session. Note it is a PORTION of the already allocated
SORT AREA. Grasping that concept should allow the quote from the
manual to make sense.
> Please clarify?
I have, and you REALLY need to read the fine manuals if you want more
information on this topic.
David Fitzjarrell
gazzag - 30 Nov 2005 10:18 GMT
I would guess that the phrase "What i don't understand 1005..." is a
simple typo. With a bit of lateral thinking and being familiar with a
QWERTY keyboard, the OP clearly meant:
"What i don't understand 100%...".
Although I will concede that this post is only slightly more helpful
than yours was, David.
xhoster@gmail.com - 29 Nov 2005 19:16 GMT
> The docs states that
> " Sort_area_size is the memory used to for sort." This is understood
[quoted text clipped - 13 lines]
> this. What happens to the sorted rows? How does it provides the sorted
> rows ?
I agree that SORT_AREA_RETAINED_SIZE is particularly poorly documented.
In the case of a disk sort, SORT_AREA_SIZE is the max size of the memory
scratch space for doing the partial sorts which are written to temp disk.
Once the sort is done and only the final merge is left, you no longer get
much benefit from having a lot of this scratch space. My understanding (or
guess, if you prefer) is that it drops down to SORT_AREA_RETAINED_SIZE for
doing this final merge and buffering.
I don't think Oracle uses an in-place memory sort, so even for a sort which
is done in memory there is going to be no-longer used space once the sort
it done, and that can be freed. I don't know why Oracle would need a
parameter to tell it how much of this space to free, it seems like it would
just free all of it that isn't needed to hold the results. From something
I've seen under 8i, which I no longer recall exactly what it was, I had the
suspicion that, even for in-memory sorts, the part of the result that
exceeds SORT_AREA_RETAINED_SIZE is written to disk for safe keeping so that
the rest of SORT_AREA_SIZE can be freed.
Xho

Signature
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Jonathan Lewis - 29 Nov 2005 22:42 GMT
Assuming workarea_size_policy = manual.
The default setting for sort_area_retained_size
is zero, which means it matches sort_area_size
whatever you do to the sort_area_size.
Assume,. therefore, you have set the
sort_area_retained_size to a non-zero value.
When your session starts a sort, it will acquire
memory a few KB at a time in the UGA, up
to the limit of sort_area_retained_size. If your
sort has not completed in memory at that point,
your session will start to demand memory from
the PGA - up to sort_area_size - sort_area_retained_size.
(so the total demand can reach sort_area_size, but
is split into two parts).
If your sort completes in memory, Oracle dumps the
data to disc, releases the PGA memory allocation,
and retains the UGA memory allocation (although
in recent versions it seems to limit the retention to
1MB) in order to read back and return the rows
to the client process as FETCH calls are made.
If the sort_area_retained_size is left at zero, then
sort_area_retained_size = sort_area_size, which
means that there is no excess to demand in the PGA,
and when the sort completes, it does not dump to
disc.
Things get a little more complicated if the
sort_area_size is too small to hold the entire
data set, but the principle is the same - the
sort_area_retained_size acts as a buffer
between the sorted data on disc, and the
next operation that needs to see that data

Signature
Regards
Jonathan Lewis
http://www.jlcomp.demon.co.uk/faq/ind_faq.html
The Co-operative Oracle Users' FAQ
http://www.jlcomp.demon.co.uk/cbo_book/ind_book.html
Cost Based Oracle: Fundamentals
http://www.jlcomp.demon.co.uk/appearances.html
Public Appearances - schedule updated 4th Nov 2005
> The docs states that
> " Sort_area_size is the memory used to for sort." This is understood
[quoted text clipped - 18 lines]
>
> Please clarify?
Pradeep - 30 Nov 2005 04:35 GMT
Thanks Jonathan, it opened some of the shut windows
But few questions though. Just assume for explanation sake, If my
sort_area_retained_size can store 1000 sorted rows (or do sorting of
1000 rows. I assume both are same). If i do a sort of 2000 rows it will
(as you said) do the sorting with the help of
sort_area_size-sort_area_retained_size. So now the 2000 rows are
sorted. Now oracle releases the sort_area_size-sort_area_retained_size
amount of memory but retains sort_area_retained_size. So UGA might have
1000 sorted rows in it. Now what happens to the rest of the 1000 rows.
Is this what goes to the temp tbs ?
Thanks a lot for your time & energy.
Pradeep
> Assuming workarea_size_policy = manual.
>
[quoted text clipped - 70 lines]
> >
> > Please clarify?
Jonathan Lewis - 30 Nov 2005 08:10 GMT
> Thanks Jonathan, it opened some of the shut windows
> But few questions though. Just assume for explanation sake, If my
[quoted text clipped - 9 lines]
> Thanks a lot for your time & energy.
> Pradeep
Note particularly this bit: "Oracle dumps the data to disc".
This means Oracle dumps the ENTIRE sorted data set,
in the correct order, into your temp tablespace. Then it
starts reading it back in order to return it to the user (or
next execution path operation). When the dump is complete,
the memory in the PGA (the excess of sort_area_size over
sort_area_retained_size) is freed.
In passing:
I suspect that the sort_area_retained_size got its name
because, as part of the UGA it could not be released,
not because it meant anything particularly special for
sorting. (i.e. it's the "retained" bit that is significant,
not the "sort" bit).
>> Assume,. therefore, you have set the
>> sort_area_retained_size to a non-zero value.
[quoted text clipped - 5 lines]
>> 1MB) in order to read back and return the rows
>> to the client process as FETCH calls are made.

Signature
Regards
Jonathan Lewis
http://www.jlcomp.demon.co.uk/faq/ind_faq.html
The Co-operative Oracle Users' FAQ
http://www.jlcomp.demon.co.uk/cbo_book/ind_book.html
Cost Based Oracle: Fundamentals
http://www.jlcomp.demon.co.uk/appearances.html
Public Appearances - schedule updated 4th Nov 2005
Pradeep - 30 Nov 2005 09:06 GMT
Thanks Jonathan. You Rock.
But just need a little bit of clarification. (I hope you don't get
pissed of on me)
1. So sort_area_retained_size is a memory area which is retained, it
has nothing to do with the Sorted rows (sorted rows are in the temp
tablespace) Am i correct ?
2. Now who reads the data from the temp tablespace ? is it server
process ?
3. If i don't have a temp tablespace in my database, then where does it
store the sorted result set?
Thanks & God Bless
Pradeep
> > Thanks Jonathan, it opened some of the shut windows
> > But few questions though. Just assume for explanation sake, If my
[quoted text clipped - 48 lines]
> http://www.jlcomp.demon.co.uk/appearances.html
> Public Appearances - schedule updated 4th Nov 2005
Jonathan Lewis - 30 Nov 2005 09:20 GMT
> Thanks Jonathan. You Rock.
> But just need a little bit of clarification. (I hope you don't get
[quoted text clipped - 3 lines]
> has nothing to do with the Sorted rows (sorted rows are in the temp
> tablespace) Am i correct ?
That's a point that people could easily argue about,
but technically I think it's a valid point. But bear in mind
that if the sort_area_retained_size was large enough the
sort would have completed in the sort_area_retained_size
and the rows will still be there in sorted order. Moreover,
since most people leave the parameter at zero, the
actual value for sort_area_retained_size follows the
current value of sort_area_size, so it might be quite
big and could often be large enough for in-memory
sorts.
> 2. Now who reads the data from the temp tablespace ? is it server
> process ?
Yes (as in your dedicated server, or shared server process).
> 3. If i don't have a temp tablespace in my database, then where does it
> store the sorted result set?
If you haven't declared a temp tablespace, or haven't associated
a user with a temp tablespace then the SYSTEM tablespace is
the default tablespace. 9i (I think) allowed you do define a
'default temporary tablespace' so that any user with no explicitly
named tablespace would go to the default.
> Thanks & God Bless
> Pradeep
Pradeep - 30 Nov 2005 11:05 GMT
Thanks, thanks, thanks a lot Jonathan.
Do you have any plans of coming to India?? If yes, i hope your seminars
are not too expensive.
> > Thanks Jonathan. You Rock.
> > But just need a little bit of clarification. (I hope you don't get
[quoted text clipped - 31 lines]
> > Thanks & God Bless
> > Pradeep