Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes.

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

12 Copyright © Oracle Corporation, All rights reserved. Managing Indexes.
Introduction to Structured Query Language (SQL)
IS 4420 Database Fundamentals Chapter 6: Physical Database Design and Performance Leon Chen.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Introduction to Structured Query Language (SQL)
Optimization Exercises. Question 1 How do you think the following query should be computed? What indexes would you suggest to use? SELECT E.ename, D.mgr.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
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 Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Lecture 8 Index Organized Tables Clusters Index compression
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Chapter 6 Additional Database Objects
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
Database Technical Session By: Prof. Adarsh Patel.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
School of Computing and Management Sciences © Sheffield Hallam University Finding Data –In a list of 700 composers, how do we find Berlioz? –The row with.
Materialized Views. 2 Materialized Views – Agenda What is a Materialized View? – Advantages and Disadvantages How Materialized Views Work – Parameter.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
8 Copyright © 2007, Oracle. All rights reserved. Managing Schema Objects.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
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.
13 Copyright © Oracle Corporation, All rights reserved. Maintaining Data Integrity.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Partition Architecture Yeon JongHeum
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Chapter 4 Logical & Physical Database Design
Managing Schema Objects
Chapter 5 Index and Clustering
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.
Indexes … WHERE key = Table Index 22 Row pointer Key Indexes
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata Performance Optimization.
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.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
Unit 6 Seminar. Indexed Organized Tables Definition: Index Organized Tables are tables that, unlike heap tables, are organized like B*Tree indexes.
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.
1 Indexes ► Sort data logically to improve the speed of searching and sorting operations. ► Provide rapid retrieval of specified rows from the table without.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
SQL Basics Review Reviewing what we’ve learned so far…….
Indexes 22 Index Table Key Row pointer … WHERE key = 22.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
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
Physical Database Design
Indexes and Basic Access Methods
COMP 430 Intro. to Database Systems
Database Performance Tuning and Query Optimization
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE
Indexes … WHERE key = Table Index 22 Row pointer Key Indexes
Lecture 12 Lecture 12: Indexing.
Chapter 4 Indexes.
CH 4 Indexes.
CH 4 Indexes.
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
Understanding Indexes
Chapter 11 Database Performance Tuning and Query Optimization
Presentation transcript:

Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes

Semantec Ltd. Agenda Overview Types Storage Selecting an index strategy

Semantec Ltd. Overview Create Indexes when selecting a small percentage of rows from a table (less than 2-4%) Indexes are logically and physically independent of the data in the associate table. Required CREATE ANY INDEX system privilege for creating index.

Semantec Ltd. Indexing schemes B-tree indexes B-tree cluster indexes Reverse key indexes Bitmap indexes Hash cluster indexes

Semantec Ltd. Types Unique and non unique indexes Composite indexes Function-based indexes Application domain indexes

Semantec Ltd. Unique and nonunique indexes Oracle recommends that you do not explicitly define unique indexes on tables. Oracle automatically creates index to enforce UNIQUE and PRIMARY KEY integrity constraints.

Semantec Ltd. Composite index Example Vend_idPart_NoUnit_cost CREATE INDEX Vend_idx1 ON Vendor (Vend_id,Part_No); CREATE INDEX Vend_idx2 ON Vendor (Part_No,Vend_id);

Semantec Ltd. Composite index Guidelines for creating Create on keys that are frequently used together in WHERE clause conditions combined with AND operators. If several queries select the same set of keys based on one or more key values, then create a composite index containing all of these keys. Consider the guidelines associated with the general performance advantages and trade- offs of all type of indexes.

Semantec Ltd. Composite index Guidelines for ordering Create the index so the keys used in WHERE clauses make up a leading portion. Create the index so that the more frequently selected keys make up a leading portion. If all keys are used in WHERE clauses equally often, then ordering these keys from most selective to least selective. If all keys are used in the WHERE clauses equally often but the data is physically ordered on one of the keys, then place that key first in the composite index.

Semantec Ltd. Internal structure of indexes B-tree indexes B-tree cluster indexes Reverse key indexes Bitmap indexes Index-organized tables

Semantec Ltd. B-tree indexes Storage

Semantec Ltd. B-tree indexes Advantages All leaf blocks of the tree are at the same depth. B-tree indexes automatically stay balanced. All blocks of the B-tree are three-quarters full on the average. B-trees provide excellent retrieval performance for a wide range of queries, including exact match and range searches. Inserts, updates, and deletes are efficient, maintaining key order for fast retrieval. B-tree performance is good for both small and large tables, and does not degrade as the size of a table grows.

Semantec Ltd. Reverse key indexes Creating a reverse key index, compared to a standard index, reverses the bytes of each column indexed (except the rowid) while keeping the column order. Example: CREATE INDEX i ON t (a,b,c) REVERSE; ALTER INDEX i REBUILD NOREVERSE;

Semantec Ltd. Bitmap indexes Example CUSTO MER# MARITAL_ STATUS REGIONGENDERINCOME_ LEVEL 101SingleEastMale1 102MarriedCentralFemale2 103MarriedWestFemale3 104DivorcedCentralFemale1 105MarriedWestMale2 106SingleCentralMale2 Table Customer_data

Semantec Ltd. Bitmap indexes Example CREATE BITMAP INDEX ON Customer_data(MARITAL_STATUS, REGION, GENDER); SELECT COUNT(*) FROM Customer_data WHERE MARITAL_STATUS = ’Married’ AND REGION IN (’Central’,’West’);

Semantec Ltd. Bitmap indexes Example REGION = ‘East’ REGION = ‘Central’ REGION = ‘West’

Semantec Ltd. REGION = ‘Central’ REGION = ‘West’ Bitmap indexes Example Status = ‘married’ AND OR = = AND

Semantec Ltd. Bitmap indexes Benefits Reduced response time for large classes of queries Asubstantial reduction of space usage compared to other indexing techniques Dramatic performance gains even on very low end hardware Very efficient parallel DML and loads

Semantec Ltd. Function-based indexes Advantages Increase the number of situations where the optimizer can perform a range scan instead of a full table scan. Precompute the value of a computationally intensive function and store it in the index. Create indexes on object columns and REF columns. Create more powerful sorts.

Semantec Ltd. Function-based indexes Restrictions Used only by cost-based optimization. A PL/SQL function, used in the index expression must be declared as DETERMINISTIC. Function-based indexes cannot be built on LOB columns, nested tables, or varrays. Expressions used in a function-based index should reference only columns in a row in the table. Hence, these expressions cannot contain any aggregate functions. You must have the initialization parameters COMPATIBLE set to or higher, QUERY_REWRITE_ENABLED=TRUE, and QUERY_REWRITE_INTEGRITY=TRUSTED.

Semantec Ltd. Function-based indexes Restrictions You must analyze the table or index before the index is used. Bitmap optimizations cannot used descending indexes. Function-based indexes are not used when OR- expansion is done. The index function cannot be marked NOT NULL. To avoid a full table scan, you must ensure that the query cannot fetch null values. Function-based indexes that return VARCHAR2 or RAW data types from a PL/SQL function are not permitted due to length restrictions.

Semantec Ltd. Function-based indexes Example CREATE INDEX Idx ON Emp_tab(UPPER(Ename)); SELECT * FROM Emp_tab WHERE UPPER(Ename) like :KEYCOL;

Semantec Ltd. Function-based indexes Example CREATE INDEX Idx ON Fbi_tab (A+B*(C-1),A,B); SELECT a FROM Fbi_tab WHERE A+B*(C-1) < 100;

Semantec Ltd. Index-organized tables Primary key uniquely identifies a row; primary key must be specified Primary key based access Logical rowid in ROWID pseudocolumn allows building secondary indexes UNIQUE constraint not allowed but triggers are allowed Cannot be stored in a cluster Can contain LOB columns but not LONG columns Distribution and replication not supported

Semantec Ltd. Application domain indexes Indextype schema object Domain index (an application-specific index) Application specific operators

Semantec Ltd. Selecting an index strategy Creating indexes Alter indexes Dropping indexes

Semantec Ltd. Determine whether an index is good Create index, Analyze index, Use EXPLAIN PLAN on your query to see if the optimizer uses it. Is it expensive to maintain? Compare optimizer costs with and without index.

Semantec Ltd. Re-creating Indexes Use the ALTER INDEX... REBUILD statement to reorganize or compact an existing index or to change its storage characteristics. The REBUILD statement uses the existing index as the basis for the new one. ALTER INDEX... REBUILD is usually faster than dropping and re-creating an index. It reads all the index blocks using multiblock I/O then discards the branch blocks. A further advantage of this approach is that the old index is still available for queries while the rebuild is in progress.

Semantec Ltd. Writing Statements that Avoid Using Indexes You can use the NO_INDEX hint to give the CBO maximum flexibility while disallowing the use of a certain index. You can use the FULL hint to force the optimizer to choose a full table scan instead of an index scan. You can use the INDEX, INDEX_COMBINE, or AND_EQUAL hints to force the optimizer to use one index or a set of listed indexes instead of another.

2001, Semantec Ltd. Creating tables with constraints and indexes 1. Create the tables with the constraints. NOT NULL constraints may be unnamed and should be created enabled and validated. All other constraints should be named and should be "created disabled". 2. Load old data into the tables. 3. Create all indexes. 4. Enable novalidate all constraints. Do this to primary keys before foreign keys. 5. Allow users to query and modify data. 6. With a separate ALTER TABLE statement for each constraint, validate all constraints.