SlideShare a Scribd company logo
1 of 16
Download to read offline
SQL Server
Statistics
Crafted for the love ♥ of SQL Server
http://www.sqlserverapp.com/
Dedicated to the DBA community
Distribution of data
http://www.sqlserverapp.com/
Distribution of data
When we have millions of rows in the tables, it really matters (to the database!) on how the
data is distributed. For example, it is useful to know that 35% of the employees (from the data in
an Employee table) work from France, 28% from Germany and so on.
Distribution of data really matters!
http://www.sqlserverapp.com/
Why does it matter so much?
So why is all this obsession about data distribution?!
Because only then SQL Server can optimize query execution.
Before it runs a query, SQL Server needs to ‘estimate’ how much of data is being fetched.
For example, ‘Is the query fetching about 10% of the data from the table?’
Or ‘Is it getting almost 90% of the data in the table?’
Based on this, the SQL Server Query Optimizer makes several choices on how to
execute the query.
Say, for example, it will decide whether or not to use a specific index during the execution.
http://www.sqlserverapp.com/
Introducing
Statistics
http://www.sqlserverapp.com/
SQL Server uses a really cool way to track data distribution.
And thats’s what we call
Statistics
Statistics … a crucial SQL technique
http://www.sqlserverapp.com/
sys.stats
is our hero here!
Not that you are going to look into its data much.
But worth getting a basic hang on it when you find some time
or during your coffee break!
DMV for Statistics
https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-stats-transact-sql
http://www.sqlserverapp.com/
Each Statistics object is created for one or more of the columns
in the tables and indexed views in SQL Server.
SQL Server maintains a histogram depicting the distribution of values.
Statistics objects
http://www.sqlserverapp.com/
Tidbit : What is a Histogram?
A Histogram groups data into ranges and helps display how much data is in each range.
When the automatic creation/updating of Statistics is enable in SQL Server, SQL Server takes a wise
call on whether it is really necessary to update the Statistics before a query is run.
It takes this call based on how much the data in the related tables have changed since the last Statistics
update.
When are they created?
http://www.sqlserverapp.com/
While the concept of Statistics is really cool, we need to keep in mind that it has a performance cost.
Having to maintain what distribution of data is present in every table and indexed view is not trivial.
While the need to keep the Statistics up-to-date is important, there is a question of how much up-to-
date it needs to be. Updating Statistics for, say, every insert/delete that happens in a table might be
way too costly. However, updating too less might also turn out bad because then queries will be
executed (i.e. query plans would be chosen by the Query Optimizer) using the old values in Statistics.
When are they created?
http://www.sqlserverapp.com/
http://www.sqlserverapp.com/
How much control do you have
over Statistics?
Yes!
But again, be wary of the performance implication in maintaining a Statistic object.
Can you create a Statistic object?
http://www.sqlserverapp.com/
This is possible too. You can run an update of the Statistics objects when you want.
You can use the Stored Procedure sp_updatestats
Updating Statistics at your will
http://www.sqlserverapp.com/
This is possible too. You can run an update of the Statistics objects when you want.
You can use the Stored Procedure sp_updatestats
Updating Statistics at your will
http://www.sqlserverapp.com/
Updating Statistics at your will
http://www.sqlserverapp.com/
Be wary that updating
Statistics will lead to
recompilation of your queries!
Happy
DBA’ing!
See you soon with another interesting SQL Server concept!
Until then …
Referenced from MSDN
iKosmik
http://www.sqlserverapp.com/
Follow us to get notified on SQL Server concepts and tidbits

More Related Content

What's hot

1b s4 i interpreting runcharts final
1b s4 i interpreting runcharts final  1b s4 i interpreting runcharts final
1b s4 i interpreting runcharts final ABCiABUHB
 
1a s4 i creating runcharts final
1a s4 i creating runcharts final1a s4 i creating runcharts final
1a s4 i creating runcharts finalABCiABUHB
 
Join 2017_Deep Dive_Table Calculations 201
Join 2017_Deep Dive_Table Calculations 201Join 2017_Deep Dive_Table Calculations 201
Join 2017_Deep Dive_Table Calculations 201Looker
 
Jaspersoft Studio Quick Start Guide
Jaspersoft Studio Quick Start GuideJaspersoft Studio Quick Start Guide
Jaspersoft Studio Quick Start GuideJeff Rix
 
