Lecture 8 Index Organized Tables Clusters Index compression

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.
1 Introduction to Database Systems CSE 444 Lectures 19: Data Storage and Indexes November 14, 2007.
Physical Database Design Chapter 5 G. Green 1. Agenda Purpose Activities Fields Records Files 2.
Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes.
Chapter Physical Database Design Methodology Software & Hardware Mapping Logical Design to DBMS Physical Implementation Security Implementation Monitoring.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
IS 4420 Database Fundamentals Chapter 6: Physical Database Design and Performance Leon Chen.
© 2005 by Prentice Hall 1 Chapter 6: Physical Database Design and Performance Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B. Prescott,
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.
AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Physical DB Design CSE2132 Database Systems Week 10 Lecture Physical Database Design - File Structures.
1 Physical Data Organization and Indexing Lecture 14.
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.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
TM 7-1 Copyright © 1999 Addison Wesley Longman, Inc. Physical Database Design.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
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.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
© Pearson Education Limited, Chapter 13 Physical Database Design – Step 4 (Choose File Organizations and Indexes) Transparencies.
Database Management COP4540, SCS, FIU Physical Database Design (ch. 16 & ch. 3)
Chapter 10 Designing the Files and Databases. SAD/CHAPTER 102 Learning Objectives Discuss the conversion from a logical data model to a physical database.
Indexes and Views Unit 7.
University of Sunderland COM 220 Lecture Ten Slide 1 Database Performance.
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.
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.
Managing Schema Objects
Chapter 5 Index and Clustering
Indexes CSE2132 Database Systems Week 11 Lecture Indexes.
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
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.
Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns.
Spring 2004 ECE569 Lecture 05.1 ECE 569 Database System Engineering Spring 2004 Yanyong Zhang
Chap 5. Disk IO Distribution Chap 6. Index Architecture Written by Yong-soon Kwon Summerized By Sungchan IDS Lab
CS 440 Database Management Systems Lecture 6: Data storage & access methods 1.
Description and exemplification use of a Data Dictionary. A data dictionary is a catalogue of all data items in a system. The data dictionary stores details.
Unit 6 Seminar. Indexed Organized Tables Definition: Index Organized Tables are tables that, unlike heap tables, are organized like B*Tree indexes.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Indexes 22 Index Table Key Row pointer … WHERE key = 22.
Select Operation Strategies And Indexing (Chapter 8)
1 Chapters 19 and 20  Ch. 19: By What Authority? Users Roles Grant and revoke Synonyms  Ch. 20: Changing the Oracle Surroundings Indexes Clusters Sequences.
Indexes By Adrienne Watt.
Indexing Structures for Files and Physical Database Design
Physical Database Design and Performance
ITD1312 Database Principles Chapter 5: Physical Database Design
Choosing Access Path The basic methods.
COMP 430 Intro. to Database Systems
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Indexes … WHERE key = Table Index 22 Row pointer Key Indexes
Session #, Speaker Name Indexing Chapter 8 11/19/2018.
Lecture 12 Lecture 12: Indexing.
Physical Database Design
Chapter 4 Indexes.
CH 4 Indexes.
CH 4 Indexes.
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
Introduction to Database Systems CSE 444 Lectures 19: Data Storage and Indexes May 16, 2008.
Alternative Storage Techniques
Presentation transcript:

Lecture 8 Index Organized Tables Clusters Index compression Bitmap Indexes

Index Organized Tables In Oracle Tables can be organized as: HEAP (default, meaning unorganized) INDEX (meaning Index Organized Table) Index Organized Table: In MsSQL called: CLUSTER INDEX, clusters in Oracle mean something else Table data is stored together with primary key index

IOT tables - details Index Organized Table: There is no separate table data storage, everything is stored in index data Index structure is dynamic, physical location of the row can change → ROWIDs can change Table access by primary key is very fast, faster than for HEAP organized tables

IOT tables - syntax To create IOT table, add ORGANIZATION INDEX when creating a table IOT table must have primary key CREATE TABLE emp_iot ( id NUMBER PRIMARY KEY, ... hire_date DATE ) ORGANIZATION INDEX;

IOT tables - overflow Storing table data with index can improve performance – there is no separate data storage to look up Storing data with index makes index larger – this degrades index performance In some cases record data is large, it is not practical to store that in the PK index IOT tables can have OVERFLOW area – if there is too much data it is stored in separate location

