Solved

Left join running very slow - any directions to speed up

Posted on 2008-10-28
7
217 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

786 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