SlideShare a Scribd company logo
1 of 16
SQL Server 2014
Cardinality Estimator
Gianluca Sartori
gianluca.sartori@sqlconsulting.it
PILLS SPONSORS
Gianluca Sartori
•Independent SQL Server consultant
•Works with SQL Server since version 7
•MCTS, MCITP, MCT
•DBA @ Formula 1 team
Blog:
Twitter:

spaghettidba.com
@spaghettidba
Cardinality Estimator
SQL Server 2014 include un nuovo Cardinality Estimator
I piani di esecuzione saranno compilati usando il nuovo
CE
Nuovi algoritmi di calcolo dalla cardinalità
Cos’è il Cardinality Estimator?
Componente centrale del Query Processor
Ha il compito di stimare la cardinalità degli insiemi di
righe che soddisfano uno o più predicati
Le stime di cardinalità sono utilizzate dall’optimizer per
produrre i piani di esecuzione
Le stime si basano sulle statistiche
Perché un nuovo Cardinality
Estimator?
Il vecchio CE è stato scritto per SQL Server 7
Codice vecchio di 15 anni!
Molte nuove feature
Molte modifiche
Complessità elevata
Difficile da manutenere

 Conveniente una riscrittura completa
Come si attiva il nuovo CE?
Per attivare il nuovo CE:
ALTER DATABASE AdventureWorks2012 SET COMPATIBILITY_LEVEL = 120;
--oppure
DBCC TRACEON(2312);

Per disattivare il nuovo CE:
ALTER DATABASE AdventureWorks2012 SET COMPATIBILITY_LEVEL = 110;
--oppure

DBCC TRACEON(9481);
Perché disattivare il nuovo CE?
Molti algoritmi sono cambiati
Codice complesso
Possibilità di regressione
Nuovi bug
Correzione di bug che nascondono altri bug

Compatibility 110 consente di mantenere il
comportamento precedente
Come funziona il CE?
Interroga le statistiche per stimare il numero di righe
DBCC SHOW_STATISTICS (
'Sales.SalesOrderHeader',
'OrderDate')

WITH HISTOGRAM;
Come funziona il CE?
SELECT *
FROM Sales.SalesOrderHeader
WHERE OrderDate = '2007-01-01'
Predicati multipli
Exponential Backoff
Cardinality Estimator
Colonne Ascendenti
Colonne ascendenti  manca un valore nell’istogramma
per le righe appena inserite
TF 2389 e 2390 forzano l’interrogazione del valore
Massimo
Con il nuovo CE non è più necessario usare i TF
Sono già attivi di default
Cardinality Estimator
Nelle prossime puntate…
Extending the Buffer Pool with Solid-State Drives
Grazie!
Trovi altri video su:
www.ugiss.org/sql-server-2014pills

More Related Content

Viewers also liked

The Tipping Point - Final Presentation
The Tipping Point - Final PresentationThe Tipping Point - Final Presentation
The Tipping Point - Final PresentationCamilh
 
Why do you want to study international management
Why do you want to study international managementWhy do you want to study international management
Why do you want to study international managementJen Vuhuong
 
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?Gianluca Sartori
 
[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014
[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014
[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014Jen Vuhuong
 

Viewers also liked (7)

Pregunta de investigacion
Pregunta  de  investigacionPregunta  de  investigacion
Pregunta de investigacion
 
The Tipping Point - Final Presentation
The Tipping Point - Final PresentationThe Tipping Point - Final Presentation
The Tipping Point - Final Presentation
 
6 Summer Projects You'll Love
6 Summer Projects You'll Love6 Summer Projects You'll Love
6 Summer Projects You'll Love
 
Why do you want to study international management
Why do you want to study international managementWhy do you want to study international management
Why do you want to study international management
 
Learn software development
Learn software developmentLearn software development
Learn software development
 
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?
 
[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014
[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014
[Jennifer vuhuong]Social innovation^The case of MyBnk^24032014
 

More from Gianluca Sartori

SQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesSQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesGianluca Sartori
 
Responding to extended events in near real time
Responding to extended events in near real timeResponding to extended events in near real time
Responding to extended events in near real timeGianluca Sartori
 
Sql server security in an insecure world
Sql server security in an insecure worldSql server security in an insecure world
Sql server security in an insecure worldGianluca Sartori
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - ENGianluca Sartori
 
TSQL Advanced Query Techniques
TSQL Advanced Query TechniquesTSQL Advanced Query Techniques
TSQL Advanced Query TechniquesGianluca Sartori
 
SQL Server Benchmarking, Baselining and Workload Analysis
SQL Server Benchmarking, Baselining and Workload AnalysisSQL Server Benchmarking, Baselining and Workload Analysis
SQL Server Benchmarking, Baselining and Workload AnalysisGianluca Sartori
 
A performance tuning methodology
A performance tuning methodologyA performance tuning methodology
A performance tuning methodologyGianluca Sartori
 
SQL Server Worst Practices
SQL Server Worst PracticesSQL Server Worst Practices
SQL Server Worst PracticesGianluca Sartori
 

More from Gianluca Sartori (10)

Benchmarking like a pro
Benchmarking like a proBenchmarking like a pro
Benchmarking like a pro
 
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
 
SQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesSQL Server 2016 New Security Features
SQL Server 2016 New Security Features
 
Responding to extended events in near real time
Responding to extended events in near real timeResponding to extended events in near real time
Responding to extended events in near real time
 
Sql server security in an insecure world
Sql server security in an insecure worldSql server security in an insecure world
Sql server security in an insecure world
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
 
TSQL Advanced Query Techniques
TSQL Advanced Query TechniquesTSQL Advanced Query Techniques
TSQL Advanced Query Techniques
 
SQL Server Benchmarking, Baselining and Workload Analysis
SQL Server Benchmarking, Baselining and Workload AnalysisSQL Server Benchmarking, Baselining and Workload Analysis
SQL Server Benchmarking, Baselining and Workload Analysis
 
A performance tuning methodology
A performance tuning methodologyA performance tuning methodology
A performance tuning methodology
 
SQL Server Worst Practices
SQL Server Worst PracticesSQL Server Worst Practices
SQL Server Worst Practices
 

SQL Server 2014 - Il nuovo Cardinality Estimator

  • 1. SQL Server 2014 Cardinality Estimator Gianluca Sartori gianluca.sartori@sqlconsulting.it
  • 3. Gianluca Sartori •Independent SQL Server consultant •Works with SQL Server since version 7 •MCTS, MCITP, MCT •DBA @ Formula 1 team Blog: Twitter: spaghettidba.com @spaghettidba
  • 4. Cardinality Estimator SQL Server 2014 include un nuovo Cardinality Estimator I piani di esecuzione saranno compilati usando il nuovo CE Nuovi algoritmi di calcolo dalla cardinalità
  • 5. Cos’è il Cardinality Estimator? Componente centrale del Query Processor Ha il compito di stimare la cardinalità degli insiemi di righe che soddisfano uno o più predicati Le stime di cardinalità sono utilizzate dall’optimizer per produrre i piani di esecuzione Le stime si basano sulle statistiche
  • 6. Perché un nuovo Cardinality Estimator? Il vecchio CE è stato scritto per SQL Server 7 Codice vecchio di 15 anni! Molte nuove feature Molte modifiche Complessità elevata Difficile da manutenere  Conveniente una riscrittura completa
  • 7. Come si attiva il nuovo CE? Per attivare il nuovo CE: ALTER DATABASE AdventureWorks2012 SET COMPATIBILITY_LEVEL = 120; --oppure DBCC TRACEON(2312); Per disattivare il nuovo CE: ALTER DATABASE AdventureWorks2012 SET COMPATIBILITY_LEVEL = 110; --oppure DBCC TRACEON(9481);
  • 8. Perché disattivare il nuovo CE? Molti algoritmi sono cambiati Codice complesso Possibilità di regressione Nuovi bug Correzione di bug che nascondono altri bug Compatibility 110 consente di mantenere il comportamento precedente
  • 9. Come funziona il CE? Interroga le statistiche per stimare il numero di righe DBCC SHOW_STATISTICS ( 'Sales.SalesOrderHeader', 'OrderDate') WITH HISTOGRAM;
  • 10. Come funziona il CE? SELECT * FROM Sales.SalesOrderHeader WHERE OrderDate = '2007-01-01'
  • 14. Colonne Ascendenti Colonne ascendenti  manca un valore nell’istogramma per le righe appena inserite TF 2389 e 2390 forzano l’interrogazione del valore Massimo Con il nuovo CE non è più necessario usare i TF Sono già attivi di default
  • 15. Cardinality Estimator Nelle prossime puntate… Extending the Buffer Pool with Solid-State Drives
  • 16. Grazie! Trovi altri video su: www.ugiss.org/sql-server-2014pills