|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am hoping someone can help me with a speed issue. We use MS SQL 7 and I have found that one of my latest queries is painfully slow, but has a lot of inner joins. Here is my query:
SELECT workorders.woID, workorders.woCustID, (SELECT TOP 1 noteCallCode FROM notes WHERE noteWOID = woID AND noteType = 'Call' ORDER BY noteDateTime DESC) AS noteCallCode, workorders.woStatus, workorders.woMachID, workorders.woDateTime, workorders.woCurrentTechID, workorders.woLocation, workorders.woLaborType, workorders.woLastCallDate, workorders.woTechID, workorders.woMiscID, customers.custID, customers.custFirstName, customers.custLastName, customers.custOrganization, techs.techID, techs.techInitial, techs.techColor, techs.techName, locations.localID, locations.localName, machines.machType FROM techs INNER JOIN workorders ON techs.techID = workorders.woCurrentTechID INNER JOIN customers ON workorders.woCustID = customers.custID INNER JOIN locations ON workorders.woLocation = locations.localID INNER JOIN machines ON workorders.woMachID = machines.machID INNER JOIN notes ON workorders.woID = notes.noteWOID WHERE (notes.noteRead = 0) AND (techs.techID = 12) ORDER BY workorders.woDateTime DESC Currently this will only return 3 records like it should, but it takes over 2800ms to do it, can anyone tell me what to do here? I am also only selecting nessesary columns in that statement. Thanks. |
|
#2
|
|||
|
|||
|
What is the SHOWPLAN output?
|
|
#3
|
|||
|
|||
|
Hope this displays right:
|--Sort(ORDER BY:([workorders].[woDateTime] DESC)) |--Compute Scalar(DEFINE:([Expr1014]=[Expr1014])) |--Nested Loops(Inner Join) |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[techs].[PK_techs]), SEEK:([techs].[techID]=12) ORDERED) |--Nested Loops(Inner Join) |--Nested Loops(Inner Join) | |--Hash Match(Inner Join, HASH:([workorders].[woID])=([notes].[noteWOID]), RESIDUAL:([workorders].[woID]=[notes].[noteWOID])) | | |--Nested Loops(Left Outer Join) | | | |--Nested Loops(Inner Join) | | | | |--Clustered Index Scan(OBJECT:([techmasterdev].[dbo].[workorders].[PK_workorders]), WHERE:([workorders].[woCurrentTechID]=12) ORDERED) | | | | |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[machines].[PK_machines]), SEEK:([machines].[machID]=[workorders].[woMachID]) ORDERED) | | | |--Compute Scalar(DEFINE:([notes].[noteCallCode]=[notes].[noteCallCode])) | | | |--Top(1) | | | |--Sort(ORDER BY:([notes].[noteDateTime] DESC)) | | | |--Index Spool(SEEK:([notes].[noteWOID]=[workorders].[woID] AND [notes].[noteType]='Call')) | | | |--Table Scan(OBJECT:([techmasterdev].[dbo].[notes])) | | |--Filter(WHERE:([notes].[noteRead]=0)) | | |--Table Scan(OBJECT:([techmasterdev].[dbo].[notes])) | |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[customers].[PK_customers]), SEEK:([customers].[custID]=[workorders].[woCustID]) ORDERED) |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[locations].[PK_locations]), SEEK:([locations].[localID]=[workorders].[woLocation]) ORDERED) |
|
#4
|
|||
|
|||
|
Whenever displaying text like this, it is usually best to put the text inside the [ code ] tags, and check the "Disable Smilies in This Post " option at the bottom. (of course, this also disables line-wrapping, so be careful about posting extremely wide text selections)
Code:
|--Sort(ORDER BY:([workorders].[woDateTime] DESC)) |--Compute Scalar(DEFINE:([Expr1014]=[Expr1014])) |--Nested Loops(Inner Join) |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[techs].[PK_techs]), SEEK:([techs].[techID]=12) ORDERED) |--Nested Loops(Inner Join) |--Nested Loops(Inner Join) | |--Hash Match(Inner Join, HASH:([workorders].[woID])=([notes].[noteWOID]), RESIDUAL:([workorders].[woID]=[notes].[noteWOID])) | | |--Nested Loops(Left Outer Join) | | | |--Nested Loops(Inner Join) | | | | |--Clustered Index Scan(OBJECT:([techmasterdev].[dbo].[workorders].[PK_workorders]), WHERE:([workorders].[woCurrentTechID]=12) ORDERED) | | | | |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[machines].[PK_machines]), SEEK:([machines].[machID]=[workorders].[woMachID]) ORDERED) | | | |--Compute Scalar(DEFINE:([notes].[noteCallCode]=[notes].[noteCallCode])) | | | |--Top(1) | | | |--Sort(ORDER BY:([notes].[noteDateTime] DESC)) | | | |--Index Spool(SEEK:([notes].[noteWOID]=[workorders].[woID] AND [notes].[noteType]='Call')) | | | |--Table Scan(OBJECT:([techmasterdev].[dbo].[notes])) | | |--Filter(WHERE:([notes].[noteRead]=0)) | | |--Table Scan(OBJECT:([techmasterdev].[dbo].[notes])) | |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[customers].[PK_customers]), SEEK:([customers].[custID]=[workorders].[woCustID]) ORDERED) |--Clustered Index Seek(OBJECT:([techmasterdev].[dbo].[locations].[PK_locations]), SEEK:([locations].[localID]=[workorders].[woLocation]) ORDERED)
__________________
The real n-tier system: FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL Amazon wishlist -- rycamor (at) gmail.com |
|
#5
|
|||
|
|||
|
Thanks, I didn't see any quick buttons for anything like that, but as you see I didn't go look at the documentation. Looks much nicer in that.
|
|
#6
|
|||
|
|||
|
Ahh, I am reading about this showplan stuff(haven't used it before). I guess I should put in some different indexes to avoid the "scans" but I'm not sure where would be the best
|
|
#7
|
|||
|
|||
|
Well I figured it out. Thanks for sorta telling me about the showplan stuff. I managed to make a couple other slower queries work much faster as well.
|
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > Speed of inner joins |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|