Catalyst 2016: Distributing Data to Stakeholders, Share Reports, Distribution
Catalyst 2016: Distributing Data to Stakeholders, Share Reports, DistributionCatalyst 2016: Distributing Data to Stakeholders, Share Reports, Distribution
Catalyst 2016: Distributing Data to Stakeholders, Share Reports, DistributionEnergyCAP, Inc.
 
Migrating Monitoring to Observability – How to Transform DevOps from being Re...
Migrating Monitoring to Observability – How to Transform DevOps from being Re...Migrating Monitoring to Observability – How to Transform DevOps from being Re...
Migrating Monitoring to Observability – How to Transform DevOps from being Re...Liz Masters Lovelace
 
DataEngConf SF16 - Data Asserts: Defensive Data Science
DataEngConf SF16 - Data Asserts: Defensive Data ScienceDataEngConf SF16 - Data Asserts: Defensive Data Science
DataEngConf SF16 - Data Asserts: Defensive Data ScienceHakka Labs
 
Model Analyzer For Excel
Model Analyzer For ExcelModel Analyzer For Excel
Model Analyzer For ExcelYsrael Mertz
 

What's hot (10)

1b s4 i interpreting runcharts final
1b s4 i interpreting runcharts final  1b s4 i interpreting runcharts final
1b s4 i interpreting runcharts final
 
1a s4 i creating runcharts final
1a s4 i creating runcharts final1a s4 i creating runcharts final
1a s4 i creating runcharts final
 
Join 2017_Deep Dive_Table Calculations 201
Join 2017_Deep Dive_Table Calculations 201Join 2017_Deep Dive_Table Calculations 201
Join 2017_Deep Dive_Table Calculations 201
 
Jaspersoft Studio Quick Start Guide
Jaspersoft Studio Quick Start GuideJaspersoft Studio Quick Start Guide
Jaspersoft Studio Quick Start Guide
 
Catalyst 2016: Distributing Data to Stakeholders, Share Reports, Distribution
Catalyst 2016: Distributing Data to Stakeholders, Share Reports, DistributionCatalyst 2016: Distributing Data to Stakeholders, Share Reports, Distribution
Catalyst 2016: Distributing Data to Stakeholders, Share Reports, Distribution
 
Migrating Monitoring to Observability – How to Transform DevOps from being Re...
Migrating Monitoring to Observability – How to Transform DevOps from being Re...Migrating Monitoring to Observability – How to Transform DevOps from being Re...
Migrating Monitoring to Observability – How to Transform DevOps from being Re...
 
DataEngConf SF16 - Data Asserts: Defensive Data Science
DataEngConf SF16 - Data Asserts: Defensive Data ScienceDataEngConf SF16 - Data Asserts: Defensive Data Science
DataEngConf SF16 - Data Asserts: Defensive Data Science
 
Belajar spss
Belajar spssBelajar spss
Belajar spss
 
Model Analyzer For Excel
Model Analyzer For ExcelModel Analyzer For Excel
Model Analyzer For Excel
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 

Similar to Sql Server Statistics

Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016Antonios Chatzipavlis
 
SQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya BhatnagarSQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya Bhatnagarsammykb
 
Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenancenspyrenet
 
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Amanda Lam
 
Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...
Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...
Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...Spark Summit
 
Skills Portfolio
Skills PortfolioSkills Portfolio
Skills Portfoliorolee23
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's Newdpcobb
 
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and DatabricksSelf-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and DatabricksGrega Kespret
 
Sql Server 2005 Business Inteligence
Sql Server 2005 Business InteligenceSql Server 2005 Business Inteligence
Sql Server 2005 Business Inteligenceabercius24
 
Query Store and live Query Statistics
Query Store and live Query StatisticsQuery Store and live Query Statistics
Query Store and live Query StatisticsSolidQ
 
Advance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAdvance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAmin Uddin
 
Sql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scaleSql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scaleKlaudiia Jacome
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersAdam Hutson
 
Getting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise MonitorGetting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise MonitorMark Leith
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
Part2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsPart2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsMaria Colgan
 
SQL Server End Of Support
SQL Server End Of SupportSQL Server End Of Support
SQL Server End Of SupportMariano Kovo
 

Similar to Sql Server Statistics (20)

Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016
 
SQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya BhatnagarSQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya Bhatnagar
 
Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenance
 
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
 
Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...
Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...
Learnings Using Spark Streaming and DataFrames for Walmart Search: Spark Summ...
 
Msbi Architecture
Msbi ArchitectureMsbi Architecture
Msbi Architecture
 
Skills Portfolio
Skills PortfolioSkills Portfolio
Skills Portfolio
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
 
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and DatabricksSelf-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
 
