fundamentos sobre los indices en sql server

35
Fundamentos sobre los índices en SQL Server 20 de Agosto (12 pm GMT - 5) Enrique Puig Resúmen: Los índices son elementos importantísimos a la hora de optimizar consultas. En esta sesión abarcaremos los distintos tipos de índices que existen, veremos como nos ayudan a optimizar consultas y finalmente hablaremos de su mantenimiento.. Próximos Eventos Indices columnares en SQL Server 2014 10 de Septiembre José L. Rivera Visualización de Big Data con Power View 27 de Agosto Eduardo Castro Mejores prácticas de SQL Server para implementar SharePoint 3 de Septiembre David Sánchez Está por comenzar:

Upload: kike-puig

Post on 20-Jun-2015

219 views

Category:

Data & Analytics


0 download

DESCRIPTION

Introducción a los indices mas comunes en SQL Server. Presentación realizada con el Virtual Spanish Chapter de PASS.

TRANSCRIPT

Page 1: Fundamentos sobre los indices en SQL Server

Fundamentos sobre los índices en SQL Server

20 de Agosto (12 pm GMT -5)

Enrique PuigResúmen:Los índices son elementos importantísimos a la hora de optimizar consultas. En esta sesión abarcaremos los distintostipos de índices que existen, veremos como nos ayudan a optimizar consultas y finalmente hablaremos de su mantenimiento..

Próximos Eventos

Indices columnares en SQL Server 2014

10 de SeptiembreJosé L. Rivera

Visualización de Big Data con Power View

27 de AgostoEduardo Castro

Mejores prácticas de SQL Server para implementar SharePoint

3 de SeptiembreDavid Sánchez

Está por comenzar:

Page 2: Fundamentos sobre los indices en SQL Server

Fundamentos sobre los Índices en SQL Server20/08/2014

Enrique PuigMAP | MCITPDBA at RipLife Gaming TechnologiesBlog: www.sqlserverpasion.comMail: [email protected]: @epuignouselles

Page 3: Fundamentos sobre los indices en SQL Server

3

Objetivos

• Introducción a los Índices• ¿Qué son?• ¿Para que sirven?• ¿Qué tipos de índices existen?• ¿Cómo ayudan los índices a mejorar el performance?

Page 4: Fundamentos sobre los indices en SQL Server

4

Agenda

• ¿Qué son los índices?• Introducción• Heaps• Índices clustered• Índices nonclustered• Conclusiones• Preguntas

Page 5: Fundamentos sobre los indices en SQL Server

5

¿Qué son los Índices?

Page 6: Fundamentos sobre los indices en SQL Server

6

Introducción

• Gestores de base de datos guardan información (Datos) en• Tablas / Relaciones

• Conjuntos de datos no ordenados• Los datos se almacenan en disco• Unidad de almacenamiento son Paginas de datos (8KB)

Page 7: Fundamentos sobre los indices en SQL Server

7

Introducción (II)

Data Page 1 Data Page 2 Data Page 3 Data Page 4 …

dbo.Sales

Page 8: Fundamentos sobre los indices en SQL Server

8

Heaps

• ´Montón’ de datos no ordenado• Un Heap es la Tabla• Contiene los datos

Data Data Data Data Data

IAM

Page 9: Fundamentos sobre los indices en SQL Server

9

Índices clustered

• Estructura de datos: Árbol B• Estructura de datos ordenada por clave• El Índice clustered es la tabla• Contiene todos los datos• Nodos hoja

• Primary Key by Default

Root

Int.

Data Data

Int

Data Data

Page 10: Fundamentos sobre los indices en SQL Server

10

Heaps vs. Clustered Indexes

• Clustered Index• Datos ordenados• Acceso a datos rápido (KEY)• Paginas de datos enlazadas

• Acceso secuencial eficiente

• Heaps• Datos no ordenados• Paginas de datos no enlazadas

• Acceso secuencial ineficiente• Consultas extra a la IAM

• Recomendación: Utilizar Clustered Index

Page 11: Fundamentos sobre los indices en SQL Server

11

DEMO: Heaps vs. Índices clustered

Page 12: Fundamentos sobre los indices en SQL Server

12

Índices nonclustered

• Estructura auxiliar a la tabla de datos: Árbol B• Ordenada por Clave del Índice• Nodos hoja contienen• Claves de Índice• Referencia a registro de datos

Root

Int.

KeyRef

KeyRef

Int

KeyRef

KeyRef

Page 13: Fundamentos sobre los indices en SQL Server

13

Índices nonclustered vs. Clustered

Root

Int.

Data Data

Int

Data Data

Root

Int.

KeyRef

KeyRef

Int

KeyRef

KeyRef

Nonclustered INDEX Clustered INDEX

