November 3, 2008 at 9:31 am
Hi,
I have a cursor which fetch around 1000 rows from the table.
This step is fast there is no isue. But which inserting the row into the table takes lots of time. So i was thinking how to tune this.
Query is attached with time statistics data.
Waiting for your replies.....
Cheers,
Got an idea..share it !!
DBA_Vishal
November 3, 2008 at 9:46 am
The insert statement takes ten seconds and this is being run inside the cursor 1000 times. I think it's pretty clear that it is the cursor that is your problem. Even if you got the statement to run in 100ms you're still going to run it 1000 times - that's 100 seconds. And if tomorrow you're suddenly doing it over 10,000 rows then it will take even longer.
But, if you're going to persist with using the cursor and if you want to tune the insert statement then try and tune the corresponding select statement (below)... get the execution plan and look at where you're doing index scans and where it might be appropriate to place indexes.
SELECT 10126824 as STRATEGY_KEY, DEAL_DETAIL_ID as DEAL_ID, '10/03/2008' as COB_DT from STAGE.DEAL_DETAIL WHERE DEAL_HEADER_ID IS NOT NULL AND [STRATEGY_KEY]>0 AND COB_DT = '10/03/2008' AND STRATEGY_NM IN ('GS&T-GT-406733','PSAT-GT-407230','Americas Products-GT-407234','Distillates-GT-408232','2007 Roll-GT-408495','GTL Diesel Sep 2007 - GLP-GT-387447')
November 3, 2008 at 11:06 am
Please provide the DDL's including any keys and indexes for STAGE.DEAL_DETAIL and STAGE.REF_DEAL_STRATEGY.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
November 3, 2008 at 9:17 pm
vkundar (11/3/2008)
Hi,I have a cursor which fetch around 1000 rows from the table.
This step is fast there is no isue.
Heh.... Bzzzzt! Wrong answer! Deduct 10 points! 😛 As Karl suggested, using the cursor IS the issue... 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
November 4, 2008 at 2:37 am
I agree with you Cursor takes time. I had the same experience earlier.
Is there a way to reduce the time taken for the Insert statement in the cursor ? I am just blank on this. It will of real use.
"More Green More Oxygen !! Plant a tree today"
November 4, 2008 at 5:11 am
shalu (11/4/2008)
Is there a way to reduce the time taken for the Insert statement in the cursor ? I am just blank on this.
So is everyone else... that's why you shouldn't use a cursor to begin with. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
November 4, 2008 at 8:42 am
Thanks SQLZ & Jeff for replying. I have added indexes as suggested by SQLZ and it has improved the performance.
Would like to have a pointers about indexing and other best tips for query tuning in Dataware housing.
Cheers,
Got an idea..share it !!
DBA_Vishal
November 4, 2008 at 7:06 pm
Heh... the best tip has already been given... did you get rid of the cursor?;)
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply