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: Thursday, August 14, 2014 8:12 AM
Points: 17, Visits: 80
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 PM
Points: 42,849, Visits: 35,978
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: Thursday, August 14, 2014 8:12 AM
Points: 17, Visits: 80
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 @ 8:15 PM
Points: 3,564, Visits: 7,702
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.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

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: Friday, August 29, 2014 1:14 PM
Points: 1,194, Visits: 2,217
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