IOT overflow - syntax CREATE TABLE emp_iot ( id NUMBER PRIMARY KEY, name VARCHAR2(100), hire_date DATE, description VARCHAR2(4000) ) ORGANIZATION INDEX PCTTHRESHOLD 20 INCLUDING hire_date OVERFLOW TABLESPACE users;

IOT tables – secondary indexes For HEAP table, index contains ROWID For IOT tables rows can be moved as index structure changes, ROWID cannot be fixed IOT table always contains Primary Key index, other indexes are called Secondary Indexes Secondary Index contains Logical ROWID Logical ROWID contains: Primary key of the row ROWID guess – probable location of the row

IOT - secondary indexes, cont. When using secondary index: Database finds the Logical ROWID It tries to locate the row by ROWID guess If that fails, it searches for the row using primary key index As a result, secondary indexes on IOT perform worse than indexes on HEAP organized tables

Clustered Tables In Oracle Tables with common fields are stored together. The common field is called a cluster key. Records with the same cluster key are stored together for faster access. Oracle implements two types of clusters: Index Clusters Hash Clusters

Indexed Clusters Recommended for situations where: Queries retrieve records over a range of values, for example SELECT * FROM emp WHERE dept_id = 1 not just SELECT * FROM emp WHERE id = 1 Tables do not have fixed size, they grow unpredictably

Indexed Clusters example CREATE CLUSTER emp_phones_cluster (emp_id NUMBER) size 1024; CREATE INDEX idx_emp_cluster ON CLUSTER emp_phones_cluster;

Indexed Clusters example, cont. CREATE TABLE emp_clust ( id NUMBER PRIMARY KEY, ... hire_date DATE ) CLUSTER emp_phones_cluster(id); CREATE TABLE emp_phones_clust ( emp_id NUMBER REFERENCES emp_clust(id), phone_number VARCHAR2(15), ) CLUSTER emp_phones_cluster(emp_id);

Using Indexed Clusters Indexed clusters – advantages: Rows stored together can be retrieved without additional join effort Queries are faster when joining tables by cluster key Disadvantages: It can take longer when updating cluster key column in a table

Hash Clusters Hash Clusters: Useful when queries retrieve records based on an equality condition on cluster key: SELECT * FROM products WHERE id = 5; Not useful for non-equality conditions: SELECT * FROM products WHERE id < 5; Useful when tables are static - they have fixed size. Maximum number of records and maximum space can be predicted. Useful for dictionary tables, lookup tables etc.

Hash Clusters - example CREATE CLUSTER products_cluster ( id number ) HASHKEYS 20; CREATE TABLE products ( id number not null, name varchar2(100), ... ) CLUSTER products_cluster(id);

Hash Clusters - details Using Hash Clusters: Do not create Cluster Index for hash cluster Do not create index on cluster key for hash cluster When using condition like: SELECT * FROM zip_codes WHERE id = 5; access is faster than index cluster or table with index.

Index Compression Oracle multi column indexes can be COMPRESSED Uncompressed index stores values: COL1, COL2, rowid (123, 1, ROWID) (123, 2, ROWID) (123, 3, ROWID) (200, 1, ROWID) (200, 2, ROWID) (200, 3, ROWID)

Index Compression, cont Compressed index stores values: COL1, COL2, rowid Prefix: 123 (1, ROWID) (2, ROWID) (3, ROWID) Prefix: 200

Using Index Compression Index compression is useful: For indexes with 2 or more columns. The first column must have many duplicated values. Index organized tables can be compressed

Index Compression syntax CREATE TABLE emp_phones_iot ( emp_id number not null, phone_number varchar2(15), PRIMARY KEY (emp_id, phone_number) ) ORGANIZATION INDEX COMPRESS 1; CREATE INDEX emp_dept_idx ON emp(dept_id, id) COMPRESS 1;

Bitmap Indexes Bitmap Indexes are intended for: low cardinality columns (many duplicated values). This is the oposite of BTree indexes, which are best for unique or close to unique columns tables not very frequently updated Bitmap Indexes are only available in Oracle Enterprise Edition

Bitmap Indexes Characteristics Must be non-unique Include NULL values (BTree indexes do not) Can be IOT secondary indexes Cannot be compressed

Bitmap Indexes example CREATE TABLE properties ( id NUMBER PRIMARY KEY, bedrooms NUMBER, bathrooms NUMBER, garages NUMBER ); CREATE BITMAP INDEX idx_beds ON properties (bedrooms); CREATE BITMAP INDEX idx_bths ON properties (bathrooms); CREATE BITMAP INDEX idx_gar ON properties (garages); SELECT id FROM properties WHERE bedrooms = 3 AND bathrooms = 2 AND garages = 1;