Sql Server 2005 Business Inteligence
Sql Server 2005 Business InteligenceSql Server 2005 Business Inteligence
Sql Server 2005 Business Inteligence
 
Query Store and live Query Statistics
Query Store and live Query StatisticsQuery Store and live Query Statistics
Query Store and live Query Statistics
 
Advance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAdvance Sql Server Store procedure Presentation
Advance Sql Server Store procedure Presentation
 
Sql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scaleSql server 2008 r2 performance and scale
Sql server 2008 r2 performance and scale
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for Programmers
 
Getting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise MonitorGetting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise Monitor
 
Data_Warehouse_Concept.pptx
Data_Warehouse_Concept.pptxData_Warehouse_Concept.pptx
Data_Warehouse_Concept.pptx
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
Part2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsPart2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer Statistics
 
Tracing Sql Server 2005
Tracing Sql Server 2005Tracing Sql Server 2005
Tracing Sql Server 2005
 
SQL Server End Of Support
SQL Server End Of SupportSQL Server End Of Support
SQL Server End Of Support
 

Recently uploaded

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 
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...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Sql Server Statistics

  • 1. SQL Server Statistics Crafted for the love ♥ of SQL Server http://www.sqlserverapp.com/ Dedicated to the DBA community
  • 3. Distribution of data When we have millions of rows in the tables, it really matters (to the database!) on how the data is distributed. For example, it is useful to know that 35% of the employees (from the data in an Employee table) work from France, 28% from Germany and so on. Distribution of data really matters! http://www.sqlserverapp.com/
  • 4. Why does it matter so much? So why is all this obsession about data distribution?! Because only then SQL Server can optimize query execution. Before it runs a query, SQL Server needs to ‘estimate’ how much of data is being fetched. For example, ‘Is the query fetching about 10% of the data from the table?’ Or ‘Is it getting almost 90% of the data in the table?’ Based on this, the SQL Server Query Optimizer makes several choices on how to execute the query. Say, for example, it will decide whether or not to use a specific index during the execution. http://www.sqlserverapp.com/
  • 6. SQL Server uses a really cool way to track data distribution. And thats’s what we call Statistics Statistics … a crucial SQL technique http://www.sqlserverapp.com/
  • 7. sys.stats is our hero here! Not that you are going to look into its data much. But worth getting a basic hang on it when you find some time or during your coffee break! DMV for Statistics https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-stats-transact-sql http://www.sqlserverapp.com/
  • 8. Each Statistics object is created for one or more of the columns in the tables and indexed views in SQL Server. SQL Server maintains a histogram depicting the distribution of values. Statistics objects http://www.sqlserverapp.com/ Tidbit : What is a Histogram? A Histogram groups data into ranges and helps display how much data is in each range.
  • 9. When the automatic creation/updating of Statistics is enable in SQL Server, SQL Server takes a wise call on whether it is really necessary to update the Statistics before a query is run. It takes this call based on how much the data in the related tables have changed since the last Statistics update. When are they created? http://www.sqlserverapp.com/
  • 10. While the concept of Statistics is really cool, we need to keep in mind that it has a performance cost. Having to maintain what distribution of data is present in every table and indexed view is not trivial. While the need to keep the Statistics up-to-date is important, there is a question of how much up-to- date it needs to be. Updating Statistics for, say, every insert/delete that happens in a table might be way too costly. However, updating too less might also turn out bad because then queries will be executed (i.e. query plans would be chosen by the Query Optimizer) using the old values in Statistics. When are they created? http://www.sqlserverapp.com/
  • 11. http://www.sqlserverapp.com/ How much control do you have over Statistics?
  • 12. Yes! But again, be wary of the performance implication in maintaining a Statistic object. Can you create a Statistic object? http://www.sqlserverapp.com/
  • 13. This is possible too. You can run an update of the Statistics objects when you want. You can use the Stored Procedure sp_updatestats Updating Statistics at your will http://www.sqlserverapp.com/
  • 14. This is possible too. You can run an update of the Statistics objects when you want. You can use the Stored Procedure sp_updatestats Updating Statistics at your will http://www.sqlserverapp.com/
  • 15. Updating Statistics at your will http://www.sqlserverapp.com/ Be wary that updating Statistics will lead to recompilation of your queries!
  • 16. Happy DBA’ing! See you soon with another interesting SQL Server concept! Until then … Referenced from MSDN iKosmik http://www.sqlserverapp.com/ Follow us to get notified on SQL Server concepts and tidbits