Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Optimising the insert into temp table query Expand / Collapse
Author
Message
Posted Wednesday, February 12, 2014 7:18 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 2:51 PM
Points: 15, Visits: 59
i have the below query which takes 1 hour to run please suggest any optimising method for the same :

Insert Into #Finaldata
Select Distinct A.id,F.me,F.status ,left(A.ffunction,3) 'function',
left(A.ction,6) '6characters',
A.sublist,A.status ,
'','','','' 'Account_status',''
From DBO.FUNCTION A Join #Finaldata B
On A.ccap_id=B.ccap_id
And A.id Not In (Select distinct id From #Finaldata)
left Join dbo.CUSTOMER F
On A.id=F.idl
left Join dbo.USER C
On A.ccap_id=C.ccap_id
And A.id=C.id
Where left(A.ffunction,3)<>'@@@'

Order by A.id
Post #1540722
Posted Wednesday, February 12, 2014 7:46 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:52 AM
Points: 42,445, Visits: 35,501
Table definitions, index definitions and execution plan please, as per http://www.sqlservercentral.com/articles/SQLServerCentral/66909/


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1540735
Posted Wednesday, February 12, 2014 2:25 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 2:51 PM
Points: 15, Visits: 59
please find the attached plan

  Post Attachments 
insertQuery.sqlplan (12 views, 148.46 KB)
Post #1540976
Posted Wednesday, February 12, 2014 4:00 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 9:58 AM
Points: 3,336, Visits: 7,199
You're still missing DDL for tables and indexes.
Things might speed up if you remove the ORDER BY and change your WHERE clause to
WHERE A.entitlement_function NOT LIKE '@@@%'

However, more improvements can be made with some changes to the DB (and possibly the code to remove the self join but I'm not sure). I'm sure that others will give better advices.



Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1540990
Posted Monday, February 24, 2014 3:04 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 4:23 PM
Points: 1,194, Visits: 2,209
Don't use function in the where clause. That will slow down the performance by disabling the indexes. Do as Luiz mentioned.

--
SQLBuddy
Post #1544725
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse