SQL Server, fetching data from multiple joined tables. Why is slow?

Posted by user562192 on Stack Overflow See other posts from Stack Overflow or by user562192
Published on 2011-01-04T07:33:25Z Indexed on 2011/01/04 7:53 UTC
Read the original article Hit count: 142

Filed under:
|

I have problem with performance when retrieving data from SQL Server.

My sql query looks something like this:

SELECT 
  table_1.id, 
  table_1.value, 
  table_2.id, 
  table_2.value,..., 
  table_20.id, 
  table_20.value
From table_1 
INNER JOIN table_2 
ON table_1.id = table_2.table_1_id 
INNER JOIN table_3 
ON  table_2.id = table_3.table_2_id...
WHERE table_1.row_number BETWEEN 1 AND 20

So, I am fetching 20 results. This query takes about 5 seconds to execute. When I select only table_1.id, it returns results instantly. Because of that, I guess that problem is not in JOINs, it is in retrieving data from multiple tables.

Any suggestions how I would speed up this query?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server