We recently switched over to the dbms_stats package and the gather_schema_stats procedure to collect statistics. We have one database that once in a while completely exhausts the TEMPORARY space. Is there some kind of formula that we could use to predict how much TEMP space the package is going to require for it to complete?

    Requires Free Membership to View

Well, you can estimate it by this ROUGH formula:

Expected_rows_returned * total_size_of_columns in ORDER BY clause

Changing pga_aggregate_target will simply make more or less space available for disk sorts and hash joins. Staring with Oracle9i we see several exciting new execution plan columns and you can run specialized queries to see estimates of resource usage associated with specific steps of Oracle SQL execution, for example:

  • CPU_COST: The CPU cost of the operation as estimated by the optimizer's cost based approach. For statements that use the rule based approach, this column is null. The value of this column is proportional to the number of machine cycles required for the operation.
  • IO_COST: The I/O cost of the operation as estimated by the optimizer's cost based approach. For statements that use the rule based approach, this column is null. The value of this column is proportional to the number of data blocks read by the operation.
  • TEMP_SPACE: The temporary space, in bytes, used by the operation as estimated by the optimizer's cost based approach. For statements that use the rule based approach, or for operations that don't use any temporary space, this column is null.

Oracle claims to use this information to make more intelligent choices of execution plans, but there is a serious problem with this approach.

  1. The CBO has no a priori knowledge of the data buffer contents. Because of this shortcoming, the CBO cannot know if the data blocks are already in the RAM data buffers.
  2. CPU costs depend upon system load. The CPU costs associated with servicing an Oracle query depend upon the server load, and CPU costs are generally not important unless the entire Oracle instance is using excessive CPU resources.
  3. Temporary segment space is transient. Even though the CBO estimates the TEMP_SPACE costs at optimization time, this execution plan will become permanent for the SQL query until the executable is flushed from the library cache. Hence, obsolete execution plans may be used to execute a query.

Oracle also has two new views to show active work area space: the v$sql_workarea and the v$sql_workarea_active views. The v$sql_workarea_active view will display all of the work areas that are currently executing in the instance. Note that small sorts (under 65,535 bytes) are excluded from the view. The v$sql_workarea_active view can be used to quickly monitor the size of all large active work areas.

Here is workarea.sql:

******************************************************************

Copyright © 2004 by Rampant TechPress Inc.

Free for non-commercial use! To license, e-mail info@rampant.cc

******************************************************************
select

to_number(decode(SID, 65535, NULL, SID)) sid,

operation_type OPERATION,

trunc(WORK_AREA_SIZE/1024) WSIZE, 

trunc(EXPECTED_SIZE/1024) ESIZE,

trunc(ACTUAL_MEM_USED/1024) MEM, 

trunc(MAX_MEM_USED/1024) "MAX MEM", 

number_passes PASS

from

v$sql_workarea_active

order by

1,2;

Here is a sample listing from this script:

SID OPERATION WSIZE ESIZE MEM MAX MEM PASS

--- --------------------- ----- --------- --------- --------- ----

27 GROUP BY (SORT) 73 73 64 64 0

44 HASH-JOIN 3148 3147 2437 6342 1

71 HASH-JOIN 13241 19200 12884 34684 1

This was first published in October 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: