query store

24
##SQLSatMadrid Query Store Enrique Catala Bañuls MVP , Mentor at SolidQ | [email protected] | [email protected] | @enriquecatala | www.enriquecatala.com

Upload: enrique-catala-banuls

Post on 09-Jan-2017

81 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Query store

##SQLSatMadrid

Query Store

Enrique Catala BañulsMVP , Mentor at SolidQ

| [email protected]

| [email protected]

| @enriquecatala

| www.enriquecatala.com

Page 2: Query store

##SQLSatMadrid

BIG Thanks to SQLSatMadrid Sponsors

Page 3: Query store

##SQLSatMadrid

4 Sponsor Sessions at 11:40

Don’t miss them, they might be getting distributing some awesome prizes!

HPE

SolidQ

KABEL

TSD Consulting

Also BIG Raffle prizes at the end of the event provided by:

Plainconcepts, SolidQ, Kabel, TSD Consulting, Pyramid Analytics & sqlpass.es

Page 4: Query store

##SQLSatMadrid

Enrique Catalá Bañuls

Ingeniero Informático

Microsoft Data Platform MVP

Mentor en SolidQ

Tuning y alta disponibilidad

[email protected] | www.solidq.com

@enriquecatala | www.enriquecatala.com

Page 5: Query store

##SQLSatMadrid

Contenido de la sesión

Live Query Statistics (LQS)

Query Store

Page 6: Query store

##SQLSatMadrid

El infierno del DBA

La aplicaciónno responde

Rendimientoaleatorio

Problemasde regresion

Page 7: Query store

##SQLSatMadrid

Live Query Statistics (LQS)

Identificación rápida

de cuellos de botella

Ver en tiempo real

Filas/sec

Tiempo consumido

Progreso de

operador

Warnings

Page 8: Query store

##SQLSatMadrid

Live Query Statistics (LQS)

DMVs sys.dm_exec_requests

sys.dm_exec_sql_text

sys.dm_exec_query_memory_grants

sys.dm_exec_query_plan

sys.dm_exec_query_profiles

Activación SET STATISTICS XML ON | SET STATISTICS

PROFILE ON

Xevents capturando query_post_execution_showplan

Page 9: Query store

##SQLSatMadrid

Demo

Live Query Statistics

Page 10: Query store

##SQLSatMadrid

Live Query Statistics

Limitaciones

Tiene que ser activado previa ejecución de la

query

No se soportan procedimientos almacenados

compilados nativos

Requiere

SHOWPLAN para ver la pestaña resultados

VIEW SERVER STATE para ver estadísticas live

Page 11: Query store

##SQLSatMadrid

El infierno del DBA

La aplicaciónno responde

Rendimientoaleatorio

Problemasde regresion

Page 12: Query store

##SQLSatMadrid

Regresión de rendimiento

El optimizador utiliza dos tipos de clave

Conforme los parámetros cambian, el plan de

ejecución óptimo puede ser otro

Y si lo estima

incorrectamente?

Page 13: Query store

##SQLSatMadrid

Query Store: ¿Por qué?

Problemas

• Tiempodetecciónincidencias

• Tiemporesolución del problema

Soluciones

• Información de rendimientohistorico

• Forzar plan anterior mediante GUI

Page 14: Query store

##SQLSatMadrid

Query Store: Cómo funciona

Texto de consulta

Métricas de rendimiento

Historificado por tiempo

Permite forzado de planes

Configuracionde recolecciónDurability latency controlled by DB

option

DATA_FLUSH_INTERNAL_SECONDS

Query Store

Async write-back

Compile

Execute

SQL

Plan store

Runtime stats

Query

Store

schema

Compile MSG

Execute MSG

Async write-back

Query Store

Page 15: Query store

##SQLSatMadrid

Query Store: Cómo funciona

Existe en

plan caché?

Compilar y optimizar

query

Ejecucion query

Fin de ejecución

NO

Ejecutar query

Necesario

recompilar?

NO

Query Store

Obtener plan de caché

SI

SI

Enviar texto y plan

Nuevo plan forzado

Obtener plan forzado

Page 16: Query store

##SQLSatMadrid

Query Store: Almacenamiento

Captura de datos en memoria para minimizar E/S

Persistencia de datos asíncrona en background

Query execution Query Store

async

Compile

Execute

Query Store plan store

Runtimestats store

Internal

tables

Query text and plan

Query execute stats

Page 17: Query store

##SQLSatMadrid

Query Store: Lectura

Vistas de mezcla entre datos in-memory y on-disk

Los usuarios siempre ven el “ultimo” dato

Query execution Query Store

async

Compile

Execute

Query Store plan store

Runtimestats store

Internal

tables

Query text and plan

Query execute stats

Query Store views (TVF)

Page 18: Query store

##SQLSatMadrid

Query Store: Tracking

Tablas internas

Query text

Query PlanRuntime

stats1 -n1 -n

Context settings

sys.

Compile stats

query_store_query_text

query_context_settings

query_store_query

query_store_plan

Runtime statsquery_store_runtime_stats_inter

val

query_store_runtime_stats

Vistas expuestas

One row per query text, per plan affecting option(example: ANSI NULLS on/off)

One row per plan (for each query)

Runtime stats interval

One row per plan, per time interval (example: 5 min)

Page 19: Query store

##SQLSatMadrid

Query Store: configuraciones

Operation mode [OFF | READ_ONLY | READ_WRITE] Actual | Requested (status)

Data flush interval (minutes)

Statistics Collection Interval (minutes)

Max Size (MB)

Capture Mode [None | ALL | AUTO]

Stale Query Threshold (Days)

Purge Query Data

Page 20: Query store

##SQLSatMadrid

Demo

Query Store

Page 21: Query store

##SQLSatMadrid

Query Store: Uso típico

Activar Query Store

(ALTER DB)

Captura de datos por

Query Store

Buscar“patrónes

problemáticos”

AplicarFORCE PLAN

Page 22: Query store

##SQLSatMadrid

Query Store: Uso típico

Queries con regresión de rendimiento

Queries con regresión de rendimiento en

período de tiempo

Queries con mayor coste en un período de

tiempo

Coste de compilación de queries

Forzar plan de ejecución

Page 23: Query store

##SQLSatMadrid

Encontrar y arreglarproblemas de regresión

Identificarqueries “pesadas”

Realizaranálisis en profundidadde cargas de trabajo

Reducirriesgos ante migraciones

Largo plazo/estratégicoCorto plazo/táctico

Query Store: Repaso

Page 24: Query store

##SQLSatMadrid

[email protected]

www.solidq.com

@enriquecatala

www.enriquecatala.com