Thread: Update Performance Issue

This question is answered. Helpful answers available: 5. Correct answers available: 1.


Permlink Replies: 16 - Pages: 2 [ 1 2 | Next ] - Last Post: Nov 24, 2009 7:47 AM Last Post By: Joze Senegacnik
user12260689

Posts: 10
Registered: 11/23/09
Update Performance Issue
Posted: Nov 23, 2009 3:28 AM
 
Click to report abuse...   Click to reply to this thread Reply
Hi everyone I need to improve update performance of the table called dcag_document_item_lines

STATEMENT
update /*+ NO_CPU_COSTING */ dcag_document_item_lines a
set A.ALIEN_ITEM = 'N'
where EXISTS (SELECT b.ip_part_code
from pending_dcag_pt6_mra B
where A.CODE = B.ip_part_code)
AND A.item_line_type=('PA')
AND EXISTS (SELECT c.document_id
from dcag_documents c
where c.document_id = a.document_id
and c.document_date >= '01-jan-2007');

NUMBER OF RECORDS

dcag_document_item_lines=200 millon records
pending_dcag_pt6_mra =1.7 million
dcag_documents =10 Million

INDEXED COLUMNS

dcag_document_item_lines.DOCUMENT_ID -----inndex1
dcag_document_item_lines.LINE_ITEM_NO -----inndex2

dcag_documents.CLIENT_ID -----D_CLIENT_DEP_DOC_DATE_IND
DEPARTMENT_TYPE
DOCUMENT_DATE
MODEL_ID
POSTCODE_TYPE
AGE_AT_EVENT
VEHICLE_ID

dcag_documents.DOCUMENT_ID ----DCAG_DOCUMENTS_PK

PENDING_DCAG_PT6_MRA.IP_PART_CODE -----PENDING_DCAG_PT6_MRA_IDX
PENDING_DCAG_PT6_MRA.SYS_NC00010$------PT6_PRINT_PART_CODE_IDX
PENDING_DCAG_PT6_MRA.SYS_NC00011$------PT6_SORTCODE_IDX

ORACLE VER:Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

EXECUTION PLAN


Statement Id=1638424 Type=
Cost=2.0960068036193E-317 TimeStamp=23-11-09::11::33:52

(1) UPDATE STATEMENT CHOOSE
Est. Rows: 18,609,815 Cost: 580,793
UPDATE DCAG.DCAG_DOCUMENT_ITEM_LINES
(6) HASH JOIN RIGHT SEMI
Est. Rows: 18,609,815 Cost: 580,793
(2) TABLE TABLE ACCESS FULL DCAG.DCAG_DOCUMENTS [Analyzed]
(2) Blocks: 633,918 Est. Rows: 12,113,924 of 24,916,950 Cost: 96,214
Tablespace: DCAG_T
(5) HASH JOIN RIGHT SEMI
Est. Rows: 25,321,324 Cost: 460,759
(3) INDEX INDEX FAST FULL SCAN DCAG.PENDING_DCAG_PT6_MRA_IDX [Analyzed]
Est. Rows: 1,700,302 Cost: 1,694
(4) TABLE TABLE ACCESS FULL DCAG.DCAG_DOCUMENT_ITEM_LINES [Analyzed]
(4) Blocks: 2,778,518 Est. Rows: 73,066,252 of 199,390,240 Cost: 421,708
Tablespace: DCAG_T

Any help will be aprreciated.

Thanks guys.

Edited by: user12260689 on 23-Nov-2009 03:35

user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 23, 2009 3:31 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
SQL Statement from editor:

update /*+ NO_CPU_COSTING */ dcag_document_item_lines a
set A.ALIEN_ITEM = 'N'
where EXISTS (SELECT b.ip_part_code
from pending_dcag_pt6_mra B
where A.CODE = B.ip_part_code)
AND A.item_line_type=('PA')
AND EXISTS (SELECT c.document_id
from dcag_documents c
where c.document_id = a.document_id
and c.document_date >= '01-jan-2007');


Statement Id=1638424 Type=
Cost=2.0960068036193E-317 TimeStamp=23-11-09::11::33:52

(1) UPDATE STATEMENT CHOOSE
Est. Rows: 18,609,815 Cost: 580,793
UPDATE DCAG.DCAG_DOCUMENT_ITEM_LINES
(6) HASH JOIN RIGHT SEMI
Est. Rows: 18,609,815 Cost: 580,793
(2) TABLE TABLE ACCESS FULL DCAG.DCAG_DOCUMENTS [Analyzed]
(2) Blocks: 633,918 Est. Rows: 12,113,924 of 24,916,950 Cost: 96,214
Tablespace: DCAG_T
(5) HASH JOIN RIGHT SEMI
Est. Rows: 25,321,324 Cost: 460,759
(3) INDEX INDEX FAST FULL SCAN DCAG.PENDING_DCAG_PT6_MRA_IDX [Analyzed]
Est. Rows: 1,700,302 Cost: 1,694
(4) TABLE TABLE ACCESS FULL DCAG.DCAG_DOCUMENT_ITEM_LINES [Analyzed]
(4) Blocks: 2,778,518 Est. Rows: 73,066,252 of 199,390,240 Cost: 421,708
Tablespace: DCAG_T

Edited by: user12260689 on 23-Nov-2009 03:33

Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 23, 2009 3:46 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
What is the number of actually updated rows - the CBO's estimate is 713,287.

First of all I would add the following condition to the main update statement:

AND A.ALIEN_ITEM != 'N'


