Module 3: Creating and Tuning Indexes. Planning Indexes Creating Indexes Optimizing Indexes.

Slides:



Advertisements
Similar presentations
Microsoft Dynamics® AX 2012
Advertisements

Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Denny Cherry Manager of Information Systems MVP, MCSA, MCDBA, MCTS, MCITP.
Module 4: Joining Data from Multiple Tables. Querying Multiple Tables by Using Joins Applying Joins for Typical Reporting Needs Combining and Limiting.
Module 2: Database Architecture
SQL Server Storage Engine.  Software architect at Red Gate Software  Responsible for SQL tools: ◦ SQL Compare, SQL Data Compare, SQL Packager ◦ SQL.
Module 8 Importing and Exporting Data. Module Overview Transferring Data To/From SQL Server Importing & Exporting Table Data Inserting Data in Bulk.
Module 12: Auditing SQL Server Environments
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
Module 2 Designing a Logical Database Model. Module Overview Guidelines for Building a Logical Database Model Planning for OLTP Activity Evaluating Logical.
SQL Server 2005 features for VLDBs. SQL Server 2005 features for VLDBs aka (it’s fixed in the next release)
Tables Lesson 6. Skills Matrix Tables Tables store data. Tables are relational –They store data organized as row and columns. –Data can be retrieved.
Working with SQL Server Database Objects
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
Physical Database Design CIT alternate keys - named constraints - indexes.
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.
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
Denny Cherry twitter.com/mrdenny.
Module 8 Improving Performance through Nonclustered Indexes.
With Michelle Ufford.  Sr. DBA for GoDaddy.com  Working with SQL for 6 years, focused on performance tuning and VLDB’s  Member of the PASS Performance.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Module 19 Managing Multiple Servers. Module Overview Working with Multiple Servers Virtualizing SQL Server Deploying and Upgrading Data-Tier Applications.
Module 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Module 14 Configuring Security for SQL Server Agent.
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
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
Module 4 Designing and Implementing Views. Module Overview Introduction to Views Creating and Managing Views Performance Considerations for Views.
Denny Cherry twitter.com/mrdenny.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Indexes and Views Unit 7.
Module 11 Authorizing Users to Access Resources. Module Overview Authorizing User Access to Objects Authorizing Users to Execute Code Configuring Permissions.
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.
SQLintersection Putting the "Squeeze" on Large Tables Improve Performance and Save Space with Data Compression Justin Randall Tuesday,
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.
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
Session 1 Module 1: Introduction to Data Integrity
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.
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.
Module 9: Using Advanced Techniques. Considerations for Querying Data Working with Data Types Cursors and Set-Based Queries Dynamic SQL Maintaining Query.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Indexes Part 2 What type of Indexes are there? Make sure you have the pages 2 & 3 of the Lab for Indexes in front of you before playing this presentation.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
SQL Basics Review Reviewing what we’ve learned so far…….
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Chris Index Feng Shui Chris
Module 2: Creating Data Types and Tables
Data Definition and Data Types
Finding more space for your tight environment
Module 4: Creating and Tuning Indexes
Designing Database Solutions for SQL Server
Module 7: Implementing Views
Module 5: Implementing Data Integrity by Using Constraints
Table Indexing for the .NET Developer
Indexes: The Basics Kathi Kellenberger.
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Database systems Lecture 6 – Indexes
Indexing For Optimal Performance
SQL Server Indexing for the Client Developer
Presentation transcript:

Module 3: Creating and Tuning Indexes

Planning Indexes Creating Indexes Optimizing Indexes

Lesson 1: Planning Indexes How SQL Server Accesses Data What Is a Heap? What Is a Clustered Index? What Is a Nonclustered Index?

How SQL Server Accesses Data Index SQL Server reads all table pages SQL Server uses index pages to find rows Table Scan SQL Server 2008 introduces enhanced full-text indexing

What Is a Heap? A table without a clustered index Pages stored in no particular order Heap idindex_id=0first_iam_page IAM Page Data Pages

What Is a Clustered Index? One clustered index per table B-tree stores data pages in order of index key Leaf Nodes idindex_id=1root_page Data Pages Intermediate Level Intermediate Level Index Pages Root Index Page

What Is a Nonclustered Index? B-tree references underlying heap or clustered index Up to 249 nonclustered indexes per table Heap or Clustered Index Heap or Clustered Index idindex_id>1root_page Data Pages Leaf Nodes Index Pages Root Index Page

Lesson 2: Creating Indexes Overview of Creating Indexes What Are Unique Indexes? Considerations for Creating Indexes with Multiple Columns When to Create Indexes on Computed Columns What Are Partitioned Indexes? Options for Incorporating Free Space in Indexes Methods for Obtaining Index Information

