Results 1 to 8 of 8

Thread: Sql join performance Query

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Answers
    2

    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?


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Sql join performance Query

    Create proper indexes. It will improve the performance.
    Also check execution plan of your statement.


  3. #3
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Sql join performance Query

    try to make the smaller table (as per rows) as your left most table. That might make so difference.


  4. #4
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    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.


  5. #5
    Junior Member
    Join Date
    Sep 2008
    Answers
    1

    Re: Sql join performance Query

    Select only the desired columns in the 'select' statement


  6. #6
    Junior Member
    Join Date
    Dec 2008
    Answers
    2

    Re: Sql join performance Query

    Indexing the best option in this situation


  7. #7
    Expert Member
    Join Date
    Nov 2008
    Answers
    300

    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.


  8. #8
    Contributing Member
    Join Date
    Jun 2009
    Answers
    76

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact