Solved

Left join running very slow - any directions to speed up

Posted on 2008-10-28
7
220 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

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