Overview of Creating Indexes CREATE [UNIQUE] [CLUSTERED | NONCLUSTERED ] INDEX index_name ON { table | view } ( column [ ASC | DESC] [,... n ] ) INCLUDE ( column [,... n ] ) [ WITH option [,... n ] ] [ ON { partition_scheme (column) | filegroup | default } ] Use SQL Server Management Studio -OR- CREATE INDEX Transact-SQL statement

What Are Unique Indexes? CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_LoginID] ON [HumanResources].[Employee] ( [LoginID] ASC ) EmployeeIDLoginIDGenderMaritalStatus… 216mike0MS… 231fukiko0MM… 242pat0MS… 291pat0FS… … Duplicate key value not allowed

Included columns Considerations for Creating Indexes with Multiple Columns Composite indexes Define most unique column first Include up to 16 columns and 900 bytes in key Nonkey columns included in index CREATE NONCLUSTERED INDEX AK_Employee_LoginID ON HumanResources.Employee ( LoginID ASC) INCLUDE ( ContactID, NationalIDNumber ) CREATE NONCLUSTERED INDEX K_Contact_LastName_First Name ON Peson.Contact ( LastName ASC, FirstName ASC ) Improve query coverage and performance

When to Create Indexes on Computed Columns You can create indexes on computed columns when: NUMERIC_ROUNDABORT option is set to OFF The expression is deterministic and precise ANSI_NULLS connection_level option is ON Column does not evaluate to text, ntext or image data types Required options are set to ON when index is created and when changes cause index to update Query optimizer might ignore an index on a computed column

Index is partitioned horizontally by range similar to a partitioned table What Are Partitioned Indexes? Consider aligning with underlying table and inclusion of partitioning in index key (unique) < > 2005 idindex_idpartition_numberhobt_id ………… sys.partitions

Options for Incorporating Free Space in Indexes Free space affects index update performance FILLFACTOR determines amount of free space on leaf nodes Use low FILLFACTOR for OLTP applications Use high FILLFACTOR for OLAP applications PAD_INDEX determines amount of free space on non-leaf index nodes CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_LoginID] ON [HumanResources].[Employee] ([LoginID] ASC) WITH FILLFACTOR = 65, PAD_INDEX = ON)

Methods for Obtaining Index Information SQL Server Management Studio: Object Explorer Index Properties window System stored procedures: sp_help Catalog Views System functions Reports sp_helpindex

Demonstration: Creating Indexes In this demonstration, you will see how to: Create an index by using SQL Server Management Studio Examine an index by using SQL Server Management Studio Create an index by using Transact-SQL

Lesson 3: Optimizing Indexes What Is the Database Engine Tuning Advisor? Index Fragmentation Options for Defragmenting Indexes

What Is the Database Engine Tuning Advisor? Analyzes database performance under workload Graphical and command-line interfaces Reports and Recommendations Workload Database Engine Tuning Advisor Database and Database Objects

Demonstration: Using the Database Engine Tuning Advisor In this demonstration, you will see how to: Use a Transact-SQL script to analyze indexes in AdventureWorks Review the index recommendations

Index Fragmentation How does fragmentation occur? SQL Server reorganizes index pages when data is modified – causes index pages to split SQL Server Management Studio – Index Properties System function - sys.dm_db_index_physical_stats Detecting fragmentation Internal – pages are not full External – pages are out of logical sequence Types of fragmentation:

Options for Defragmenting Indexes Reorganize Less than 30% fragmentation Greater than 30% fragmentation ALTER INDEX AK_Product_Name ON Production.Product REORGANIZE Rebuild ALTER INDEX AK_Product_Name ON Production.Product REBUILD

Demonstration: Defragmenting Indexes In this demonstration, you will see how to: Identify fragmented indexes Remove fragmentation by rebuilding the index

Lab: Creating and Optimizing Indexes Exercise 1: Creating Indexes Exercise 2: Optimizing Indexes Logon information Virtual machineNY-SQL-01 User nameAdministrator Password Pa$$w0rd Estimated time: 45 minutes

Lab Scenario The Production department at Adventure Works has spent the last six months reviewing its processes and application support requirements. Out of this review have come a number of issues that need immediate attention and a number of new initiatives. As each initiative is started, the impact it will have on the database and any new requirements it introduces are discussed with the senior database developer and an appropriate course of action is agreed on.

Lab Review In SQL Server Management Studio, how do you view the index properties of a table? What does the option Fillfactor = 90 do when creating an index? When you check the fragmentation properties on the AK_Product_Name index after addressing the fragmentation, the fragmentation level is only reduced by 5%. What did you do wrong?

Module Review and Takeaways Review Questions Best Practices and Troubleshooting Tools