?
Solved

Left join running very slow - any directions to speed up

Posted on 2008-10-28
7
Medium Priority
?
221 Views
Last Modified: 2008-11-06
I have a query using left join, running very slow - how to speed up.

SELECT temp_RFI.callid, [%$##@_Alias].request_type
FROM temp_RFI LEFT JOIN [SELECT call.request_type, call.casetype, oldcasenumber
FROM call
WHERE (((call.request_type)="IT" Or (call.request_type)="TA") AND ((call.casetype)="FA" Or (call.casetype)="NFA" Or (call.casetype)="ERU" Or (call.casetype)="Lost Injured Missing"))]. AS [%$##@_Alias] ON temp_RFI.oldcasenumber = [%$##@_Alias].oldcasenumber;
0
Comment
Question by:Jsara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 11

Expert Comment

by:SeanStrickland
ID: 22821950
Do you have indexes on requesttype and casetype?

That would probably help.
0
 

Author Comment

by:Jsara
ID: 22821989
Yes the requesttype and casetype fields are part of index fields.
0
 
LVL 9

Expert Comment

by:jamesgu
ID: 22822311
is it slow to run your inner query alone?

[SELECT call.request_type, call.casetype, oldcasenumber
FROM call
WHERE (((call.request_type)="IT" Or (call.request_type)="TA") AND ((call.casetype)="FA" Or (call.casetype)="NFA" Or (call.casetype)="ERU" Or (call.casetype)="Lost Injured Missing"))

is oldcasenumber  the first column of your index if any on your temp_RFI  table?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:Jsara
ID: 22822519
The inner query runs faster no problem with that.
0
 
LVL 17

Expert Comment

by:Natchiket
ID: 22823174
sometimes using an IN clause works faster than OR , you could try:

SELECT temp_RFI.callid, [%$##@_Alias].request_type
FROM temp_RFI LEFT JOIN [SELECT call.request_type, call.casetype, oldcasenumber
FROM call
WHERE (((call.request_type IN ("IT","TA")) AND ((call.casetype IN ("FA","NFA","ERU","Lost Injured Missing")))]. AS [%$##@_Alias] ON temp_RFI.oldcasenumber = [%$##@_Alias].oldcasenumber;

(not sure about my bracketing but you get the idea)


0
 
LVL 11

Expert Comment

by:SeanStrickland
ID: 22825069
Can you join them directly without doing the subquery?  It's likely running slow because you're hitting that subquery on every record that you'll pulling here: "SELECT temp_RFI.callid, [$##@_Alias].request_type FROM temp_RFI".  If you can do this without a subquery it will run faster, otherwise this may be the fastest way for you to process it.  What I'm saying is similar to the code below, but not dead on.

SELECT temp_RFI.callid, [%$##@_Alias].request_type, call.request_type, call.casetype, call.oldcasenumber
FROM temp_RFI LEFT JOIN temp_RFI.oldcasenumber = [%$##@_Alias].oldcasenumber
WHERE ((call.request_Type IN ("IT","TA")) AND (call.casetype IN ("FA","NFA","ERU","Lost Injured Missing"));
0
 
LVL 9

Accepted Solution

by:
jamesgu earned 2000 total points
ID: 22837005
do you have an index on the  temp_RFI  table?

is oldcasenumber  the first column of your index if any on your temp_RFI  table?
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question