Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Sql join performance Query

This is a discussion on Sql join performance Query within the Database Design forums, part of the Databases category; I have a sql join 3 tables, like this: select * from tableA a left join tableB b on a.id1 = b.id1 left join tableC c on b.id2 = c.id2 ...

Go Back   Geeks Talk > Databases > Database Design
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Database Design Disucss if you have any issues with Database Design and Concepts

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2008
Junior Member
 
Join Date: Jul 2008
Location: Bombay
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
PompanaGouda is on a distinguished road
Sql join performance Query

I have a sql join 3 tables, like this:

select *
from tableA a
left join tableB b
on a.id1 = b.id1
left join tableC c
on b.id2 = c.id2

It works with the correct result, but takes so long time. For example, in each table, there is about 300 rows --> the above query takes ~ 20 seconds.
Does anyone know how to improve in this case?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-07-2008
Expert Member
 
Join Date: Sep 2007
Posts: 738
Thanks: 22
Thanked 67 Times in 65 Posts
krishnaindia2007 is on a distinguished road
Re: Sql join performance Query

Create proper indexes. It will improve the performance.
Also check execution plan of your statement.
Reply With Quote
  #3 (permalink)  
Old 07-08-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,853
Thanks: 9
Thanked 168 Times in 142 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
Re: Sql join performance Query

try to make the smaller table (as per rows) as your left most table. That might make so difference.
Reply With Quote
  #4 (permalink)  
Old 07-08-2008
Expert Member
 
Join Date: Sep 2007
Posts: 738
Thanks: 22
Thanked 67 Times in 65 Posts
krishnaindia2007 is on a distinguished road
Re: Sql join performance Query

Quote:
Originally Posted by debasisdas View Post
try to make the smaller table (as per rows) as your left most table. That might make so difference.

The very purpose of the left outer join is to get the records meets the join condition + rest of the rows from left table.

The left most table will the table that he wants to get all the records whether it satisfies the join condition or not.

Changing the smaller table as left most table may not serve its purpose.
Reply With Quote
  #5 (permalink)  
Old 09-07-2008
Junior Member
 
Join Date: Sep 2008
Location: England
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
aliaheed is on a distinguished road
Re: Sql join performance Query

Select only the desired columns in the 'select' statement
Reply With Quote
  #6 (permalink)  
Old 01-17-2009
Junior Member
 
Join Date: Dec 2008
Location: usa
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
imran44 is on a distinguished road
Re: Sql join performance Query

Indexing the best option in this situation
Reply With Quote
  #7 (permalink)  
Old 01-19-2009
Expert Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 303
Thanks: 1
Thanked 37 Times in 32 Posts
amitpatel66 is on a distinguished road
Re: Sql join performance Query

Are the index created on the tables? Again you have only 300 records so creating an index might not work out for you becuase the data volume is very very less.
Reply With Quote
  #8 (permalink)  
Old 06-27-2009
Contributing Member
 
Join Date: Jun 2009
Location: United States
Posts: 71
Thanks: 0
Thanked 5 Times in 4 Posts
CSOOR is on a distinguished road
Re: Sql join performance Query

Since the query has " Select * ", server will not able to understand which " id "column to select . So please specify all the common columns in the select statement. This will help you.

Check all the ids columns in the where clause have values. Could be because of null values in the ids columns , if these are ids then must have unique values. Performance could be because of your data.
Reply With Quote
Reply

  Geeks Talk > Databases > Database Design

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Outer Join Query Example mailtos.ravi SQL 4 03-05-2008 04:34 AM
Query Performance krishnaindia2007 Oracle 4 12-12-2007 04:21 AM
calculating the sum of a field in a query with join 3roses Oracle 2 09-05-2007 01:17 PM
Writing query with LEFT OUTER JOIN N SRIRAM K Data Warehousing 5 09-03-2007 06:08 AM
Join Query without using NOT IN subquery Geek_Guest SQL 1 03-07-2007 04:24 PM


All times are GMT -4. The time now is 09:49 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved