Module 5 Planning for SQL Server® 2008 R2 Indexing.

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.
Module 8 Importing and Exporting Data. Module Overview Transferring Data To/From SQL Server Importing & Exporting Table Data Inserting Data in Bulk.
© IBM Corporation Informix Chat with the Labs John F. Miller III Unlocking the Mysteries Behind Update Statistics STSM.
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
Quick Review of Apr 10 material B+-Tree File Organization –similar to B+-tree index –leaf nodes store records, not pointers to records stored in an original.
Working with SQL Server Database Objects
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Introduction to Structured Query Language (SQL)
Chapter 6: Database Evolution Title: AutoAdmin “What-if” Index Analysis Utility Authors: Surajit Chaudhuri, Vivek Narasayya ACM SIGMOD 1998.
Database management concepts Database Management Systems (DBMS) An example of a database (relational) Database schema (e.g. relational) Data independence.
File Organizations March 2007R McFadyen ACS In SQL Server 2000 Tree terms root, internal, leaf, subtree parent, child, sibling balanced, unbalanced.
1 Indexing Structures for Files. 2 Basic Concepts  Indexing mechanisms used to speed up access to desired data without having to scan entire.
Introduction to Structured Query Language (SQL)
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
Module 17 Storing XML Data in SQL Server® 2008 R2.
Module 18 Monitoring SQL Server 2008 R2. Module Overview Monitoring Activity Capturing and Managing Performance Data Analyzing Collected Performance Data.
Module 2 Working with Data Types. Module Overview Using Data Types Working with Character Data Converting Data Types Working with Specialized Data Types.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
Module 8 Improving Performance through Nonclustered Indexes.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
Module 19 Managing Multiple Servers. Module Overview Working with Multiple Servers Virtualizing SQL Server Deploying and Upgrading Data-Tier Applications.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
1 CPS216: Advanced Database Systems Notes 04: Operators for Data Access Shivnath Babu.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
Module 3 Designing a Physical Database Model. Module Overview Selecting Data Types Designing Database Tables Designing Data Integrity.
DBMS Implementation Chapter 6.4 V3.0 Napier University Dr Gordon Russell.
Module 16: Performing Ongoing Database Maintenance
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
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.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
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.
1 Multi-Level Indexing and B-Trees. 2 Statement of the Problem When indexes grow too large they have to be stored on secondary storage. However, there.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Module 1 Introduction to SQL Server® 2008 R2 and its Toolset.
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.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
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.
 CONACT UC:  Magnific training   
APRIL 13 th Introduction About me Duško Mirković 7 years of experience.
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.
Standards and Conventions
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.
Creating Database Objects
CPS216: Data-intensive Computing Systems
Indexes By Adrienne Watt.
Indexing Structures for Files and Physical Database Design
Module 2: Creating Data Types and Tables
Module 4: Creating and Tuning Indexes
COMP 430 Intro. to Database Systems
Indexing and Hashing Basic Concepts Ordered Indices
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Relational Database Design
Indexes and Performance
Creating Database Objects
Presentation transcript:

Module 5 Planning for SQL Server® 2008 R2 Indexing

Module Overview Core Indexing Concepts Data Types and Indexes Single Column and Composite Indexes

Lesson 1: Core Indexing Concepts How SQL Server Accesses Data The Need for Indexes Index Structures Selectivity, Density and Index Depth Index Fragmentation Demonstration 1A: Viewing Index Fragmentation

How SQL Server Accesses Data Index SQL Server reads all table pages SQL Server uses index pages to find rows Table Scan

The Need for Indexes ANSI SQL does not mention indexes  Generally considered to be external to the logical data model All queries can be executed without indexes  Primary reason for indexes is performance Some constraints are implemented via indexes  Indexes are used to make constraints efficient but in theory could be implemented in other ways Analogy: Physical library holding books  Index by author is useful  Additional indexes would also be useful

Index Structures Indexes are commonly based on tree structures  Not just a binary tree as nodes can have more than two children Top node is called the root node Bottom level nodes are called leaf nodes

Selectivity, Density and Index Depth Three core concepts when working with indexes Selectivity  A measure of how many rows are returned compared to the total number of rows  High selectivity means a small number of rows when related to the total number of rows Density  A measure of the lack of uniqueness of data in the table  High density indicates a large number of duplicates Index Depth  Number of levels within the index  Common misconception that indexes are deep

Index Fragmentation How does fragmentation occur? SQL Server reorganizes index pages when data modifications cause 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:

Demonstration 1A: Viewing Index Fragmentation In this demonstration, you will see how to identify fragmented indexes

Lesson 2: Data Types and Indexes Numeric Index Data Character Index Data Date-Related Index Data GUID Index Data BIT Index Data Indexing Computed Columns

Numeric Index Data Indexes with numeric keys work efficiently  Many values fit in a small number of index pages  Sorts and comparisons are quick Exact numeric types are most efficient  Integer types are the most efficient  INT and BIGINT commonly used Approximate data types (float and real) much less efficient

Character Index Data Character data types are much less efficient when used in index keys Character values tend to be much larger than numeric values Even short character values are slow to compare unless binary comparisons are being made  Most SQL Server applications use collations other than binary  Rules for collations need to be applied whenever comparisons are made

Date-Related Index Data Date data types are generally good candidates for index keys  Very commonly used in business applications Only slightly less efficient than integer data Size of the data will be important  date more efficient than datetime

GUID Index Data Becoming very common in new business applications Moderate efficiency  Size is 128 bits or 16 bytes  Comparison performance is reasonable Problems arise  Randomness of generation causes fragmentation problems  Very common problem in many current applications

BIT Index Data BIT columns have only two possible values BIT columns are efficient as index keys Common misconception that BIT columns are not useful in indexes  Many valid usage scenarios exist  Filtered indexes often useful with BIT column indexes

Indexing Computed Columns Computed columns are based on expressions  Values are typically derived from other columns Indexing the computed value rather than any underlying values can be useful  Can assist with improving performance on poorly-designed databases  Example: a column that is used to hold values that should have been held in separate columns Persisted computed columns  Avoid the overhead of computing values each time they are selected  Are computed during INSERT and UPDATE statements

Lesson 3: Single Column and Composite Indexes Single Column vs. Composite Indexes Ascending vs. Descending Indexes Index Statistics Demonstration 3A: Viewing Index Statistics

Single Column vs. Composite Indexes Indexes are not always constructed on a single column  Multi-column indexes are called "composite" indexes Composite indexes are often useful  Tend to be more useful than single column indexes in most typical business applications  Having an index sorted first by customer then by order date makes it very easy to find orders for a particular customer on a particular date.  A query might involve multiple search predicates.  Two columns together might be selective while neither is selective on its own. Index on A,B is not the same as an index on B,A  Typically index the most restrictive column first

Ascending vs. Descending Indexes Indexes could be constructed in ascending or descending order In general, for single column indexes, both are equally useful  Each layer of a SQL Server index is double-linked (ie: linked in both directions)  SQL Server can start at either end and work towards the other end Each component of a composite index can be ascending or descending  Might be very useful for avoiding sort operations

Index Statistics SQL Server needs to have knowledge of the layout of the data in a table or index before it optimizes and executes queries  Needs to create a reasonable plan for executing the query  Important to know the usefulness of each index  Selectivity is the most important metric By default, SQL Server automatically creates statistics on indexes  Can be disabled  Recommendation is to leave auto-creation and auto-update enabled

Demonstration 3A: Viewing Index Statistics In this demonstration, you will see how to work with index statistics

Exercise 1: Explore existing index statistics Challenge Exercise 2: Design column orders for indexes (Only if time permits) Lab 5: Planning for SQL Server Indexing Logon information Estimated time: 45 minutes

Lab Scenario You have been asked to explain the concept of index statistics and selectivity to a new developer. You will explore the statistics available on an existing index and determine how selective some sample queries would be. One of the company developers has provided you with a list of the most important queries that will be executed by the new marketing management system. Depending upon how much time you have available, you need to determine the best column orders for indexes to support each query. Complete as many as possible within the allocated time. In later modules, you will consider how these indexes would be implemented. Each query is to be considered in isolation in this exercise.

Lab Review Which types of queries would most likely lead to widely- differing query plans? If you have an equality predicate and a LIKE predicate in your most important query, which predicate would you try to satisfy as the first column of a composite index?

Module Review and Takeaways Review Questions Best Practices