Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Dell PowerEdge Servers
  #1  
Old June 26th, 2003, 03:50 PM
marvel marvel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 marvel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Speed of inner joins

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.

Reply With Quote
  #2  
Old June 26th, 2003, 04:08 PM
MattR MattR is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: High above the mucky-muck (Columbus, OH)
Posts: 266 MattR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to MattR
What is the SHOWPLAN output?

Reply With Quote
  #3  
Old June 26th, 2003, 04:22 PM
marvel marvel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 marvel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #4  
Old June 26th, 2003, 04:29 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,298 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 1 h 54 m 21 sec
Reputation Power: 41
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

Reply With Quote
  #5  
Old June 26th, 2003, 04:37 PM
marvel marvel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 marvel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old June 26th, 2003, 04:40 PM
marvel marvel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 marvel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old June 26th, 2003, 05:31 PM
marvel marvel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 marvel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Speed of inner joins


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway