Boris Gurov Support Analyst Oracle Bulgaria All you need to know about Oracle Indexes.

Slides:



Advertisements
Similar presentations
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Advertisements

Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
File Management Chapter 12. File Management A file is a named entity used to save results from a program or provide data to a program. Access control.
12 Copyright © Oracle Corporation, All rights reserved. Managing Indexes.
Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes.
1 King Saud University College of Computer & Information Sciences IS 335 Database Management System Lecture 6 Query Processing and Optimization (Practice)
1 Overview of Storage and Indexing Chapter 8 (part 1)
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Data Indexing Herbert A. Evans. Purposes of Data Indexing What is Data Indexing? Why is it important?
1 Overview of Storage and Indexing Yanlei Diao UMass Amherst Feb 13, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
1 Indexing Structures for Files. 2 Basic Concepts  Indexing mechanisms used to speed up access to desired data without having to scan entire.
1 Overview of Storage and Indexing Chapter 8 1. Basics about file management 2. Introduction to indexing 3. First glimpse at indices and workloads.
DBMS Internals: Storage February 27th, Representing Data Elements Relational database elements: A tuple is represented as a record CREATE TABLE.
Access Path Selection in a Relation Database Management System (summarized in section 2)
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Tree-Structured Indexes Chapter 9.
Tree-Structured Indexes. Range Searches ``Find all students with gpa > 3.0’’ –If data is in sorted file, do binary search to find first such student,
Layers of a DBMS Query optimization Execution engine Files and access methods Buffer management Disk space management Query Processor Query execution plan.
Storage and Indexing February 26 th, 2003 Lecture 19.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
B+ Tree What is a B+ Tree Searching Insertion Deletion.
Database System Architecture and Performance CSCI 6442 ©Copyright 2015, David C. Roberts, all rights reserved.
Practical Database Design and Tuning. Outline  Practical Database Design and Tuning Physical Database Design in Relational Databases An Overview of Database.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Database Management 9. course. Execution of queries.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
Query Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
1 Overview of Storage and Indexing Chapter 8 (part 1)
1 Tree Indexing (1) Linear index is poor for insertion/deletion. Tree index can efficiently support all desired operations: –Insert/delete –Multiple search.
1 Indexing. 2 Motivation Sells(bar,beer,price )Bars(bar,addr ) Joe’sBud2.50Joe’sMaple St. Joe’sMiller2.75Sue’sRiver Rd. Sue’sBud2.50 Sue’sCoors3.00 Query:
Index tuning-- B+tree. overview Overview of tree-structured index Indexed sequential access method (ISAM) B+tree.
Indexing CS 400/600 – Data Structures. Indexing2 Memory and Disk  Typical memory access: 30 – 60 ns  Typical disk access: 3-9 ms  Difference: 100,000.
Query Optimizer (Chapter ). Optimization Minimizes uses of resources by choosing best set of alternative query access plans considers I/O cost,
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Chapter 5 Index and Clustering
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 B+-Tree Index Chapter 10 Modified by Donghui Zhang Nov 9, 2005.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 12 – Introduction to.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Storage and Indexing. How do we store efficiently large amounts of data? The appropriate storage depends on what kind of accesses we expect to have to.
Indexing. 421: Database Systems - Index Structures 2 Cost Model for Data Access q Data should be stored such that it can be accessed fast q Evaluation.
1 Tree-Structured Indexes Chapter Introduction  As for any index, 3 alternatives for data entries k* :  Data record with key value k   Choice.
Query Optimization Cases. D. ChristozovINF 280 DB Systems Query Optimization: Cases 2 Executable Block 1 Algorithm using Indices (if available) Temporary.
8 Copyright © 2005, Oracle. All rights reserved. Gathering Statistics.
Chapter 11 Indexing And Hashing (1) Yonsei University 1 st Semester, 2016 Sanghyun Park.
Indexes 22 Index Table Key Row pointer … WHERE key = 22.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Tree-Structured Indexes Chapter 10.
Database Applications (15-415) DBMS Internals- Part III Lecture 13, March 06, 2016 Mohammad Hammoud.
Tree-Structured Indexes. Introduction As for any index, 3 alternatives for data entries k*: – Data record with key value k –  Choice is orthogonal to.
How is data stored? ● Table and index Data are stored in blocks(aka Page). ● All IO is done at least one block at a time. ● Typical block size is 8Kb.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Indexing Structures for Files and Physical Database Design
Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed.
Record Storage, File Organization, and Indexes
EVOLUTION OF THE ORACLE OPTIMIZER THINKING
Indexing ? Why ? Need to locate the actual records on disk without having to read the entire table into memory.
Choosing Access Path The basic methods.
Database Management Systems (CS 564)
COST ESTIMATION FOR THE RELATIONAL ALGEBRA OPERATIONS MIT 813 GROUP 15 PRESENTATION.
Chapter 15 QUERY EXECUTION.
Understanding Indexes
Managing Indexes.
Indexing 1.
Storage and Indexing.
General External Merge Sort
Introduction to the Optimizer
Presentation transcript:

Boris Gurov Support Analyst Oracle Bulgaria All you need to know about Oracle Indexes

What is a table? row 1 fields row 2 fields. Data Blocks A table is a collection of data blocks Each data block physically stores several rows Each row is composed of several fields containing data row m fields row m+1 fields. row n fields

How can data in a table be accessed? Data in a table can be accessed by reading the table’s data pages sequentially looking for the required data. Can we speed this up?

The Concept of an Index We want a cross-reference of the table to enable us to access the data rows quickly We choose a key - the data fields that we normally use to locate a data row We store a list of key values and for each key value we write down the physical location of the data row

What does an index look like? row 1 fields row 2 fields …… Key1 Key2 …….. rowid Rowid ……...

row 1 fields row 2 fields …… Key1 Key2 …….. Keym rowid Rowid ……... rowid What does an index look like? row m fields row m+1 fields …….. row n fields …. Keym …… Rowid …..

Keym …… Keyn Rowid ….. Rowid row 1 fields row 2 fields …… Key1 Key2 …….. rowid Rowid ……... row m fields row m+1 fields …….. row n fields …. What does an index look like? Key1 Keym ……..……...

What does an index look like? row 1 fields row 2 fields …… row m fields row m+1 fields …….. row n fields Key1 Key2 …….. rowid Rowid ……... Keym Keyn ……. rowid ……. Keyrowid …...…. …. Table Leaf blocks Key1 Keym …….. Key1 Key …….. …… Key Branch Blocks

Creating a Balanced Tree Index An Oracle index has a balanced tree (B*-tree) structure In a balanced tree, the shortest path from the root block to a leaf block is either equal to the longest path or to the longest path minus 1 This guarantees that no matter what data we are looking for, navigating the index will use the same amount of I/O operations

Clustering Factor (CF) The CF is a number that indicates the extent to which the “SORT” sequences of the table and index match The CF ranges between the number of blocks containing data and the number of rows in the table The CF represents the number of I/O operations performed on the table when the entire index is scanned

Index Clustering - Low Clustering Factor R LLLL Row 1 Row 2 Row 3 Data Row 4 Row 5 Row 6 Data Row 7 Row 8 Row 9 Data Row 10 Row 11 Row 12 Data Row 13 Row 14 Row 15 Data Row 16 Data Row sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 Page sequence: 1, -, -, 2, -, -, 3, -, -, 4, -, -, 5, -, -, 6 Low Clustering Factor: 6

Index Clustering - Low Clustering Factor R LLLL Row 1 Row 4 Row 7 Data Row 10 Row 13 Row 16 Data Row 2 Row 8 Row 5 Data Row 11 Row 9 Row 15 Data Row 3 Row 14 Row 12 Data Row 6 Data Row sequence: 1, 4, 7, 10, 13, 16, 2, 8, 5, 11, 9, 15, 3, 14, 12, 6 Page sequence: 1, 2, 3, 4, 5, 6, 1, 3, 2, 4, 3, 5, 1, 5, 4, 2 High Clustering Factor: 16

Adjusting the Cost in Oracle 8i In Oracle 8i, the total cost of the index is adjusted using the following formula: Adjusted cost = cost * OPTIMIZER_INDEX_COST_ADJ / 100 This adjustment bypasses the Oracle assumption of a low buffer hit ratio used in the data access calculation

Data in Oracle’s Data Dictionary When the Analyze command is used to collect statistics, the following data on indexes is collected:  Index tree depth  Number of leaf blocks  Number of distinct values  Clustering factor  Average number of leaf blocks per index value  Average number of data blocks per index value

More Data More data on indexes can be collected using the Validate Index command The data collected is stored in a table called INDEX_STATS. Table INDEX_STATS is not part of the data dictionary and contains only one row with data on the last index for which the command was executed

Table INDEX_STATS contains the following useful data:  NAME:Name of the index for which the Validate Index command was executed  HEIGHT: Number of levels + 1  BLOCKS:Total number of index blocks  LF_ROWS:Number of rows in the leaf pages  LF_BLKS:Total number of leaf pages  BR_ROWS:Total number of rows in non-leaf blocks  BR_BLKS:Total number of non-leaf blocks

 LF_ROWS_LEN:Total length of all leaf rows  BR_ROWS_LEN:Total length of all non-leaf rows  DEL_LF_ROWS:Number of logically deleted rows  DEL_LF_ROWS_LEN:Total length of all deleted rows  DISTINCT_KEYS:Number of distinct keys in the index  MOST_REPEATED_KEY:Most repeated key  ROWS_PER_KEY:Average number of rows per key

More Data in the Data Dictionary Table Statistics  Number of rows  Number of currently used data blocks Column Statistics  Number of distinct values  Minimum value  Maximum value  Histogram information - provide improved selectivity information in cases where data distribution is not uniform

The Cost Based Optimizer (CBO) Uses knowledge and assumptions on data distribution and access patterns to select an access path to data Introduces the concept of a “hint”. Hints can force the use of specific access paths Optimizes queries for best throughput, unless instructed otherwise Selects an index ONLY if the price of using the index is lower than the price of a full table scan

PredicateEstimated Filter Factor =1/(number of distinct values) IN(values in IN)/(number of distinct values) >(highest value - requested value) (highest value - lowest value) <(requested value - lowest value) (highest value - lowest value) BETWEEN(requested high - requested low) (highest value - lowest value) Logical OperatorsEstimated Filter Factor expr1 AND expr2ff1 * ff2 expr1 OR expr2(ff1 + ff2) - (ff1 * ff2) Filtering Factor (FF)

Unique Index Scan Number of blocks read = index height + 1 (to scan the index) + 1 (to access the table data) A C

Range Index Scan Number of blocks read = index height leaves * FFM + CF * FFSM CF-index clustering factor FFM- filter factor of matching predicates FFSM- filter factor of all screening and matching predicates A B C

Full Index Scan Number of blocks read = leaves + CF * FFSM CF-index clustering factor FFSM- filter factor of all screening and matching predicates B C

Fast Full Index Scan Number of blocks read = IBLK / DBF + CF * FFSM IBLK-number of index blocks DBF-DB_FILE_MULTIBLOCK_READ_COUNT CF-index clustering factor FFSM- filter factor of all screening and matching predicates

Full Table Scan Number of blocks read = BLK / DBF BLK-number of dirty table blocks DBF-DB_FILE_MULTIBLOCK_READ_COUNT init.ora parameter

Summary An index improves performance ONLY if used correctly It is your responsibility to determine whether the optimizer selected the best access path to the required data and to correct the optimizer’s decision when you believe it failed to select the best access path