+ All Categories
Home > Documents > Boris Gurov Support Analyst Oracle Bulgaria

Boris Gurov Support Analyst Oracle Bulgaria

Date post: 09-Jan-2016
Category:
Upload: miracle
View: 17 times
Download: 1 times
Share this document with a friend
Description:
All you need to know about Oracle Indexes. Boris Gurov Support Analyst Oracle Bulgaria. What is a table?. A table is a collection of data blocks Each data block physically stores several rows Each row is composed of several fields containing data. Data Blocks. row 1 fields row 2 fields - PowerPoint PPT Presentation
28
Transcript
Page 1: Boris Gurov Support Analyst Oracle Bulgaria
Page 2: Boris Gurov Support Analyst Oracle Bulgaria

Boris GurovSupport AnalystOracle Bulgaria

All you need to know about Oracle Indexes

Page 3: Boris Gurov Support Analyst Oracle Bulgaria

What is a table?

row 1 fieldsrow 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 fieldsrow m+1 fields . .

row n fields

Page 4: Boris Gurov Support Analyst Oracle Bulgaria

How can data in a tablebe 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?

Page 5: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 6: Boris Gurov Support Analyst Oracle Bulgaria

What does an index look like?

row 1 fieldsrow 2 fields ……

Key1Key2……..

rowidRowid……...

Page 7: Boris Gurov Support Analyst Oracle Bulgaria

row 1 fieldsrow 2 fields ……

Key1Key2……..Keym

rowidRowid……...rowid

What does an index look like?

row m fieldsrow m+1 fields ……..

row n fields….

Keym

……

Rowid

…..

Page 8: Boris Gurov Support Analyst Oracle Bulgaria

Keym……Keyn

Rowid…..Rowid

row 1 fieldsrow 2 fields ……

Key1Key2……..

rowidRowid……...

row m fieldsrow m+1 fields ……..

row n fields….

What does an index look like?Key1Keym…….. ……...

Page 9: Boris Gurov Support Analyst Oracle Bulgaria

What does an index look like?

row 1 fieldsrow 2 fields ……

row m fieldsrow m+1 fields ……..

row n fields

Key1Key2……..

rowidRowid……...

KeymKeyn…….

rowidrowid …….

Key rowid

…...….

….Table

Leafblocks

Key1Keym……..

Key1Key……..

……Key

BranchBlocks

Page 10: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 11: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 12: Boris Gurov Support Analyst Oracle Bulgaria

Index Clustering -Low Clustering Factor

R

L L L L

Row 1

Row 2

Row 3

DataRow 4

Row 5

Row 6

DataRow 7

Row 8

Row 9

DataRow 10

Row 11

Row 12

DataRow 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

Page 13: Boris Gurov Support Analyst Oracle Bulgaria

Index Clustering -Low Clustering Factor

R

L L L L

Row 1

Row 4

Row 7

DataRow 10

Row 13

Row 16

DataRow 2

Row 8

Row 5

DataRow 11

Row 9

Row 15

DataRow 3

Row 14

Row 12

DataRow 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

Page 14: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 15: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 16: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 17: Boris Gurov Support Analyst Oracle Bulgaria

Table INDEX_STATS contains the following useful data: NAME: Name of the index for which the

ValidateIndex 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

Page 18: Boris Gurov Support Analyst Oracle Bulgaria

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

theindex

MOST_REPEATED_KEY: Most repeated key ROWS_PER_KEY: Average number of rows per

key

Page 19: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 20: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 21: Boris Gurov Support Analyst Oracle Bulgaria

Predicate Estimated 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 Operators Estimated Filter Factor

expr1 AND expr2 ff1 * ff2

expr1 OR expr2 (ff1 + ff2) - (ff1 * ff2)

Filtering Factor (FF)

Page 22: Boris Gurov Support Analyst Oracle Bulgaria

Unique Index Scan

Number of blocks read = index height + 1 (to scan the index) + 1 (to access the table data)

A

C

Page 23: Boris Gurov Support Analyst Oracle Bulgaria

Range Index Scan

Number of blocks read = index height + 1 + 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

Page 24: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 25: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 26: Boris Gurov Support Analyst Oracle Bulgaria

Full Table Scan

Number of blocks read = BLK / DBF

BLK - number of dirty table blocks

DBF - DB_FILE_MULTIBLOCK_READ_COUNT init.ora parameter

Page 27: Boris Gurov Support Analyst Oracle Bulgaria

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

Page 28: Boris Gurov Support Analyst Oracle Bulgaria

Recommended