Solved

Left join running very slow - any directions to speed up

Posted on 2008-10-28
7
215 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now