Home » SQL & PL/SQL » SQL & PL/SQL » Query taking too long to execute and then throws an error. Need to change the SQL query (Oracle 11g, Oracle SQL developer 4)
Query taking too long to execute and then throws an error. Need to change the SQL query [message #632224] Tue, 27 January 2015 14:52 Go to next message
SQL_Dev
Messages: 2
Registered: January 2015
Junior Member
Below is my query:
SELECT C.g_plan_ctr, 
       C.g_department, 
       D.name, 
       A.emplid, 
       A.action, 
       B.deptid, 
       A.deptid, 
       To_char(A.effdt, 'YYYY-MM-DD'), 
       A.effseq, 
       To_char(A.action_dt, 'YYYY-MM-DD'), 
       A.jobcode, 
       E.descr, 
       To_char(A.job_entry_dt, 'YYYY-MM-DD'), 
       B.jobcode, 
       F.descr, 
       To_char(B.job_entry_dt, 'YYYY-MM-DD'), 
       A.empl_status, 
       G.empl_status, 
       To_char(G.action_dt, 'YYYY-MM-DD'), 
       To_char(G.effdt, 'YYYY-MM-DD'), 
       To_char(G.termination_dt, 'YYYY-MM-DD'), 
       To_char(C.effdt, 'YYYY-MM-DD') 
FROM   ps_job A, 
       ps_job B, 
       ps_dept_tbl C, 
       ps_personal_vw D, 
       ps_jobcode_tbl E, 
       ps_jobcode_tbl F, 
       ps_job G 
WHERE  ( A.effdt BETWEEN To_date('2013-01-01', 'YYYY-MM-DD') AND 
                                  To_date('2013-01-31', 'YYYY-MM-DD') 
         AND A.empl_status IN ( 'A', 'L' ) 
         AND A.company NOT IN ( 'PEN', 'GFR' ) 
         AND A.emplid = B.emplid 
         AND A.empl_rcd = B.empl_rcd 
         AND B.effdt = (SELECT Max(B_ED.effdt) 
                        FROM   ps_job B_ED 
                        WHERE  B.emplid = B_ED.emplid 
                               AND B.empl_rcd = B_ED.empl_rcd 
                               AND B_ED.effdt < A.effdt) 
         AND B.effseq = (SELECT Max(B_ES.effseq) 
                         FROM   ps_job B_ES 
                         WHERE  B.emplid = B_ES.emplid 
                                AND B.empl_rcd = B_ES.empl_rcd 
                                AND B.effdt = B_ES.effdt) 
         AND A.deptid <> B.deptid 
         AND C.deptid = A.deptid 
         AND C.effdt = (SELECT Max(C_ED.effdt) 
                        FROM   ps_dept_tbl C_ED 
                        WHERE  C.setid = C_ED.setid 
                               AND C.deptid = C_ED.deptid 
                               AND C_ED.effdt <= SYSDATE) 
         AND A.emplid = D.emplid ) 


This is running forever and below error is thrown:

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 don't have DBA rights to wok through this error message. The only way I can proceed is to improve the query performance.

Any help is highly appreciated. Thank you.
*BlackSwan added {code} tags & formatted the SQL. Please do so yourself in the future.

[Updated on: Tue, 27 January 2015 15:11] by Moderator

Report message to a moderator

Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632225 is a reply to message #632224] Tue, 27 January 2015 15:12 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/


post formatted EXPLAIN PLAN for this query
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632226 is a reply to message #632225] Tue, 27 January 2015 15:44 Go to previous messageGo to next message
SQL_Dev
Messages: 2
Registered: January 2015
Junior Member
I created explain plan and ran the query: select * from plan_table where statement_id = 'test127';
It returned 33 rows. I am not sure what values of what columns I have to provide you. Could you please let me know?
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632227 is a reply to message #632226] Tue, 27 January 2015 16:50 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
Please post the entire results of the following:

SET LINESIZE 130
SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY ('PLAN_TABLE', 'test_127'));

This should provide meaningful output in a readable fashion. However, you may find that even when the query is as well-tuned as possible, you may still need to have your DBA add a datafile to the tablespace.
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632228 is a reply to message #632226] Tue, 27 January 2015 17:21 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
ORAFAQ tuning below -
Since NOBODY can optimize SQL just by looking at it, we need a few more details.
http://www.orafaq.com/forum/mv/msg/84315/433888/#msg_433888
Please refer to URL above & be sure to provide the details requested:
1) DDL for all tables & indexes
2) EXPLAIN PLAN
3) output from SQL_TRACE & tkprof
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632241 is a reply to message #632224] Wed, 28 January 2015 01:24 Go to previous messageGo to next message
John Watson
Messages: 9004
Registered: January 2010
Location: Global Village
Senior Member
It looks to me as though you have forgotten to include any join conditions to E and F and G. So you are crossjoining to those tables, which will be why te query is returning zillions of rows and filling up your temp space.

This is another example of why one should always using ANSI join sytax, where it is impossible to make such mistakes.
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632306 is a reply to message #632241] Wed, 28 January 2015 15:15 Go to previous messageGo to next message
ravikanth_b
Messages: 42
Registered: November 2007
Location: Bay Area, CA
Member
Yes. Cartesian product!
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632312 is a reply to message #632306] Wed, 28 January 2015 17:51 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
ravikanth_b wrote on Wed, 28 January 2015 13:15
Yes. Cartesian product!


I agree
Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632325 is a reply to message #632312] Thu, 29 January 2015 00:59 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Laughing

Re: Query taking too long to execute and then throws an error. Need to change the SQL query [message #632327 is a reply to message #632312] Thu, 29 January 2015 01:33 Go to previous message
John Watson
Messages: 9004
Registered: January 2010
Location: Global Village
Senior Member
BlackSwan wrote on Wed, 28 January 2015 23:51
ravikanth_b wrote on Wed, 28 January 2015 13:15
Yes. Cartesian product!


I agree


Me too.

[Updated on: Thu, 29 January 2015 01:34]

Report message to a moderator

Previous Topic: How to insert with100 Million record's sql query result into another table 1 million by 1 million
Next Topic: need a query for following description
Goto Forum:
  


Current Time: Tue Sep 01 01:58:31 CDT 2026