Bitmap Indexes When creating bitmap index: Oracle creates bitmap for each unique value in a column (plus NULL value) Each bitmap has as many values as there are rows in the table

Bitmap Indexes example Example table PROPERTIES Bedroom index bitmap id Bed rooms 100 1 101 2 102 3 103 104 105 106 100 101 102 103 104 105 106 1 2 3

Bitmap Indexes example Bedroom index bitmap SELECT id FROM properties WHERE bedrooms=1 Get all 1-s from the first bitmap SELECT id FROM properties WHERE bedrooms = 1 OR bedrooms = 2 Combine bitmap 1 and 2, then get all 1-s 100 101 102 103 104 105 106 1 2 3

Bitmap Indexes Oracle supports many bitmap operations: AND – AND operation between two bitmaps OR NOT MINUS (A MINUS B is A AND NOT B) Bitmap range scans are supported (for example: WHERE bathroom <= 2)

Bitmap AND CREATE TABLE t1 (c1 NUMBER, c2 NUMBER); CREATE BITMAP INDEX i1 ON t1 (c1); CREATE BITMAP INDEX i2 ON t1 (c2); SELECT c1,c2 FROM t1 WHERE c1 = 0 AND c2 = 0; 0 SELECT STATEMENT Optimizer=CHOOSE 1 0 BITMAP CONVERSION (TO ROWIDS) 2 1 BITMAP OR 3 2 BITMAP INDEX (SINGLE VALUE) OF 'I1‘ 4 2 BITMAP INDEX (SINGLE VALUE) OF 'I2‘

Bitmap OR CREATE TABLE t1 (c1 NUMBER, c2 NUMBER); CREATE BITMAP INDEX i1 ON t1 (c1); CREATE BITMAP INDEX i2 ON t1 (c2); SELECT c1,c2 FROM t1 WHERE c1 = 0 OR c2 = 0; 0 SELECT STATEMENT Optimizer=CHOOSE 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T1‘ 2 1 BITMAP CONVERSION (TO ROWIDS) 3 2 BITMAP OR 4 3 BITMAP INDEX (SINGLE VALUE) OF 'I1‘ 5 3 BITMAP INDEX (SINGLE VALUE) OF 'I2'

Bitmap MINUS CREATE TABLE t1 (c1 NUMBER, c2 NUMBER); CREATE BITMAP INDEX i1 ON t1 (c1); CREATE BITMAP INDEX i2 ON t1 (c2); SELECT c1,c2 FROM t1 WHERE c1 = 0 AND c2 != 0; 0 SELECT STATEMENT Optimizer=CHOOSE 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T1‘ 2 1 BITMAP CONVERSION (TO ROWIDS) 3 2 BITMAP MINUS 4 3 BITMAP MINUS 5 4 BITMAP INDEX (SINGLE VALUE) OF 'I1‘ 6 4 BITMAP INDEX (SINGLE VALUE) OF 'I2‘ 7 3 BITMAP INDEX (SINGLE VALUE) OF 'I2'

Bitmap MERGE CREATE TABLE t1 (c1 NUMBER, c2 NUMBER); CREATE BITMAP INDEX i1 ON t1 (c1); CREATE BITMAP INDEX i2 ON t1 (c2); SELECT c1,c2 FROM t1 WHERE c1 > 0 AND c2 = 0; 0 SELECT STATEMENT Optimizer=CHOOSE 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T1' 2 1 BITMAP CONVERSION (TO ROWIDS) 3 2 BITMAP AND 4 3 BITMAP INDEX (SINGLE VALUE) OF 'I2‘ 5 3 BITMAP MERGE 6 5 BITMAP INDEX (RANGE SCAN) OF 'I1'

BTree bitmap execution plans CREATE TABLE t2 (c1 NUMBER, c2 NUMBER); CREATE INDEX it2 ON t2 (c1); CREATE INDEX it3 ON t2 (c2); SELECT c1,c2 FROM t2 WHERE c1 = 0 AND c2 = 0; 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=5) 1 0 BITMAP CONVERSION (TO ROWIDS) 2 1 BITMAP AND 3 2 BITMAP CONVERSION (FROM ROWIDS) 4 3 INDEX (RANGE SCAN) OF 'IT3' (NON-UNIQUE) 5 2 BITMAP CONVERSION (FROM ROWIDS) 6 5 INDEX (RANGE SCAN) OF 'IT2' (NON- UNIQUE)