SlideShare a Scribd company logo
1 of 20
Cardinality Estimator en SQL Server 2014. ¿Qué es? Y
cómo nos beneficia?
11 de Marzo 2015 (12 pm GMT -5)
Percy Reyes
Resumen:
En esta sesión revisaremos de que se trata el
CE en SQL Server 2014, cómo nos beneficia,
y consideraciones a tomar en cuanto en una
migración a esta versión.
Está por comenzar:
Próximos Eventos
Configuración y casos de uso para
AlwaysON availability groups
readable secondaries
1 de Abril
Kenneth Ureña
Creando una solución Always On
SQL Server 2014 Híbrida
18 de Marzo
Miguel Escobar
Power Query y el Lenguaje M
25 de Marzo
German Cayo
Moderador: José L. Rivera
Manténgase conectado a nosotros!
Visítenos en http://globalspanish.sqlpass.org
/SpanishPASSVC
lnkd.in/dtYBzev
/user/SpanishPASSVC
/SpanishPASSVC
4
5
Oportunidades de Voluntariado
PASS no pudiera existir sin personas apasionadas y
dedicadas de todas partes del mundo que dan de su
tiempo como voluntarios.
Se un voluntario ahora!!
Para identificar oportunidades locales visita
volunteer.sqlpass.org
Recuerda actualizar tu perfil en las secciones de
“MyVolunteering” y MyPASS para mas detalles.
Sigan Participando!
• Obtén tu membresía gratuita en sqlpass.org
• Linked In: http://www.sqlpass.org/linkedin
• Facebook: http://www.sqlpass.org/facebook
• Twitter: @SQLPASS
• PASS: http://www.sqlpass.org
Cardinality Estimator en SQL Server 2014.
¿Qué es? Y cómo nos beneficia?
11 de Marzo de 2015
Percy Reyes
Microsoft SQL Server MVP
Sr. SQL DBA with over 10 years
Author at MSSQLTips.com | SQL PASS Peru Chapter Leader
MCITP DBA, MCITP Dev, MCTS, MCP
www.percyreyes.com
Moderador: José L. Rivera
Agenda
What inputs is used by the Query Optimizer
What is CE?
The importance of CE
New deployments vs upgrade
Validating a Query’s Cardinality Estimator Version
Why can query plans change with the new CE?
How to control new cardinality estimator
Recommendations
Guidelines on query performance troubleshooting with new CE
What inputs is used by the Query Optimizer
- The SQL Query and/or Stored Procedure
- If the query or stored procedure is parameterized, then the value of the parameters
- Knowledge about the index structures of table(s) to be accessed
- Statistics of index(es) and columns of the table(s) to be accessed
- Hints assigned to the query
- Global max degree of parallelism setting
- Hardware Settings (How many CPUs, How much RAM, Disk Subsystem configuration)
What is CE?
- Cardinality estimations are predictions of final row count and row counts of intermediate results (such as joins, filtering and aggregation. The
component which does cardinality estimation is called Cardinality Estimator (CE) .
- Prior to SQL Server 2014, cardinality estimator was largely based on SQL Server 7.0 code base.
- The cardinality Estimator has been redesigned.
The importance of CE
- Under estimating rows can lead to:
- The selection of serial plan when parallelism would have been more optimal.
- Inappropriate join strategies.
- Inefficient index selection and navigation strategies.
- Memory spills to disk, for example, where not enough memory was requested for sort or
hash operations
- Inversely, over estimating rows can lead to:
- Selection of a parallel plan when a serial plan might be more optimal.
- Inappropriate join strategy selection.
- Inefficient index navigation strategies (scan versus seek).
- Inflated memory grants.
- Wasted memory and unnecessarily throttled concurrency.
So, improving the accuracy of row estimates can improve the quality of the query execution
plan and, as a result, improve the performance of the query.
New deployments vs upgrade
- SQL Server 2014 uses database compatibility level to determine if new cardinality estimator
will be used
- You will continue to use old cardinality estimator in upgrade and restore situations by
default unless you have manually changed the compatibility level to be 120.
- You will use cardinality estimator based on current database under the query is compiled
(even though the query references temp table)
- Regarding upgrade of system databases:
- model, msdb and tempdb will be changed to 120
- master system database retains the compatibility level it had before upgrade
Validating a Query’s Cardinality Estimator Version
In the SQL 2014 XML plan, check the new attribute in StmtSimple called CardinalityEstimationModelVersion
- Capturing a new SQL Server 2014 XEvent called query_optimizer_estimate_cardinality
Why can query plans change with the new CE?
1. The new CE is calculating combined filter density/selectivity differently
The way how the CE calculates the selectivity of a combination of filters submitted with a query
- With Old CE:
- Treating the selectivity/density of each filter/column independently
- Old calculation formula: d1 * d2* d3* d4* … dn
- Row Estimated=# Total of rows / (1/combined density)
- With NEW CE:
- Combinations of values of different columns are not as independent.
- New CE works based on a new calculation formula to calculate combined density of filters.
- The NEW calculation formula now would d1 * d2^(1/2) * d3^(1/4) * d4^(1/8)
- Row Estimated=# Total of rows / (1/combined density)
Why can query plans change with the new CE?
2. The new CE is treating ascending/descending key scenarios differently
What if we would add a new value out of the range values of an statistics?
- An update statistics with FULLSCAN was performed and after a new value is added, which would be
out of the range of the column statistics, then the new CE would estimate 1 row. The same behavior is
for old CE.
- An update statistics performed in the default sampling and after a new value is added, which would
be out of the range of the column statistics, then the new CE also will now report an estimate of
around 1000 rows. The old CE would estimate 1 row.
- An update statistics performed in the default sampling or with FULLSCAN and after several NEW
values are added, which would be out of the range of the column statistics, then the new CE also will
now report an estimate of around 1000 rows.
IMPORTANT: The # of rows estimated which are found outside the boundaries of the statistics will
be majorly impacted by the # of values and their occurrence in the column according to the
statistics.
- What if we would add a new value within the range values of an statistics?
- The behavior here is not too much different between the old and the new CE
- The new as well as the old CE would return an estimate of 1 row only
How to control new cardinality estimator
Trace flag at query level
- You use QUERYTRACEON hint
- Example: SELECT* FROM Product where ProductId= 4672 OPTION(QUERYTRACEON 2312)
Trace flags at server level
- Flag 2312 is used to force new cardinality estimator
- Flag 9481 is used to force old cardinality estimator
- If you enable both trace flags, neither will be used. Instead, database compatibility level will determine
which version of cardinality estimator to be used
Trace flag at database level
- Via database compatibility level
Order of Precedente
Recommendations
- Before changing to the new CE in production, test all critical workloads using representative data in a
production-like environment.
- If you cannot change or fully test the existing application, you can still migrate to SQL Server 2014.
However, the database compatibility level should remain below 120 until you can perform thorough
testing.
- To leverage new SQL Server 2014 features without activating the new CE, change to the latest database
compatibility level and enable trace flag 9481 at the server level. Use DBCC TRACEON with the -1
argument to enable the trace flag globally. As an alternative, you can use the –T startup option to enable
the trace flag during SQL Server startup.
- If creating a new database for a new application, use database compatibility level 120 by default.
Guidelines on query performance troubleshooting
with new CE
- Statistics
- Make sure you enable auto update and auto create statistics for the database
- If you have large tables, you may need to schedule jobs to manually update statistics.
- Tune your indexes
- XML Plan will display missing index warning for a query
- Missing index DMVs
- Database Tuning Advisor (DTA) can be used to help you tune a specific query
- Analyze the execution plans to detect and fix any index performance issue
- Constructs not significantly addressed by the new cardinality estimator
- Table variables. You will continue to get low estimate (1) for table variables.
- Multi-statement table valued function (TVF): Multi-statement TVF will continue to get estimate of
100 instead of 1 in earlier version. But this can still cause issues if your TVF returns many rows.
- Behaviors of Table valued parameter (TVP) and local variables are unchanged. The number of rows
of TVP at compile time will be used for cardinality estimate regardless if the rows will change for
future executions. Local variables will continued to be optimized for unknown.
Thank You: Q&A
PERCY REYES
• Twitter: @percyreyes
• Blog: mssqlinternals.com
• percy.reyes@live.com
• Website: www.percyreyes.com
sqlpassperu.com
Power Query y el Lenguaje M
18 de Marzo (12 pm GMT -5)
Miguel Escobar
Resúmen:
Power Query es una nueva herramienta de la familia Power BI que se
encarga del proceso de extracción y transformación de datos. Ha sido
catalogada como una de las mejores herramientas para Excel en salir al
mercado por parte de Microsoft en los últimos años y en esta sesión
conocerás muchas razones por las cuales te encantará.
Próximo Evento

More Related Content

Similar to Cardinality estimator en sql server 2014. qué es y cómo nos beneficia

Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Antonios Chatzipavlis
 
Modernizing SQL Server the Right Way
Modernizing SQL Server the Right WayModernizing SQL Server the Right Way
Modernizing SQL Server the Right WayJuan Fabian
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersAdam Hutson
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersShehap Elnagar
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersShehap Elnagar
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersShehap Elnagar
 
Sql 2012 Upgrade Readiness Guide
Sql 2012 Upgrade Readiness GuideSql 2012 Upgrade Readiness Guide
Sql 2012 Upgrade Readiness GuidePARIKSHIT SAVJANI
 
Geek Sync | New Features in SQL Server That Will Change the Way You Tune
Geek Sync | New Features in SQL Server That Will Change the Way You TuneGeek Sync | New Features in SQL Server That Will Change the Way You Tune
Geek Sync | New Features in SQL Server That Will Change the Way You TuneIDERA Software
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's Newdpcobb
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Best Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon RedshiftBest Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon RedshiftSnapLogic
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2kaashiv1
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2kaashiv1
 
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSINGSKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSINGSkillwise Group
 

Similar to Cardinality estimator en sql server 2014. qué es y cómo nos beneficia (20)

Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
 
Modernizing SQL Server the Right Way
Modernizing SQL Server the Right WayModernizing SQL Server the Right Way
Modernizing SQL Server the Right Way
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
AIRflow at Scale
AIRflow at ScaleAIRflow at Scale
AIRflow at Scale
 
Statistics
StatisticsStatistics
Statistics
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for Programmers
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powers
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powers
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powers
 
Sql 2012 Upgrade Readiness Guide
Sql 2012 Upgrade Readiness GuideSql 2012 Upgrade Readiness Guide
Sql 2012 Upgrade Readiness Guide
 
Sql Server Statistics
Sql Server StatisticsSql Server Statistics
Sql Server Statistics
 
Geek Sync | New Features in SQL Server That Will Change the Way You Tune
Geek Sync | New Features in SQL Server That Will Change the Way You TuneGeek Sync | New Features in SQL Server That Will Change the Way You Tune
Geek Sync | New Features in SQL Server That Will Change the Way You Tune
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns
 
Best Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon RedshiftBest Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon Redshift
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2
 
Ebook2
Ebook2Ebook2
Ebook2
 
Sql interview question part 2
Sql interview question part 2Sql interview question part 2
Sql interview question part 2
 
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSINGSKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
 

More from SpanishPASSVC

Creación de un modelo de análisis predictivo en la nube
Creación de un modelo de análisis predictivo en la nubeCreación de un modelo de análisis predictivo en la nube
Creación de un modelo de análisis predictivo en la nubeSpanishPASSVC
 
Analizando la performance del subsistema de IO
Analizando la performance del subsistema de IOAnalizando la performance del subsistema de IO
Analizando la performance del subsistema de IOSpanishPASSVC
 
AlwaysON Lecciones Aprendidas
AlwaysON Lecciones AprendidasAlwaysON Lecciones Aprendidas
AlwaysON Lecciones AprendidasSpanishPASSVC
 
Data Science con Microsoft R Server y SQL Server 2016
Data Science con Microsoft R Server y SQL Server 2016Data Science con Microsoft R Server y SQL Server 2016
Data Science con Microsoft R Server y SQL Server 2016SpanishPASSVC
 
Mejoras de Rendimiento para Replicación Transaccional
Mejoras de Rendimiento para Replicación TransaccionalMejoras de Rendimiento para Replicación Transaccional
Mejoras de Rendimiento para Replicación TransaccionalSpanishPASSVC
 
Como leer planes de ejecución
Como leer planes de ejecuciónComo leer planes de ejecución
Como leer planes de ejecuciónSpanishPASSVC
 
AlwaysOn en SQL Server 2016
AlwaysOn en SQL Server 2016AlwaysOn en SQL Server 2016
AlwaysOn en SQL Server 2016SpanishPASSVC
 
VMs de alto rendimiento para SQL Server en AWS y Azure
VMs de alto rendimiento para SQL Server en AWS y AzureVMs de alto rendimiento para SQL Server en AWS y Azure
VMs de alto rendimiento para SQL Server en AWS y AzureSpanishPASSVC
 
Tecnicas avanzadas de monitoreo
Tecnicas avanzadas de monitoreoTecnicas avanzadas de monitoreo
Tecnicas avanzadas de monitoreoSpanishPASSVC
 
Principios de diseño para procesos de ETL
Principios de diseño para procesos de ETLPrincipios de diseño para procesos de ETL
Principios de diseño para procesos de ETLSpanishPASSVC
 
Planeando e implementando servicios de datos con Microsoft Azure
Planeando e implementando servicios de datos con Microsoft AzurePlaneando e implementando servicios de datos con Microsoft Azure
Planeando e implementando servicios de datos con Microsoft AzureSpanishPASSVC
 
Mejores prácticas para SQL Server en ambientes virtualizados
Mejores prácticas para SQL Server en ambientes virtualizadosMejores prácticas para SQL Server en ambientes virtualizados
Mejores prácticas para SQL Server en ambientes virtualizadosSpanishPASSVC
 
Mejores prácticas de Data Warehouse con SQL Server
Mejores prácticas de Data Warehouse con SQL ServerMejores prácticas de Data Warehouse con SQL Server
Mejores prácticas de Data Warehouse con SQL ServerSpanishPASSVC
 
La receta de la abuela para mejores cargas de datos
La receta de la abuela para mejores cargas de datosLa receta de la abuela para mejores cargas de datos
La receta de la abuela para mejores cargas de datosSpanishPASSVC
 
Introducción a Azure Machine Learning
Introducción a Azure Machine LearningIntroducción a Azure Machine Learning
Introducción a Azure Machine LearningSpanishPASSVC
 
Cuadros de mando el todo es más que la suma de las partes
Cuadros de mando el todo es más que la suma de las partesCuadros de mando el todo es más que la suma de las partes
Cuadros de mando el todo es más que la suma de las partesSpanishPASSVC
 
Automatizando la generación de Datawarehouses a través de metadatos
Automatizando la generación de Datawarehouses a través de metadatosAutomatizando la generación de Datawarehouses a través de metadatos
Automatizando la generación de Datawarehouses a través de metadatosSpanishPASSVC
 
Descubriendo el corazón de la optimización “Estadísticas más que un concepto”
Descubriendo el corazón de la optimización “Estadísticas más que un concepto”Descubriendo el corazón de la optimización “Estadísticas más que un concepto”
Descubriendo el corazón de la optimización “Estadísticas más que un concepto”SpanishPASSVC
 
Administrando soluciones de Power BI
Administrando soluciones de Power BIAdministrando soluciones de Power BI
Administrando soluciones de Power BISpanishPASSVC
 
Vista 360 grados de DataZen - Juan Alvarado
Vista 360 grados de DataZen - Juan AlvaradoVista 360 grados de DataZen - Juan Alvarado
Vista 360 grados de DataZen - Juan AlvaradoSpanishPASSVC
 

More from SpanishPASSVC (20)

Creación de un modelo de análisis predictivo en la nube
Creación de un modelo de análisis predictivo en la nubeCreación de un modelo de análisis predictivo en la nube
Creación de un modelo de análisis predictivo en la nube
 
Analizando la performance del subsistema de IO
Analizando la performance del subsistema de IOAnalizando la performance del subsistema de IO
Analizando la performance del subsistema de IO
 
AlwaysON Lecciones Aprendidas
AlwaysON Lecciones AprendidasAlwaysON Lecciones Aprendidas
AlwaysON Lecciones Aprendidas
 
Data Science con Microsoft R Server y SQL Server 2016
Data Science con Microsoft R Server y SQL Server 2016Data Science con Microsoft R Server y SQL Server 2016
Data Science con Microsoft R Server y SQL Server 2016
 
Mejoras de Rendimiento para Replicación Transaccional
Mejoras de Rendimiento para Replicación TransaccionalMejoras de Rendimiento para Replicación Transaccional
Mejoras de Rendimiento para Replicación Transaccional
 
Como leer planes de ejecución
Como leer planes de ejecuciónComo leer planes de ejecución
Como leer planes de ejecución
 
AlwaysOn en SQL Server 2016
AlwaysOn en SQL Server 2016AlwaysOn en SQL Server 2016
AlwaysOn en SQL Server 2016
 
VMs de alto rendimiento para SQL Server en AWS y Azure
VMs de alto rendimiento para SQL Server en AWS y AzureVMs de alto rendimiento para SQL Server en AWS y Azure
VMs de alto rendimiento para SQL Server en AWS y Azure
 
Tecnicas avanzadas de monitoreo
Tecnicas avanzadas de monitoreoTecnicas avanzadas de monitoreo
Tecnicas avanzadas de monitoreo
 
Principios de diseño para procesos de ETL
Principios de diseño para procesos de ETLPrincipios de diseño para procesos de ETL
Principios de diseño para procesos de ETL
 
Planeando e implementando servicios de datos con Microsoft Azure
Planeando e implementando servicios de datos con Microsoft AzurePlaneando e implementando servicios de datos con Microsoft Azure
Planeando e implementando servicios de datos con Microsoft Azure
 
Mejores prácticas para SQL Server en ambientes virtualizados
Mejores prácticas para SQL Server en ambientes virtualizadosMejores prácticas para SQL Server en ambientes virtualizados
Mejores prácticas para SQL Server en ambientes virtualizados
 
Mejores prácticas de Data Warehouse con SQL Server
Mejores prácticas de Data Warehouse con SQL ServerMejores prácticas de Data Warehouse con SQL Server
Mejores prácticas de Data Warehouse con SQL Server
 
La receta de la abuela para mejores cargas de datos
La receta de la abuela para mejores cargas de datosLa receta de la abuela para mejores cargas de datos
La receta de la abuela para mejores cargas de datos
 
Introducción a Azure Machine Learning
Introducción a Azure Machine LearningIntroducción a Azure Machine Learning
Introducción a Azure Machine Learning
 
Cuadros de mando el todo es más que la suma de las partes
Cuadros de mando el todo es más que la suma de las partesCuadros de mando el todo es más que la suma de las partes
Cuadros de mando el todo es más que la suma de las partes
 
Automatizando la generación de Datawarehouses a través de metadatos
Automatizando la generación de Datawarehouses a través de metadatosAutomatizando la generación de Datawarehouses a través de metadatos
Automatizando la generación de Datawarehouses a través de metadatos
 
Descubriendo el corazón de la optimización “Estadísticas más que un concepto”
Descubriendo el corazón de la optimización “Estadísticas más que un concepto”Descubriendo el corazón de la optimización “Estadísticas más que un concepto”
Descubriendo el corazón de la optimización “Estadísticas más que un concepto”
 
Administrando soluciones de Power BI
Administrando soluciones de Power BIAdministrando soluciones de Power BI
Administrando soluciones de Power BI
 
Vista 360 grados de DataZen - Juan Alvarado
Vista 360 grados de DataZen - Juan AlvaradoVista 360 grados de DataZen - Juan Alvarado
Vista 360 grados de DataZen - Juan Alvarado
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Cardinality estimator en sql server 2014. qué es y cómo nos beneficia

  • 1. Cardinality Estimator en SQL Server 2014. ¿Qué es? Y cómo nos beneficia? 11 de Marzo 2015 (12 pm GMT -5) Percy Reyes Resumen: En esta sesión revisaremos de que se trata el CE en SQL Server 2014, cómo nos beneficia, y consideraciones a tomar en cuanto en una migración a esta versión. Está por comenzar: Próximos Eventos Configuración y casos de uso para AlwaysON availability groups readable secondaries 1 de Abril Kenneth Ureña Creando una solución Always On SQL Server 2014 Híbrida 18 de Marzo Miguel Escobar Power Query y el Lenguaje M 25 de Marzo German Cayo Moderador: José L. Rivera
  • 2. Manténgase conectado a nosotros! Visítenos en http://globalspanish.sqlpass.org /SpanishPASSVC lnkd.in/dtYBzev /user/SpanishPASSVC /SpanishPASSVC
  • 3.
  • 4. 4
  • 5. 5 Oportunidades de Voluntariado PASS no pudiera existir sin personas apasionadas y dedicadas de todas partes del mundo que dan de su tiempo como voluntarios. Se un voluntario ahora!! Para identificar oportunidades locales visita volunteer.sqlpass.org Recuerda actualizar tu perfil en las secciones de “MyVolunteering” y MyPASS para mas detalles.
  • 6. Sigan Participando! • Obtén tu membresía gratuita en sqlpass.org • Linked In: http://www.sqlpass.org/linkedin • Facebook: http://www.sqlpass.org/facebook • Twitter: @SQLPASS • PASS: http://www.sqlpass.org
  • 7. Cardinality Estimator en SQL Server 2014. ¿Qué es? Y cómo nos beneficia? 11 de Marzo de 2015 Percy Reyes Microsoft SQL Server MVP Sr. SQL DBA with over 10 years Author at MSSQLTips.com | SQL PASS Peru Chapter Leader MCITP DBA, MCITP Dev, MCTS, MCP www.percyreyes.com Moderador: José L. Rivera
  • 8. Agenda What inputs is used by the Query Optimizer What is CE? The importance of CE New deployments vs upgrade Validating a Query’s Cardinality Estimator Version Why can query plans change with the new CE? How to control new cardinality estimator Recommendations Guidelines on query performance troubleshooting with new CE
  • 9. What inputs is used by the Query Optimizer - The SQL Query and/or Stored Procedure - If the query or stored procedure is parameterized, then the value of the parameters - Knowledge about the index structures of table(s) to be accessed - Statistics of index(es) and columns of the table(s) to be accessed - Hints assigned to the query - Global max degree of parallelism setting - Hardware Settings (How many CPUs, How much RAM, Disk Subsystem configuration)
  • 10. What is CE? - Cardinality estimations are predictions of final row count and row counts of intermediate results (such as joins, filtering and aggregation. The component which does cardinality estimation is called Cardinality Estimator (CE) . - Prior to SQL Server 2014, cardinality estimator was largely based on SQL Server 7.0 code base. - The cardinality Estimator has been redesigned.
  • 11. The importance of CE - Under estimating rows can lead to: - The selection of serial plan when parallelism would have been more optimal. - Inappropriate join strategies. - Inefficient index selection and navigation strategies. - Memory spills to disk, for example, where not enough memory was requested for sort or hash operations - Inversely, over estimating rows can lead to: - Selection of a parallel plan when a serial plan might be more optimal. - Inappropriate join strategy selection. - Inefficient index navigation strategies (scan versus seek). - Inflated memory grants. - Wasted memory and unnecessarily throttled concurrency. So, improving the accuracy of row estimates can improve the quality of the query execution plan and, as a result, improve the performance of the query.
  • 12. New deployments vs upgrade - SQL Server 2014 uses database compatibility level to determine if new cardinality estimator will be used - You will continue to use old cardinality estimator in upgrade and restore situations by default unless you have manually changed the compatibility level to be 120. - You will use cardinality estimator based on current database under the query is compiled (even though the query references temp table) - Regarding upgrade of system databases: - model, msdb and tempdb will be changed to 120 - master system database retains the compatibility level it had before upgrade
  • 13. Validating a Query’s Cardinality Estimator Version In the SQL 2014 XML plan, check the new attribute in StmtSimple called CardinalityEstimationModelVersion - Capturing a new SQL Server 2014 XEvent called query_optimizer_estimate_cardinality
  • 14. Why can query plans change with the new CE? 1. The new CE is calculating combined filter density/selectivity differently The way how the CE calculates the selectivity of a combination of filters submitted with a query - With Old CE: - Treating the selectivity/density of each filter/column independently - Old calculation formula: d1 * d2* d3* d4* … dn - Row Estimated=# Total of rows / (1/combined density) - With NEW CE: - Combinations of values of different columns are not as independent. - New CE works based on a new calculation formula to calculate combined density of filters. - The NEW calculation formula now would d1 * d2^(1/2) * d3^(1/4) * d4^(1/8) - Row Estimated=# Total of rows / (1/combined density)
  • 15. Why can query plans change with the new CE? 2. The new CE is treating ascending/descending key scenarios differently What if we would add a new value out of the range values of an statistics? - An update statistics with FULLSCAN was performed and after a new value is added, which would be out of the range of the column statistics, then the new CE would estimate 1 row. The same behavior is for old CE. - An update statistics performed in the default sampling and after a new value is added, which would be out of the range of the column statistics, then the new CE also will now report an estimate of around 1000 rows. The old CE would estimate 1 row. - An update statistics performed in the default sampling or with FULLSCAN and after several NEW values are added, which would be out of the range of the column statistics, then the new CE also will now report an estimate of around 1000 rows. IMPORTANT: The # of rows estimated which are found outside the boundaries of the statistics will be majorly impacted by the # of values and their occurrence in the column according to the statistics. - What if we would add a new value within the range values of an statistics? - The behavior here is not too much different between the old and the new CE - The new as well as the old CE would return an estimate of 1 row only
  • 16. How to control new cardinality estimator Trace flag at query level - You use QUERYTRACEON hint - Example: SELECT* FROM Product where ProductId= 4672 OPTION(QUERYTRACEON 2312) Trace flags at server level - Flag 2312 is used to force new cardinality estimator - Flag 9481 is used to force old cardinality estimator - If you enable both trace flags, neither will be used. Instead, database compatibility level will determine which version of cardinality estimator to be used Trace flag at database level - Via database compatibility level Order of Precedente
  • 17. Recommendations - Before changing to the new CE in production, test all critical workloads using representative data in a production-like environment. - If you cannot change or fully test the existing application, you can still migrate to SQL Server 2014. However, the database compatibility level should remain below 120 until you can perform thorough testing. - To leverage new SQL Server 2014 features without activating the new CE, change to the latest database compatibility level and enable trace flag 9481 at the server level. Use DBCC TRACEON with the -1 argument to enable the trace flag globally. As an alternative, you can use the –T startup option to enable the trace flag during SQL Server startup. - If creating a new database for a new application, use database compatibility level 120 by default.
  • 18. Guidelines on query performance troubleshooting with new CE - Statistics - Make sure you enable auto update and auto create statistics for the database - If you have large tables, you may need to schedule jobs to manually update statistics. - Tune your indexes - XML Plan will display missing index warning for a query - Missing index DMVs - Database Tuning Advisor (DTA) can be used to help you tune a specific query - Analyze the execution plans to detect and fix any index performance issue - Constructs not significantly addressed by the new cardinality estimator - Table variables. You will continue to get low estimate (1) for table variables. - Multi-statement table valued function (TVF): Multi-statement TVF will continue to get estimate of 100 instead of 1 in earlier version. But this can still cause issues if your TVF returns many rows. - Behaviors of Table valued parameter (TVP) and local variables are unchanged. The number of rows of TVP at compile time will be used for cardinality estimate regardless if the rows will change for future executions. Local variables will continued to be optimized for unknown.
  • 19. Thank You: Q&A PERCY REYES • Twitter: @percyreyes • Blog: mssqlinternals.com • percy.reyes@live.com • Website: www.percyreyes.com sqlpassperu.com
  • 20. Power Query y el Lenguaje M 18 de Marzo (12 pm GMT -5) Miguel Escobar Resúmen: Power Query es una nueva herramienta de la familia Power BI que se encarga del proceso de extracción y transformación de datos. Ha sido catalogada como una de las mejores herramientas para Excel en salir al mercado por parte de Microsoft en los últimos años y en esta sesión conocerás muchas razones por las cuales te encantará. Próximo Evento

Editor's Notes

  1. Course 6231A