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.

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.
Working with SQL Server Database Objects
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
SQL Server Storage and Index Structures Physical Data Organization Indexes B-Trees SQL Server Data Access Clustered and Non-Clustered Creating, Altering,
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.
1 Lecture 20: Indexes Friday, February 25, Outline Representing data elements (12) Index structures (13.1, 13.2) B-trees (13.3)
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.
Introduction to Structured Query Language (SQL)
Performing Indexing and Full-Text Searching Lesson 21.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Copyright © Curt Hill Index Creation SQL.
TEMPDB Capacity Planning. Indexing Advantages – Increases performance – SQL server do not have to search all the rows. – Performance, Concurrency, Required.
Index tuning Performance Tuning. Overview Index An index is a data structure that supports efficient access to data Set of Records index Condition on.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
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.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Module 16: Performing Ongoing Database Maintenance
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Nimesh Shah (nimesh.s) , Amit Bhawnani (amit.b)
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
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.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
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.
Session 1 Module 1: Introduction to Data Integrity
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.
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.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.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
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.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Instructor: Craig Duckett Lecture 06: Thursday, October 15 th, 2015 Indexes, Aliases, Distinct, SQL 1 BIT275: Database Design (Fall 2015)
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
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Microsoft SQL Server 2005 Advanced SQL Programming and Optimization
SQL Implementation & Administration
SQL Creating and Managing Tables
Inside of SQL Server Indexes
Module 4: Creating and Tuning Indexes
Using SQL Server through Command Prompt
SQL.
SQL Creating and Managing Tables
Session #, Speaker Name Indexing Chapter 8 11/19/2018.
Lecture 12 Lecture 12: Indexing.
SQL Creating and Managing Tables
Indexing Fundamentals
Chapter 4 Indexes.
CH 4 Indexes.
Indexing for Beginners
Database systems Lecture 6 – Indexes
CH 4 Indexes.
HAVING,INDEX,COMMIT & ROLLBACK
Physical Storage Structures
SQL Server Indexing for the Client Developer
Presentation transcript:

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.

Types of index A clustered index »These can be unique and or composite A nonclustered index »These can be unique and or composite They are created on a column of a table

A clustered index In this index the leaf pages are the data pages from the table. The table is physically sorted by the clustered indexed column. Like a telephone directory or encyclopaedia. You can have only one clustered index per table

A nonclustered index In this index the leaf page has a pointer (row number) which points to the data in the table. Like a reference book. The table is not physically sorted You can have more than one nonclustered index on a table.

Simplest syntax CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name ON { table | view } ( column) [ WITH [,...n] ] [ ON filegroup ] Leaves you with CREATE INDEX index_name ON table_name (col_name) Creates nonclustered index

The options - UNIQUE Creates a unique index (one in which no two rows are permitted to have the same index value) on a table or view. Benefit? Once SQL Server has found this entry it knows to stop searching. CREATE UNIQUE INDEX index_name ON table_name (col_name )

The options - COMPOSITE Uses more than one column for the index key Can be clustered or nonclustered CREATE INDEX index_name ON table ( column1,column2)

Index example Example - when designing database you discover that – A list of employees will be created showing their department number. The list will be produced in alphabetical order by last name, and then followed by first name. What would be the best index here? Write the create statement.

Composite Index If this is a common query SELECT LastName, FirstName FROM Employee WHERE DeptNo = 50 ORDER BY LastName Create this index CREATE CLUSTERED INDEX EmployeeName ON Employee (LastName, FirstName,DeptNo) Clustered because you want a sorted output Composite because it covers more than 1 column

INDEX OPTIONS :: = { PAD_INDEX | FILLFACTOR = fillfactor | }

FILLFACTOR Specifies a percentage to indicate how full SQL Server should make the leaf level of each index page during index creation. When an index page fills up, SQL Server must take time to split the index page to make room for new rows.

What Fillfactor to set If data is volatile, FILLFACTOR needs to be low If data is static, FILLFACTOR can be high The default is a high fillfactor CREATE INDEX index_name ON table_name (col_name) WITH FILLFACTOR = 50 Reduces page splitting Double the size of the database with a clustered index 

Which of the following fillfactors would be 90% and which would be 60%?

A. High fill factor Very soon the leaf page will have to be split as more data is entered into the table

B. Low fill factor The leaf level has plenty of space to take more data. Performance will not be reduced due to lots of page splitting The index will take up almost twice the disk space 

PAD_INDEX Used in conjunction with FILLFACTOR CREATE INDEX index_name ON table_name (col_name) WITH FILLFACTOR = 50, PAD_INDEX This gives the root page and intermediate pages in the index the same amount of free space when the index is created. Reduces page splitting

Which columns? What type of index? –Range queries (WHERE cus_name BETWEEN ‘A%’ and ‘D%’) Cus IDcus_name 3456Anderson 3467Archer 6789Batty 2345Brearley 7659Carter 7654Denton 1222Ellis CLUSTERED on cus-name Table data is in alphabetical order

Which columns? What type of index? –Wildcard queries (WHERE customer_name LIKE ‘ch%’) CusNoName 1253Charr 6788Charter 1222Chester 7890Chett 2222Chippen CLUSTERED Index on Name column

Which columns? What type of index? an exact match query that uses the WHERE clause to return a unique record eg select empname where NINO = 12 And another query that lists employees in alphabetical order PayroleNoEmpnameNINO 134LECCinderey12 UNIQUE, NONCLUSTERED index on NINO. SqlServer stops looking after it has found one record Clustered (not unique) index on Empname

Deciding which columns to index Columns which are used in table joins CLUSTERED (WILL SORT ON THE JOIN COLUMN) but if there is already a clustered index use a non-clustered index.

You’ve already created indexes Creating a primary key automatically creates a unique index

This is the end of the lecture. Any Questions? Use the forum or bring the questions to class