KEY + Row Reference Data rows

Page 14: Fundamentos sobre los indices en SQL Server

14

Índices nonclustered con Heaps

• Referencias a Datos• Row IDentifier (RID)

Root

Int.

KeyRID

KeyRID

Int

KeyRID

KeyRID

Data2

Data3

Data4

Data5

Data6

Data7

Data1

INDEX

HEAP

Page 15: Fundamentos sobre los indices en SQL Server

Índices nonclustered con Clustered Index

• Referencia a Datos• Clustered Index KEY

15

Root

Int.

Keycl

key

Keycl

key

Int

Keycl

key

Keycl

key

INDEX

Root

Int.

Data Data

Int

Data Data

Clustered Index

Page 16: Fundamentos sobre los indices en SQL Server

16

DEMO: Índices nonclustered

Page 17: Fundamentos sobre los indices en SQL Server

17

Indices nonclustered de cobertura

• Posibilidad de incluir columnas en Índices• Acerca datos a los índices• Nodo Hoja

• Eficiencia vs. Espacio• Reduce Lookups

Root

Int.

KeyRef

COL1COL2

Int

KeyRef

COL1COL2

KeyRef

COL1COL2

KeyRef

COL1COL2

Page 18: Fundamentos sobre los indices en SQL Server

18

DEMO: Índices nonclustered de cobertura

Page 19: Fundamentos sobre los indices en SQL Server

19

Otros tipo de Índices

• Índices nonclustered (Filtrados)• Índices columnares (New 2012)• Hash (New 2014 / In-Memory OLTP)• Menos comunes• Índices XML• Índices espaciales (Spatial Indexes)• Full-Text

Page 20: Fundamentos sobre los indices en SQL Server

20

Conclusiones

• Índices son armas poderosas para acelerar consultas• Sigue las buenas practicas!!• Utiliza Clustered Index• Evitar sobre indexación• Evitar índices solapados

• Todo tiene un coste• Mantenimiento de índices con operaciones de escritura

Page 21: Fundamentos sobre los indices en SQL Server

21

¿Preguntas?

Blog: www.sqlserverpasion.comMail: [email protected]: @epuignouselles

Page 22: Fundamentos sobre los indices en SQL Server

22

Gracias

Blog: www.sqlserverpasion.comMail: [email protected]: @epuignouselles

Page 23: Fundamentos sobre los indices en SQL Server

23

Manténgase conectado a nosotros!

Visítenos en http://globalspanish.sqlpass.org

/SpanishPASSVC

lnkd.in/dtYBzev

/user/SpanishPASSVC

/SpanishPASSVC

Page 24: Fundamentos sobre los indices en SQL Server

PASS Community News

August 2014

Page 25: Fundamentos sobre los indices en SQL Server

Planning on attending PASS Summit 2014? Start saving today!

• The world’s largest gathering of SQL Server & BI professionals

• Take your SQL Server skills to the next level by learning from the world’s SQL Server experts, in 190+ technical sessions

• Over 5000 attendees, representing 2000 companies, from 52 countries, ready to network & learn

Ask your Chapter Leader how to save $150 off registration!

$1,895UNTIL SEPTEMBER

26, 2014

Page 26: Fundamentos sobre los indices en SQL Server

PASS Virtual Chapters ListingCheck out the sqlpass.org for more information on all the Virtual Chapters:

• Application Development• Big Data• Book Readers• Business Analytics• Business Intelligence• Cloud• Data Architecture• Database Administration• DBA Fundamentals• Excel BI• Healthcare• High Availability and Disaster Recovery• InMemory• Master Data\Data Quality

• Oracle SQL• Performance• Powershell • Professional

Development• Security• Virtualization• Women in Technology• Global Chinese• Global French• Global Hebrew• Global Italian• Global Portuguese• Global Russian• Global Spanish

Page 27: Fundamentos sobre los indices en SQL Server

Virtual Chapter Meetings – August

VIRTUAL CHAPTER

MEETING TOPIC

DBA Fundamentals

Aug 5 11:00– 12:00 CDT (UTC -05:00)

Rolling Upgraders, The Easy Way Presented by Argenis Fernandez

Global Spanish Aug 6 12:00-12:30 (UTC -05:00) Los Caso de Uso Para In-Memory OLTP Presented by Warner Chaves

Global Hebrew Aug 10 17:30-18:30 JDT (UTC +02:00)

Take Your SQL Server Development Process Forward! Presented by Itai Binyamin

Professional Development

Aug 12 12:00-13:00 EDT (UTC -04:00)

Bridging the Communication Gap Between DBA and Developer Presented by Robert Davis

High Availability and Disaster Recovery

Aug 12 12:00-13:00 CDT (UTC -05:00)

