Managing and Maintaining Indexes and Statistics. Table Fragmentation Causes 1 Massive Updates or deletes 2 Frequent Page Splitting 3 Disk space contention.

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

Module 3: Creating and Tuning Indexes. Planning Indexes Creating Indexes Optimizing Indexes.
Big Data Working with Terabytes in SQL Server Andrew Novick
Quiz 2 Review. For which of the following attributes would a hash- index most likely be a better fit than a B+-tree index? A. Social Security Number B.
SQL Server 2005 Implementation and Maintenance Chapter 10: Maintaining and Automating SQL Server.
Working with SQL Server Database Objects
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
Database Optimization & Maintenance Tim Richard ECM Training Conference#dbwestECM Agenda SQL Configuration OnBase DB Planning Backups Integrity.
Physical Database Design CIT alternate keys - named constraints - indexes.
SQL Server Storage and Index Structures Physical Data Organization Indexes B-Trees SQL Server Data Access Clustered and Non-Clustered Creating, Altering,
Indexes Rose-Hulman Institute of Technology Curt Clifton.
Module 7: Creating and Maintaining Indexes. Overview Creating Indexes Creating Index Options Maintaining Indexes Introduction to Statistics Querying the.
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
CS27510 Commercial Database Applications. Maintenance Maintenance Disaster Recovery Disaster Recovery.
Denny Cherry twitter.com/mrdenny.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
Module 8 Improving Performance through Nonclustered Indexes.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Chapter 6 Additional Database Objects
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
SQL Server Indexes Indexes. Overview Indexes are used to help speed search results in a database. A careful use of indexes can greatly improve search.
Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
Module 16: Performing Ongoing Database Maintenance
© Pearson Education Limited, Chapter 13 Physical Database Design – Step 4 (Choose File Organizations and Indexes) Transparencies.
Effective Indexes For Beginners. Performance is slow Let’s add another index!
Physical Database Design The last phase of database design. It is to determine how to store the database. RDBMSs usually support a number of alternative.
1 Tree Indexing (1) Linear index is poor for insertion/deletion. Tree index can efficiently support all desired operations: –Insert/delete –Multiple search.
Incremental Index Maintenance A Solution “That Just Works” AL NOEL PRINCIPAL CONSULTANT, MICROSOFT
Denny Cherry twitter.com/mrdenny.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Maciej Pilecki | Project Botticelli Ltd.. SELECT Bio FROM Speakers WHERE FullName=‘Maciej Pilecki’;  Microsoft Certified Trainer since 2001  SQL Server.
SQL SERVER DAYS 2011 Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
Chapter 4 Indexes. Index Architecture  By default data is inserted on a first-come, first-serve basis  Indexes bring order to this chaos  Once you.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
Maintenance Practices. Goal  Automate the necessary DBA chores to put organizations on the path of having healthier, consistent and more trustworthy.
SQL Query Analyzer. Graphical tool that allows you to:  Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)
Indexing Fundamentals Steve Hood SimpleSQLServer.com.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
SQL SERVER MAINTENANCE PLANS Kat
October 15-18, 2013 Charlotte, NC SQL Server Index Internals Tim Chapman Premier Field Engineer.
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
Brent Ozar SQL Server Expert Quest Software SESSION CODE: DAT316.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
You Inherited a Database Now What? What you should immediately check and start monitoring for. Tim Radney, Senior DBA for a top 40 US Bank President of.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Chris Index Feng Shui Chris
Indexing and hashing.
Finding more space for your tight environment
Module 4: Creating and Tuning Indexes
Designing Database Solutions for SQL Server
Why Should I Care About … Partitioned Views?
Why Should I Care About … Partitioned Views?
Table Indexing for the .NET Developer
Why Should I Care About … Partitioned Views?
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Why Should I Care About … Partitioned Views?
Database systems Lecture 6 – Indexes
Why Should I Care About … Partitioned Views?
Why Should I Care About … Partitioned Views?
Using Columnstore indexes in Azure DevOps Services. Lessons learned.
Presentation transcript:

Managing and Maintaining Indexes and Statistics

Table Fragmentation Causes 1 Massive Updates or deletes 2 Frequent Page Splitting 3 Disk space contention 4 Insert Statements if Clustered Key is not a sequential key

How to Check Index Fragmentation use AdventureWorks2012 GO Select DB_NAME(ips.database_id) DBname, OBJECT_NAME(ips.object_id) ObjName, i.name InxName, ips.avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats(db_id(‘AdventureWorks2012'), default, default, default, default) ips INNER JOIN sys.indexes i ONips.index_id = i.index_id AND ips.object_id = i.object_id WHERE ips.object_id > 99 AND ips.avg_fragmentation_in_percent >= 10 AND ips.index_id > 0

REBUILD OR REORGANIZE? It is suggested that if fragmentation is between 10% and 30% a Reorganization might be called for and beneficial. If fragmentation is > 30% most likely a rebuild is necessary. If fragmentation is < 10%, it probably is not too consequential

Methods to Reorganize an Index SQL Server Manager allows 3 Methods to Reorganize an Index 1.SQL Server Management Studio (SSMS) – on the fly 2.T-SQL 3.A Maintenance Plan During Index Reorganization the following Activities take place 1.Index pages of the index are compacted 2.The leaf level is reordered to match the logical order of the leaf nodes in the index B-tree

Reorganize an Index T-SQL USE [AdventureWorks2012] GO ALTER INDEX [IX_SalesOrderHeader_OrderDate] on [Sales].[SalesOrderHeader] REORGANIZE Always an online operation

Methods to Rebuild an Index SQL Server Manager allows 2 Methods to Rebuild an Index 1.SQL Server Management Studio (SSMS) – on the fly 2.T-SQL During Rebuilding an Index the following activities take place 1.Disk space is reclaimed because the pages are compacted 2.The index rows are reordered 3.Fragmentation is removed

Rebuild an Index T-SQL USE [AdventureWorks2012] GO ALTER INDEX [IX_SalesOrderHeader_OrderDate] On [Sales].[SalesOrderHeader] REBUILD WITH (ONLINE = ON) - only with SQL Enterprise 2012 Always an offline operation

How to Check Index Usage USE AdventureWorks2012 SELECT DB_NAME(ius.database_id) DBName, OBJECT_NAME(ius.object_id) ObjName, i.name, ius.user_seeks, ius.user_scans, ius.user_lookups, ius.user_updates FROM sys.dm_db_index_usage_stats ius INNER JOIN sys.indexes i ON ius.object_id = i.object_id and ius.index_id = i.index_id WHERE DB_NAME(ius.database_id) = ‘ ‘ ‘AdventureWorks2012'

DATABASE STATISTICS DATABASE STATISTICS are carried both at the Database Level and also at the Table Level. Typically maintained automatically, they can also be maintained manually Database Statistics are updated either thru SSMS or thru T-SQL

UPDATING DATABASE STATISTICS T-SQL 2 Different Programs are available to update Database Statistics 1.UPDATE STATISTICS 2.Sp_updatestats Here is an example of both programs in use USE AdventureWorks2012 GO --Update all statistics within the AdventureWorks2012 database EXEC sp_updatestats GO --update all statistics for a given index on the specified table UPDATE STATISTICS [Sales].[SalesOrderHeader] [IX_SalesOrderHeader_OrderDate]