viernes, 1 de octubre de 2010

Como Crear un índice Filtrado en SQL Server 2008 / How to create a filtered index in SQL Server 2008

 

[Español]

Hola a todos hoy me gustaría compartir con ustedes una técnica muy interesante que encontré para resolver un problema de desempeño en una consulta.

Todos sabemos que un buen índice es la solución en muchas de las ocasiones para los problemas de desempeño, pero hay que tener mucho cuidado porque crear muchos índices tampoco es bueno. Entonces como tener un índice que mejore el desempeño pero que no desperdicie espacio.

Un indicie filtrado permite indicar a la base que ciertos registros son los que utilizaran ese índice por lo que al ser una muestra del universo de datos, este índice siempre va ser más pequeño que cualquier otro índice y una de las ventajas escondidas es que si los resultados a obtener no están dentro de ese rango de datos, la base de datos simplemente optará por utilizar otro índice.

Les copio la sentencia para la creación de un índice filtrado

CREATE NONCLUSTERED INDEX NOMBRE_DEL_INDICE
ON Schema.Tabla(Columna)
WHERE CualquierColumna_De_La_Tabla [=>< is null] Filtro

Un ejemplo de esto seria

CREATE NONCLUSTERED INDEX NCI_Department
ON HumanResources.Employee(EmployeeID)
WHERE Title= 'Marketing Manager'

 

Saludos

Julio Valencia

[English]

Hello everyone, today I would like to share with you a interesting technique founded while surfing the internet to solve some performance issue.

We know that a good index most of the times is the right solution for performance issues, but we must be careful when we create an index because too much of everything is not good either.  So how we can have an index that help us with our performance issue and furthermore it will not waste space?

A filtered index allows us to tell the database only a few records from the Data universe will fullfill the search criteria, and because of this, the filtered index always is smaller than any other index in the database. Another good thing of this is if our query does not match the index criteria the engine will use another index instead.

this is the sql syntax that creates a filtered index with a example:

CREATE NONCLUSTERED INDEX NOMBRE_DEL_INDICE
ON Schema.Tabla(Columna)
WHERE CualquierColumna_De_La_Tabla [=>< is null] Filtro

Un ejemplo de esto seria

CREATE NONCLUSTERED INDEX NCI_Department
ON HumanResources.Employee(EmployeeID)
WHERE Title= 'Marketing Manager'

 

Cheers

Julio Valencia

No hay comentarios:

Publicar un comentario

Nota: solo los miembros de este blog pueden publicar comentarios.