sql-serverdatabase-optimization

Why this query uses two table scans?


I have this simple query on SQL Server 2008 R2:

SELECT Art.ID_Articulo, 
       conv.Factor AS PesoToneladas 
FROM   dbo.Articulos Art 
       LEFT JOIN dbo.Conversiones conv 
              ON conv.ID_Articulo = Art.ID_Articulo 
                 AND conv.ID_Unidad1 = Art.ID_Unidad 

Table Articulos is indexed individually by ID_Articulo and ID_Unidad. Table Conversiones is indexed individually by ID_Articulo and ID_Unidad1.

Execution plans shows table scan for both tables taking a lot of resources.

How can I find why?


Solution

  • There are no filters in your query, considering this you will aggregate the entire 2 tables. Using indexes sql might need to spend more resources on lookups. So it's probably cheaper to do table scans.

    If you will use filters to cut down your data sql might decide to change the plan.