Mirroring Start to FinishPresented by Ryan Adams

Page 28: Fundamentos sobre los indices en SQL Server

Virtual Chapter Meetings – August

VIRTUAL CHAPTER

MEETING TOPIC

Global Spanish Aug 13 12:00-13:00 (UTC -05:00) Haciendo Preguntas Básicas en Power BIPresented by Andrei Garzon

Excel Business Intelligence

Aug 14 11:00-12:00 EDT (UTC-04:00)

Advanced Analytics: Excel SolverPresented by Dan Fylstra

Business Intelligence

Aug 14 11:00-12:00 EDT (UTC -04:00)

Continuous Integration for Reporting ServicesPresented by Nat Sundar

DBA Fundamentals Aug 19 11:00-12:00 CDT (UTC -05:00)

The Roadmap to Better Performance: Reading Query Plans Presented by Erin Stellato

Global Spanish Aug 20 12:00-12:30 (UTC -05:00) Fundamentos sobre lost indices end SQL Presented by Enrique Puig

Page 29: Fundamentos sobre los indices en SQL Server

Virtual Chapter Meetings – August

VIRTUAL CHAPTER

MEETING TOPIC

Global Russian Aug 20 15:00-16:30 (UTC +03:00)

SSIS - Повышение производительности обработки потоков данных

Global French Aug 21 20:00-21:00 RST (UTC +01:00)

Power BI Hybride avec la Passerelle de Gestion de Données Presented by Jean-Pierre Riehl

Business Analytics Aug 21 12:00-13:00 CDT (UTC -05:00)

Looking Through the Windshield: Creating forward-looking Dashboards and KPI’s Presented by Brian Larson

Business Intelligence

Aug 27 12:00-13:00 GMT (UTC-00:00)

Intro to RPresented by Stephanie Locke

Global Spanish Aug 27 12:00-13:00 (UTC-05:00) Visualización de Big Data Con Power ViewPresented by Eduardo Castro

Page 30: Fundamentos sobre los indices en SQL Server

Upcoming SQLSaturdays

Upcoming North America Events Upcoming International Events

• Aug 2 #324 Baton Rouge

• Aug 9 #304 Indianapolis

• Aug 23 #328 Birmingham

• Aug 23 #309 Oklahoma City

• Sep 6 #320 Raleigh

• Sep 13 #300 Kansas City

• Sep 20 #331 Denver

• Sept 20 # 340 San Diego

• Aug 30 #327 Johannesburg

• Aug 30 #317 Oslo

• Sep 6 #301 Cape Town

• Sep 13 # 323 Paris

• Sep 20 #290 Kiev

• Sep 20 #310 Dublin

• Sep 27 #325 Sao Paulo

Visit www.sqlsaturday.com to register for an event near you!

Page 31: Fundamentos sobre los indices en SQL Server

31

Volunteering with PASS

Volunteer Today!

Now it’s easier than ever to volunteer with PASS.

Let us know your volunteer preferences by updating the “myVolunteering” section of your

myPASS profile.

PASS would not exist without our passionate, dedicated, and hardworking volunteers from

around the globe.

Page 32: Fundamentos sobre los indices en SQL Server

32

Outstanding Volunteer Award

Do you know a volunteer that has gone above and beyond recently?

Nominate them for the monthly OVA.

[email protected]

Volunteering with PASS

PASSion Award

The highest of PASS accolades presented yearly to a volunteer. Nominations will open in August

2014.

Stay tuned!

Page 33: Fundamentos sobre los indices en SQL Server

Stay Involved!• Sign up for a free membership today at sqlpass.org

• Linked In: http://www.sqlpass.org/linkedin• Facebook: http://www.sqlpass.org/facebook• Twitter: @SQLPASS• PASS: http://www.sqlpass.org

Page 34: Fundamentos sobre los indices en SQL Server

Programa de Reconocimiento

Programa de Voluntario Sobresaliente

• PASS le invita a nominar a su voluntario favorito para ser “Voluntario Sobresaliente del Mes”

• Enviar nominaciones en todo momento a: [email protected] Favor proveer:• Información de contacto del nominado,• una lista breve de los programas de PASS que a participado el nominado• los años que lleva activo en la comunidad• una corta descripción por el cual considera que esta persona debe ser reconocida

• Los nominados seleccionados serán anunciados en la edición del boletín PASS Connector y recibirán un certificado de apreciación.

Page 35: Fundamentos sobre los indices en SQL Server

Visualización de Big Data con Power View

27 de Agosto (12 pm GMT -5)

Eduardo CastroResúmen:En esta sesión veremos ejemplos,de como realizar análisis de big data con PowerView integrato con HDInsight y HortonWorks.

Próximo Evento