SlideShare a Scribd company logo
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 final
ABCiABUHB
 
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
Looker
 
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, Distribution
EnergyCAP, 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 Science
Hakka Labs
 
Belajar spss
Belajar spssBelajar spss
Belajar spss
Riwanda Novan
 
Model Analyzer For Excel
Model Analyzer For ExcelModel Analyzer For Excel
Model Analyzer For Excel
Ysrael Mertz
 
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
Vibrant Technologies & Computers
 

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 2016
Antonios 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 & maintenance
nspyrenet
 
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 Portfolio
rolee23
 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
dpcobb
 
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
Grega Kespret
 
Sql Server 2005 Business Inteligence
Sql Server 2005 Business InteligenceSql Server 2005 Business Inteligence
Sql Server 2005 Business Inteligence
abercius24
 
Query Store and live Query Statistics
Query Store and live Query StatisticsQuery Store and live Query Statistics
Query Store and live Query Statistics
SolidQ
 
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 Programmers
Adam Hutson
 
Getting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise MonitorGetting to Know MySQL Enterprise Monitor
Getting to Know MySQL Enterprise Monitor
Mark Leith
 
Data_Warehouse_Concept.pptx
Data_Warehouse_Concept.pptxData_Warehouse_Concept.pptx
Data_Warehouse_Concept.pptx
Kanchana Weerasinghe
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
rainynovember12
 
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
Maria Colgan
 
SQL Server End Of Support
SQL Server End Of SupportSQL Server End Of Support
SQL Server End Of Support
Mariano 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

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

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