Home » RDBMS Server » Performance Tuning » Need performance tuning in delete statement (Oracle 10g, windows)
icon5.gif  Need performance tuning in delete statement [message #478773] Tue, 12 October 2010 08:22 Go to next message
burasami
Messages: 20
Registered: April 2010
Junior Member
Hi All,

I need to performance tune SQL statement as follows
DELETE FROM GL_ACCOUNT WHERE GL_ACCT_ID IN (SELECT GL.GL_ACCT_ID FROM GL_ACCOUNT GL WHERE GL.BU_ID !=609);


the above Statement taking long time to delete record.

for test purpose i try to delete 3 row its take much time to delete 3 records

here by i have attached TKPROF file. Please help me to fine the sql query. since for past 3 days trying to fine tune but i can't able to solve this issue.

Thanks & Regards
Sami

  • Attachment: delete1.sql
    (Size: 35.90KB, Downloaded 1431 times)
Re: Need performance tuning in delete statement [message #478775 is a reply to message #478773] Tue, 12 October 2010 08:43 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>TABLE ACCESS FULL GL_ACCOUNT_QUARTERLY_STAT (cr=109500 pr=108398 pw=0 time=20797279 us)
>GL.BU_ID

is column above indexed?
Re: Need performance tuning in delete statement [message #478776 is a reply to message #478775] Tue, 12 October 2010 09:02 Go to previous messageGo to next message
burasami
Messages: 20
Registered: April 2010
Junior Member
Hi BlackSwan,

Thanks for your quick reply.

Yes. BU_ID is indexed in GL_ACCOUNT TABLE and rebuild.

Thanks & Regards
Sami
Re: Need performance tuning in delete statement [message #478781 is a reply to message #478776] Tue, 12 October 2010 09:10 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SELECT COUNT(*) FROM GL_ACCOUNT;
SELECT COUNT(*) FROM GL_ACCOUNT GL WHERE GL.BU_ID !=609;

post results from both SQL above

Re: Need performance tuning in delete statement [message #478782 is a reply to message #478781] Tue, 12 October 2010 09:19 Go to previous messageGo to next message
burasami
Messages: 20
Registered: April 2010
Junior Member
Hi BlackSwan,

Here is output:

SELECT COUNT(*) FROM GL_ACCOUNT;

  COUNT(*)
----------
      7098

1 row selected.

SELECT COUNT(*) FROM GL_ACCOUNT GL WHERE GL.BU_ID !=609;

  COUNT(*)
----------
      6552

1 row selected.


Thanks & Regards
Sami.



Re: Need performance tuning in delete statement [message #478783 is a reply to message #478782] Tue, 12 October 2010 09:23 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
> GL.BU_ID
Since GL.BU_ID != 609 returns most all the rows a FTS is best choice.
if GL.BU_ID can be NULL, then FTS is REQUIRED.
If HWM is "excessive", then some benefit may be obtained by rebuilding table itself.
Re: Need performance tuning in delete statement [message #478784 is a reply to message #478783] Tue, 12 October 2010 09:36 Go to previous messageGo to next message
burasami
Messages: 20
Registered: April 2010
Junior Member
Hi Blackswan,

GL.BU_ID is not null column.
Please elaborate me.
 what is "HWM is "excessive"


then some benefit may be obtained by rebuilding table itself.


if I rebuild the table then data wouldn't be get affected?

Thanks & Regards
Sami.

Re: Need performance tuning in delete statement [message #478785 is a reply to message #478784] Tue, 12 October 2010 09:47 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
create or replace
  procedure show_space
  ( p_segname in varchar2,
    p_owner   in varchar2 default user,
    p_type    in varchar2 default 'TABLE' )
  as
      l_free_blks                 number;
  
      l_total_blocks              number;
      l_total_bytes               number;
      l_unused_blocks             number;
      l_unused_bytes              number;
      l_LastUsedExtFileId         number;
      l_LastUsedExtBlockId        number;
      l_LAST_USED_BLOCK           number;
      procedure p( p_label in varchar2, p_num in number )
      is
      begin
          dbms_output.put_line( rpad(p_label,40,'.') ||
                                p_num );
      end;
  begin
      dbms_space.free_blocks
      ( segment_owner     => p_owner,
        segment_name      => p_segname,
        segment_type      => p_type,
        freelist_group_id => 0,
        free_blks         => l_free_blks );
  
      dbms_space.unused_space
      ( segment_owner     => p_owner,
        segment_name      => p_segname,
        segment_type      => p_type,
        total_blocks      => l_total_blocks,
        total_bytes       => l_total_bytes,
        unused_blocks     => l_unused_blocks,
        unused_bytes      => l_unused_bytes,
        LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
        LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
        LAST_USED_BLOCK => l_LAST_USED_BLOCK );
  
      p( 'Free Blocks', l_free_blks );
      p( 'Total Blocks', l_total_blocks );
      p( 'Total Bytes', l_total_bytes );
      p( 'Unused Blocks', l_unused_blocks );
      p( 'Unused Bytes', l_unused_bytes );
      p( 'Last Used Ext FileId', l_LastUsedExtFileId );
      p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
      p( 'Last Used Block', l_LAST_USED_BLOCK );
  end;
/


CREATE procedure above then do below & post FORMATTED results

SQL> EXEC SHOW_SPACE('GL_ACCOUNT');
Re: Need performance tuning in delete statement [message #478787 is a reply to message #478785] Tue, 12 October 2010 10:01 Go to previous messageGo to next message
burasami
Messages: 20
Registered: April 2010
Junior Member
Hi

While i am trying to run the procedure its giving following error.

ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_SPACE", line 152
ORA-06512: at "SYS.SHOW_SPACE", line 22
ORA-06512: at line 1

Thanks & Regards
Sami
Re: Need performance tuning in delete statement [message #478791 is a reply to message #478787] Tue, 12 October 2010 10:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You need to have direct executre privilege on the package.

Regards
Michel
Re: Need performance tuning in delete statement [message #478792 is a reply to message #478773] Tue, 12 October 2010 10:24 Go to previous messageGo to next message
sunroser
Messages: 16
Registered: September 2010
Junior Member
Hi, just alternative, have you tried EXISTS in that deletion sql. Usually exists gets better performance.
Re: Need performance tuning in delete statement [message #478794 is a reply to message #478773] Tue, 12 October 2010 10:37 Go to previous messageGo to next message
TinchoGomez
Messages: 11
Registered: January 2010
Location: Santa Fe - Argentina
Junior Member

It's correct sentence for exists.

DELETE FROM GL_ACCOUNT GA WHERE EXISTS (SELECT 1 FROM GL_ACCOUNT GL WHERE GL.BU_ID !=609 AND GL.GL_ACCT_ID = GA.GL_ACCT_ID );

I thinks these is best way your problem.
DELETE FROM GL_ACCOUNT GL WHERE GL.BU_ID !=609;
Re: Need performance tuning in delete statement [message #478795 is a reply to message #478773] Tue, 12 October 2010 10:39 Go to previous messageGo to next message
sunroser
Messages: 16
Registered: September 2010
Junior Member
burasami wrote on Tue, 12 October 2010 09:22
Hi All,

I need to performance tune SQL statement as follows
DELETE FROM GL_ACCOUNT WHERE GL_ACCT_ID IN (SELECT GL.GL_ACCT_ID FROM GL_ACCOUNT GL WHERE GL.BU_ID !=609);


the above Statement taking long time to delete record.

for test purpose i try to delete 3 row its take much time to delete 3 records

here by i have attached TKPROF file. Please help me to fine the sql query. since for past 3 days trying to fine tune but i can't able to solve this issue.

Thanks & Regards
Sami


Something like the below .. ...

DELETE FROM GL_ACCOUNT GL
WHERE EXISTS (
SELECT NULL FROM GL_ACCOUNT GL1
WHERE GL.GL_ACCT_ID = GL1.GL_ACCT_ID
AND GL1.BU_ID != 609);
Re: Need performance tuning in delete statement [message #478866 is a reply to message #478773] Wed, 13 October 2010 01:53 Go to previous messageGo to next message
michael_bialik
Messages: 621
Registered: July 2006
Senior Member
Look at your TKPROF:


select /*+ all_rows */ count(1) 
from
 "OFFLINETESTDB"."GL_ACCOUNT_QUARTERLY_STAT" where "GL_ACCT_ID" = :1 and 
  "GL_ACCT_NO" = :2


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      3      0.00       0.06          0          0          0           0
Fetch        3      1.64      20.79     108398     109500          0           3
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        7      1.64      20.86     108398     109500          0           3

Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS   (recursive depth: 1)

Rows     Row Source Operation
-------  ---------------------------------------------------
      3  SORT AGGREGATE (cr=109500 pr=108398 pw=0 time=20797344 us)
      0   TABLE ACCESS FULL GL_ACCOUNT_QUARTERLY_STAT (cr=109500 pr=108398 pw=0 time=20797279 us)

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

select /*+ all_rows */ count(1) 
from
 "OFFLINETESTDB"."GL_ACCOUNT_MONTHLY_STAT" where "GL_ACCT_ID" = :1 and 
  "GL_ACCT_NO" = :2


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      4      0.00       0.06          0          0          1           0
Fetch        3      0.75      10.11      52140      59532          0           3
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        9      0.75      10.18      52140      59532          1           3

Misses in library cache during parse: 1
Misses in library cache during execute: 1
Parsing user id: SYS

Rows     Row Source Operation
-------  ---------------------------------------------------
      3  SORT AGGREGATE (cr=59532 pr=52140 pw=0 time=10116280 us)
      0   TABLE ACCESS FULL GL_ACCOUNT_MONTHLY_STAT (cr=59532 pr=52140 pw=0 time=10116221 us)



Both statements perform FULL table scan on GL_ACCOUNT_MONTHLY_STAT and GL_ACCOUNT_QUARTERLY_STAT tables (IMHO you have some trigger(s) attached that execute these statements).

I recommend:

CREATE INDEX ... ON GL_ACCOUNT_QUARTERLY_STAT ( GL_ACCT_ID, GL_ACCT_NO ) ...

CREATE INDEX ... ON GL_ACCOUNT_MONTHLY_STAT ( GL_ACCT_ID, GL_ACCT_NO ) ...



HTH.
Michael

[Updated on: Wed, 13 October 2010 01:55]

Report message to a moderator

icon7.gif  Re: Need performance tuning in delete statement [message #478873 is a reply to message #478866] Wed, 13 October 2010 02:38 Go to previous message
burasami
Messages: 20
Registered: April 2010
Junior Member
Hi All

Thanks to one and all,

as per Michael suggestion. I got fixed the issue by creating index on both tables.

once again i thank you all for giving wonderful support and suggestion.

Thanks and Regards
Sami.

Previous Topic: Order of executing indexes (2 merged)
Next Topic: How we do Optimisation and tuning
Goto Forum:
  


Current Time: Mon Nov 25 13:14:08 CST 2024