This condition will filter out all rows which don't need to be updated as they already contain 'N' in ALIEN_ITEM column. Then both EXISTS will be performed only for the rows which pass this additional condition. Also less redo will be generated as fewer rows will be updated. Maybe I'm wrong here because I don't know how many rows will really pass this filter. However, this additional condition should be there!
Besides this you could add a new index on dcag_document_item_lines ( item_line_type,alien_item ) but this will produce quite a big overhead when inserting and updating this table due to the maintenance of a new index and besides that I suspect if CBO would really use it.

HTH, Joze

Co-author of forthcoming OakTable book: "Expert Oracle Practices"
http://www.apress.com/book/view/9781430226680
user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 23, 2009 4:15 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
updated records will be around 35 million.
Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 23, 2009 4:19 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
updated records will be around 35 million.

With that additional condition or without it?
user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 23, 2009 4:22 AM   in response to: Joze Senegacnik in response to: Joze Senegacnik
 
Click to report abuse...   Click to reply to this thread Reply
With that additional condition.
Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 23, 2009 4:27 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
Sorry not to ask before explicitly - how many rows are updated without the additional condition?

This is a duplicate of thread http://forums.oracle.com/forums/message.jspa?messageID=3921597#3921597

Regards, Joze

Co-author of forthcoming OakTable book "Expert Oracle Practices"
http://www.apress.com/book/view/9781430226680
user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 23, 2009 6:31 AM   in response to: Joze Senegacnik in response to: Joze Senegacnik
 
Click to report abuse...   Click to reply to this thread Reply
Sorry joze I missinformed you.

select count(*) from dcag_document_item_lines a
                                     where EXISTS (SELECT b.ip_part_code
                                     from pending_dcag_pt6_mra B 
                                    where A.CODE = B.ip_part_code) 
                       AND A.item_line_type=('PA') 
                       AND EXISTS (SELECT c.document_id 
                                     from dcag_documents c 
                                    where c.document_id = a.document_id 
                                      and c.document_date >= '01-jan-2007')


returned 5458022 records

and with
select count(*) from dcag_document_item_lines a
                                     where EXISTS (SELECT b.ip_part_code
                                     from pending_dcag_pt6_mra B 
                                    where A.CODE = B.ip_part_code) 
                       AND A.item_line_type=('PA') 
                       AND EXISTS (SELECT c.document_id 
                                     from dcag_documents c 
                                    where c.document_id = a.document_id 
                                      and c.document_date >= '01-jan-2007')
                                      AND A.ALIEN_ITEM != 'N'


returned 34620 records

Edited by: user12260689 on 23-Nov-2009 07:54
Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 23, 2009 11:09 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
Ok, I'm glad that additional condition will significantly reduce the number of rows and will now return only rows which should really be updated.
Most likely the proposed index on columns item_line_type,alien_item could be beneficial as well. So now you have to decide: to create an index or not, that's the question :-)

Regards, Joze

Co-author of forthcoming OakTable book "Expert Oracle Practices"
http://www.apress.com/book/view/9781430226680
user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 24, 2009 3:06 AM   in response to: Joze Senegacnik in response to: Joze Senegacnik
 
Click to report abuse...   Click to reply to this thread Reply
Actually ITEM_LINE_TYPE and ALIEN_ITEM index allready created.
Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 24, 2009 3:08 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
And what is the performance now?
user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 24, 2009 3:40 AM   in response to: Joze Senegacnik in response to: Joze Senegacnik
 
Click to report abuse...   Click to reply to this thread Reply
Took 37 minutes in test database which will be twice slower in production database. Also tried another test which is

update /*+ NO_CPU_COSTING */ dcag_document_item_lines_t a 
                       set A.ALIEN_ITEM = 'Y' 
                     where NOT EXISTS (SELECT b.ip_part_code 
                                     from pending_dcag_pt6_mra B 
                                    where A.CODE = B.ip_part_code) 
                       AND A.item_line_type=('PA') 
                       AND EXISTS (SELECT c.document_id 
                                     from dcag_documents c 
                                    where c.document_id = a.document_id 
                                      and c.document_date >= '01-jan-2007')
                                      and A.ALIEN_ITEM = 'N'

Took 42 minutes for 858031 records updated.

Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 24, 2009 3:46 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
Can you tell what was the timing before changing SQL and creating index. Did you check that the index is really used?

Regards, Joze

Co-author of forthcoming OakTable book "Expert Oracle Practices"
http://www.apress.com/book/view/9781430226680

Home page: http://www.dbprof.com
Oracle blog: http://joze-senegacnik.blogspot.com/
Blog about flying: http://jsenegacnik.blogspot.com/
user12260689

Posts: 10
Registered: 11/23/09
Re: Update Performance Issue
Posted: Nov 24, 2009 4:26 AM   in response to: Joze Senegacnik in response to: Joze Senegacnik
 
Click to report abuse...   Click to reply to this thread Reply
Index is not used.
Joze Senegacnik

Posts: 162
Registered: 11/06/09
Re: Update Performance Issue
Posted: Nov 24, 2009 4:35 AM   in response to: user12260689 in response to: user12260689
 
Click to report abuse...   Click to reply to this thread Reply
I was affraid that that will be the answer. If the number of updated rows would be only bout 40,000 as you reported yesterday then the index would be used. If you expect that you will have such updates in future than it is worth to keep the index, otherwise I would drop it. What are the timings before and after tuning?

Regards, Joze

Co-author of forthcoming OakTable book "Expert Oracle Practices"
http://www.apress.com/book/view/9781430226680

Home page: http://www.dbprof.com
Oracle related blog: http://joze-senegacnik.blogspot.com/
Blog about flying: http://jsenegacnik.blogspot.com/
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums