Temp Tablespace running out of space (68 GB) [message #531747] |
Thu, 17 November 2011 08:44 |
manubatham20
Messages: 566 Registered: September 2010 Location: Seattle, WA, USA
|
Senior Member |
|
|
Hi,
I am getting temp tablespace error "ORA-01652: unable to extend temp segment by 128 in tablespace TEMP" for the following code.
SELECT /*+ USE_NL ( vd1 ,vd2 ,vd3 ) leading ( vd1 ,vd2 ,vd3 , tvd) */ vd1.vendor_record_seq_no,
tvr.checksum, tvr.rownumber, tvr.transaction_type, 'U'
FROM vendor_data vd1, vendor_data vd2, vendor_data vd3,
(SELECT rownumber, MAX (DECODE (control_column_seq_no, 91150, original_value, NULL)) AS value1,
MAX (DECODE (control_column_seq_no, 91152, original_value, NULL)) AS value2,
MAX (DECODE (control_column_seq_no, 91141, original_value, NULL)) AS value3
FROM (SELECT /*+ dynamic_sampling(vdt 3) dymanic_sampling_est_cdn(vdt) */ rownumber,
VALUE AS original_value,control_column_seq_no
FROM temp_vendor_data vdt
WHERE vdt.KEY = 'Y' AND error_flag IS NULL) temp
GROUP BY rownumber) tvd, temp_vendor_record tvr
WHERE vd1.study_seq_no = 25706 AND vd1.control_column_seq_no = 91150
Right now used tables has the following number of records-
SELECT COUNT(*) FROM vendor_data --292890442
SELECT COUNT(*) FROM temp_vendor_data --0
SELECT COUNT(*) FROM temp_vendor_record --0
This query is part of an application, but consuming too much of temporary tablespace (68 GB allocated). I found it out by using query below:
select * from v$session a, v$sql b
where a.sql_id=b.sql_id
and status = 'ACTIVE'
I am not sure, why this problem is occuring. Please help, what other information I should provide.
Thanks,
Manu.
|
|
|
|
|
|
Re: Temp Tablespace running out of space (68 GB) [message #531763 is a reply to message #531747] |
Thu, 17 November 2011 09:29 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Maybe this: FROM ..., vendor_data vd2, vendor_data vd3 The query contains two references to VENDOR_DATA table without using any column from them in SELECT clause nor join conditions. This leads to cartesian product (CROSS JOIN), so for each output row of the query rest, extra 292890442*292890442 rows. Although, if other tables had zero rows (are you sure it is correct during query run? - data in global temporary tables may not be visible to other sessions), the result set would contain zero rows. Are statistics on all tables current? Are all tables normal heap tables or are some of them global temporary ones?
Also other tables are not joined, so the same multiplication of rows will happen.
Of course, the best workaround would be fixing this query to properly join tables - add correct join conditions and/or remove the unused tables.
|
|
|
Re: Temp Tablespace running out of space (68 GB) [message #532533 is a reply to message #531763] |
Wed, 23 November 2011 04:41 |
|
dee_bee_eh
Messages: 6 Registered: November 2011
|
Junior Member |
|
|
explain plan will give you the estimated temporary space for any query that needs it, ie, the PGA isnt sufficient
then explain plan for <your SQL>
and then select * from table(dbms_xplan.display);
run the plan table utl package for the latest plan table
you should get the following (tempspc is missing if the pga is enough for the query)
Id | Operation | Name | Rows | Bytes |TempSpc| Cost
you should also see the cartesian in the plan.
[Updated on: Wed, 23 November 2011 04:42] Report message to a moderator
|
|
|