Translate

SQL Server Plans : difference between Index Scan / Index Seek

SQL Server: diferença entre busca de índice 

-------------     ATENÇÃO DESENVOLVEDOR    -----------
      USE O MÁXIMO DE RECURSOS DO SQL
     PROCURE VERIFICAR QUAL O MELHOR ÍNDICE A SER USADO PARA AS TABELAS  FORCE O MSSQL A UTILIZAR O INDEX SEEK
           EXEMPLO: CAMPO_INTEIRO > 0 é melhor que CAMPO_INTERIO <> 0
  *PORQUE SE USAR CAMPOS FORA DO ÍNDICE O MSSQL - USARÁ O TABLE SCAN

 Index Seek

When SQL Server does a seek it knows where in the index that the data is going to be, so it loads up the index from disk, goes directly to the part of the index that it needs and reads to where the data that it needs ends. This is obviously a much more efficient operation than a scan, as SQL already knows where the data it is looking for is located.

Fonte:


PORTUGUÊS
Quando o SQL Server faz uma pesquisa, ele sabe onde, no índice, os dados serão carregados, portanto, ele carrega o índice do disco, vai diretamente para a parte do índice que precisa e lê para onde os dados necessários. Esta é obviamente uma operação muito mais eficiente do que uma varredura, já que o SQL já sabe onde estão localizados os dados que está procurando.

SET NOCOUNT ON;
GO
SET SHOWPLAN_ALL ON;
GO
SELECT column_b, column_a
FROM tabela
WHERE column_b  BETWEEN 'Each' AND 'Inch';
GO
SET SHOWPLAN_ALL OFF;