简体   繁体   中英

11 Left Outer Join in a query and Oracle error

I have to create a sql query for a new report. The problem is that I have to do 11 Left Outer Join !!! Oh yes this is the bad part. When I execute the query Oracle generate this error :

ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
01652. 00000 -  "unable to extend temp segment by %s in tablespace %s"
*Cause:    Failed to allocate an extent of the required number of blocks for
           a temporary segment in the tablespace indicated.
*Action:   Use ALTER TABLESPACE ADD DATAFILE statement to add one or more
           files to the tablespace indicated.

I am sure that this error is triggered because there are a lot of reocrds to handle. Do you have any advice that could help me please?

Thanks, Walloud

Are the results of the report aggregated in any way? If so, you may be able to break the query down into a number of stages and store the intermediate results rather than doing it a single hit. Without seeing the query itself and having a basic understanding of the domain and requirements it would be difficult to help further.

If it's not to do with aggregation, as ninesided mentions ...

Oracle 9i and below had a problem with outer joins, particularly with hash outer joins, that might be relevant -- until 10g the driving table for table_a = table_b(+) had to be table_a, and this could mean that an efficient hash join where table_a was smaller than table_b could not occur. The alternative often turned out to be a sort-merge, which could require a lot of temp storage.

The cure could be to upgrade from a version for which extended support ended three years ago ;)

Check your temporary tablespace settings. The temporary tablespace required to sort or hash a table is usually about the same as the segment size of that table. Find those numbers with a query like this:

select bytes/1024/1024/1024 GB, dba_segments.*
from dba_segments
where segment_name = '<table_name>';

Then compare it with the available temporary tablespace:

select free_space/1024/1024/1024 GB, dba_temp_free_space.*
from dba_temp_free_space;

If you are sorting or hashing a table larger than your temp space, the easiest solution is probably to add more space.

Also check if other processes are using up a lot of temp tablespace. Assuming an 8K block size:

select blocks * 8 * 1024 /1024/1024 MB, v$sort_usage.*
from gv$sort_usage;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM