Indexes Rose-Hulman Institute of Technology Curt Clifton.

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

F28DM Indexes in Oracle 1 F28DM : Database Management Systems Indexes in Oracle Monica Farrow Room: EMG30, Ext: 4160 Material on Vision.
Introduction to Database Systems1 Records and Files Storage Technology: Topic 3.
Working with SQL Server Database Objects
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
A HEAP OF CLUSTERS A look into heaps vs. clustered tables Ami Levin CTO, DBSophic X.
1 Overview of Storage and Indexing Chapter 8 (part 1)
Introduction to Structured Query Language (SQL)
Module 13: Optimizing Query Performance. Overview Introduction to the Query Optimizer Obtaining Execution Plan Information Using an Index to Cover a Query.
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
Module 7: Creating and Maintaining Indexes. Overview Creating Indexes Creating Index Options Maintaining Indexes Introduction to Statistics Querying the.
Introduction to Structured Query Language (SQL)
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
Performing Indexing and Full-Text Searching Lesson 21.
Practical Database Design and Tuning. Outline  Practical Database Design and Tuning Physical Database Design in Relational Databases An Overview of Database.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
Module 12: Optimizing Query Performance. Overview Introducing the Query Optimizer Tuning Performance Using SQL Utilities Using an Index to Cover a Query.
Architecture Rajesh. Components of Database Engine.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
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.
Unit 6 Data Storage Design. Key Concepts 1. Database overview 2. SQL review 3. Designing fields 4. Denormalization 5. File organization 6. Object-relational.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
© Pearson Education Limited, Chapter 13 Physical Database Design – Step 4 (Choose File Organizations and Indexes) Transparencies.
Nimesh Shah (nimesh.s) , Amit Bhawnani (amit.b)
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Indexes and Views Unit 7.
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.
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.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
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.
11-1 © Prentice Hall, 2004 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
CS4432: Database Systems II
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
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 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.
Practical Database Design and Tuning
Microsoft SQL Server 2005 Advanced SQL Programming and Optimization
Indexes By Adrienne Watt.
Record Storage, File Organization, and Indexes
Chapter 6 - Database Implementation and Use
Advanced SQL Programming for SQL Server 2008
Module 4: Creating and Tuning Indexes
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE
Lecture 12 Lecture 12: Indexing.
Physical Database Design
Chapter 4 Indexes.
CH 4 Indexes.
Database systems Lecture 6 – Indexes
Indexes CHỈ MỤC DỮ LiỆU.
CH 4 Indexes.
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
Physical Storage Structures
All about Indexes Gail Shaw.
Presentation transcript:

Indexes Rose-Hulman Institute of Technology Curt Clifton

Overview  Introduction to Indexes  Index Architecture  How SQL Server Retrieves Stored Data  How SQL Server Maintains Index and Heap Structures  Deciding Which Columns to Index

Data Pages Page 7 Page 8Page 9 Akhtar Funk Smith Martin... Page 4Page 5Page 6... Con Funk White... Rudd White Barr... Smith Ota Jones... Martin Phua Jones Smith... Ganio Jones Hall... Storing and Accessing Data  How Data Is Stored Rows are stored in data pages Heaps are a collection of data pages for a table

Whether to Create Indexes  Why to Create an Index Speeds up data access Enforces uniqueness of rows  Why Not to Create an Index Consumes disk space Incurs overhead

Using Heaps  SQL Server:  Uses Index Allocation Map Pages That: Contain information on where the extents of a heap are stored Navigate through the heap and find available space for new rows being inserted Connect data pages  Reclaims Space for New Rows in the Heap When a Row Is Deleted

Using Clustered Indexes  Each Table Can Have Only One Clustered Index  The Physical Row Order of the Table and the Order of Rows in the Index Are the Same  Key Value Uniqueness Is Maintained Explicitly or Implicitly

Using Nonclustered Indexes  Nonclustered Indexes Are the SQL Server Default  Existing Nonclustered Indexes Are Automatically Rebuilt When: An existing clustered index is dropped A new clustered index is created The DROP_EXISTING option is used to change which columns define the clustered index

Maintaining Index and Heap Structures

Page Splits in an Index Index Pages Non-Leaf Level INSERT member (last name) VALUES lastname = ‘Jackson' INSERT member (last name) VALUES lastname = ‘Jackson' Lang Smith … … Akhtar Ganio … … Akhtar … … Martin Jackson Leaf Level (Key Value) Akhtar Barr Borm Buhl … … … … … … … … … … Lang Martin Moris … … … … … … … … … … Smith … … … … … … … … … … ……… Ganio Hall Hart Jones … … … … … … … … … … … Leaf Level (Key Value) Akhtar Barr Borm Buhl … … … … … … … … … … Jackson Jones … … … … … … Lang Martin Moris … … … … … … … … … … Smith … … … … … … … … … … ……… Ganio Hall Hart … … … … … … … Jackson…

Forwarding Pointer in a Heap Non-Leaf Level Page 12 - Root Page 37Page 28 Leaf Level (Key Value) Page 41Page 51Page 61Page 71 Akhtar... Martin Akhtar Barr Con Funk 4:706:01 4:705:03 4:704:01 4:706:02 4:704:02 Martin Smith... Smith White 4:706:03 4:708:04 4:707:01 4:704:03 4:705:02 Akhtar Ganio... Ganio Hall Jones 4:709:01 4:709:04 4:709:02 4:708:03 4:707:03 Heap Page 707 Page 708Page Akhtar Funk Smith Martin... Page 704Page 705Page Conn Funk White Rudd White Barr Smith Ota Jones Corets Nash Martin Phua Jones Smith Ganio Jones Hall... Martin Ota Phua Rudd 4:708:01 4:706:04 4:707:02 4:708:02 4:705:01 Non Clustered Index File ID #4 id indid = 2 root sysindexes Non-Leaf Level Page 12 - Root Page 37Page 28 Leaf Level (Key Value) Page 41Page 51Page 61Page 71 Akhtar... Martin Akhtar Barr Con Funk 4:706:01 4:705:03 4:704:01 4:706:02 4:704:02 Martin Smith... Smith White 4:706:03 4:708:04 4:707:01 4:704:03 4:705:02 Akhtar Ganio... Ganio Hall Jones 4:709:01 4:709:04 4:709:02 4:708:03 4:707:03 Heap Page 707 Page 708Page Akhtar Funk Smith Martin... Page 704Page 705Page Conn Funk White Rudd White Barr Smith Ota Jones Corets Nash Martin Phua Jones Smith Ganio Jones Hall... Martin Ota Phua Rudd 4:708:01 4:706:04 4:707:02 4:708:02 4:705:01 Non clustered Index File ID # Ota 02...Ota Martin Martin 02Ota 04...Ota Ota4:707:02 UPDATE member SET Address = WHERE lastname = 'Ota' UPDATE member SET Address = WHERE lastname = 'Ota'

Row Updates  Generally do not cause rows to move  Like a delete followed by an insert Logically Sometimes practically  Batch updates touch each index once

Deletion  Deletion creates “ghost records”  Reclaiming space Free pages when empty For indexed table:  Can overwrite ghost records immediately For non-indexed table:  Compact records when more space is needed for insert

Deciding What to Index

What You Need to Know  Logical and Physical Database Design  Data Characteristics  How Data Is Used The types of queries performed The frequency of queries that are typically performed

Indexing Guidelines  Columns to Index Primary and foreign keys Those frequently searched in ranges Those frequently accessed in sorted order Those frequently grouped together during aggregation  Columns Not to Index Those seldom referenced in queries Those that contain few unique values Those defined with text, ntext, or image data types

Choosing the Clustered Index  Heavily Updated Tables A clustered index with an identity column keeps updated pages in memory  Sorting A clustered index keeps the data pre-sorted  Column Length and Data Type Limit the number of columns Reduce the number of characters Use the smallest data type possible

Data Characteristics – Densitylast_namelast_namefirst_namefirst_name Randall Joshua Randall Cynthia Randall Tristan Ota Lani SELECT * FROM member WHERE last_name = ‘Ota’ Low Density SELECT * FROM member WHERE last_name = ‘Randall’ High Density

Data Characteristics – Selectivity  How effective is a column at selecting a subset of the data  A property of a given query: Rows matching property / Total number of rows

Determining Selectivity High selectivity member_nomember_no last_namelast_namefirst_namefirst_name Randall Flood Joshua Kathie Anderson Bill SELECT * FROM member WHERE member_no > = 10% Number of rows meeting criteria Total number of rows in table = Low selectivity member_nomember_no last_namelast_namefirst_namefirst_name Randall Flood Joshua Kathie Anderson Bill SELECT * FROM member WHERE member_no < = 90% Number of rows meeting criteria Total number of rows in table =

Indexing to Support Queries  Writing Good Search Arguments Specify a WHERE clause in the query Verify that the WHERE clause limits the number of rows Avoid using leading wildcards

Introduction to Statistics

Standard Distribution of Values F - JA - EK - OP - UV - Z Last Name Number of Last Names Even Distribution of Values Last Name Number of Last Names C - FA - BG - K L - NO - Z

How Statistics Are Gathered  DMBS reads/samples column values Produces an evenly distributed sorted list of values  Performs a full scan or sampling of rows Depending on size of table and granularity wanted  Selects samplings if necessary Picks rows to be sampled Includes all rows on the page of selected rows

Creating Statistics  Automatically Creating Statistics Indexed columns that contain data Non-indexed columns that are used in a join predicate or a WHERE clause  Manually Creating Statistics Columns that are not indexed All columns other than the first column of a composite index

Viewing Statistics  The DBCC SHOW_STATISTICS Statement Returns Statistical Information in the Distribution Page for an Index or Column  Statistical Information Includes: The time when the statistics were last updated The number of rows sampled to produce the histogram Density information Average key length Histogram step information

Performance Considerations  Create Indexes on Foreign Keys  Create the Clustered Index Before Nonclustered Indexes  Consider Creating Composite Indexes  Create Multiple Indexes for a Table That Is Read Frequently