SlideShare a Scribd company logo
<Insert Picture Here>
Effective Indexing
Thomas Kyte
http://asktom.oracle.com/
Who am I
• Been with Oracle since 1993
• User of Oracle since 1987
• The “Tom” behind AskTom in
Oracle Magazine
www.oracle.com/oramag
• Expert Oracle Database• Expert Oracle Database
Architecture
• Effective Oracle by Design
• Expert One on One Oracle
• Beginning Oracle
B*Tree
B*Tree
• What I call ‘conventional’ indexes
• Most common, some people might have only used this type
and nothing else
• Similar in implementation to a binary search tree
– Only not “binary” – they are N-ary, branches don’t go just left or
rightright
• Goal: minimize time to find small amounts of data
– Go ahead, define small
• Structurally they look like
0..50
51..100
101..150
….
10000.. 10050
0..10 51..58 10000.. 10009
Create index I on T(numColumn)
Lowest level
blocks are called
Leaf blocks
Contain every
indexed key and a
rowid
Interior blocks are
known as branch
blocks,
navigational
Leaf Nodes are
actually a doubly
linked list – once
we find where to
start – range
scanning is easyIt all starts with a
0..10
11..19
20..25
….
47.. 50
51..58
59..63
64..75
….
98.. 100
10000.. 10009
10010.. 10020
10021..10028
…
10046..10050
0,rowid
0,rowid
1,rowid
….
10,rowid
11,rowid
11,rowid
12,rowid
….
19,rowid
10046,rowid
10048,rowid
10048,rowid
….
10050,rowid
….
….
10021,rowid
10022,rowid
10023,rowid
….
10028,rowid ….
Leaf blocksrowid scanning is easyIt all starts with a
root block, root
could be all there
is
B*Tree Facts
• No such thing as a non-unique index under the covers
– Create index I on T(x,y) is sort of like Create UNIQUE index I on
T(x,y,rowid)
• All leaf blocks are at the same level
– Level is also known as the HEIGHT, BLEVEL (another metric
reported frequently) differs from height by one (does not count leafreported frequently) differs from height by one (does not count leaf
blocks)
– Any traversal from root to leaf takes the same number of IO’s
• Select indexed_col from T where indexed_col = :x will
take same number of IO’s regardless of the value of :x at
runtime.
– Most B*Trees will have a height of 2 or 3, even for millions of
records, for example
B*Tree Facts
ops$tkyte%ORA11GR1> create table t
2 as
3 select level x, level y
4 from dual
5 connect by level <= 10000000;
Table created.
ops$tkyte%ORA11GR1> alter table t add constraint t_pk primary key(x);
Table altered.
ops$tkyte%ORA11GR1> select index_name, blevel, num_rows
2 from user_indexes
3 where index_name = 'T_PK';
INDEX_NAME BLEVEL NUM_ROWS
------------------------------ ---------- ----------
T_PK 2 10000000
B*Tree Facts
ops$tkyte%ORA11GR1> set autotrace traceonly statistics
ops$tkyte%ORA11GR1> select x from t where x = 1;
3 consistent gets
ops$tkyte%ORA11GR1> select * from t where x = 1;
4 consistent gets
ops$tkyte%ORA11GR1> select x from t where x = 5000000;
3 consistent gets
ops$tkyte%ORA11GR1> select * from t where x = 5000000;
4 consistent gets
ops$tkyte%ORA11GR1> select x from t where x = 10000000;
3 consistent gets
ops$tkyte%ORA11GR1> select * from t where x = 10000000;
4 consistent gets
B*Tree Facts
• Index_stats is an important “V$” table
– Only one row
– Result of last validate structure
– Validate structure is an OFFLINE (blocking) operation
• Excellent General Purpose Indexing Mechanism
• Works well for small tables• Works well for small tables
• Works well for large tables
• Experiences little, if any, degradation in retrieval
performance as the size of the underlying table grows
• We’ll investigate when to use them shortly
– But first, compression and reverse key
Index_stats.sql
Index Key Compression
• Remove redundant leading edge values in index
keys
– Break key into “prefix” and “suffix”
– Repeating prefix values are not stored on leaf block –
only stored once
– Each leaf block is self contained– Each leaf block is self contained
– For example
Index Key Compression
• Index on t(owner,object_type,object_name)
(OPS$TKYTE, PROCEDURE, MAINTAIN_T, AAATM8AAEAAABV0AAP)(OPS$TKYTE, PROCEDURE,
P, AAATM8AAEAAABV0AAQ)(OPS$TKYTE, PROCEDURE, P1, AAATM8AAEAAABV0AAR)
(OPS$TKYTE, PROCEDURE, P2, AAATM8AAEAAABV0AAS) (OPS$TKYTE, PROCEDURE,
SHOW_SPACE, AAATM8AAEAAABV0AAT) (OPS$TKYTE, PROCEDURE, Y, AAATM8AAEAAABV0AAU)
(OPS$TKYTE, SEQUENCE, S, AAATM8AAEAAABV0AAV) (OPS$TKYTE, TABLE, ALL_DATA,
AAATM8AAEAAABV0AAW) (OPS$TKYTE, TABLE, AUDIT_TRAIL, AAATM8AAEAAABV0AAX)
(OPS$TKYTE, TABLE, BIND_DATA, AAATM8AAEAAABV0AAY) (OPS$TKYTE, TABLE, C,
AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa)
(OPS$TKYTE, PROCEDURE, MAINTAIN_T, AAATM8AAEAAABV0AAP)(OPS$TKYTE, PROCEDURE,
P, AAATM8AAEAAABV0AAQ)(OPS$TKYTE, PROCEDURE, P1, AAATM8AAEAAABV0AAR)
(OPS$TKYTE, PROCEDURE, P2, AAATM8AAEAAABV0AAS) (OPS$TKYTE, PROCEDURE,
SHOW_SPACE, AAATM8AAEAAABV0AAT) (OPS$TKYTE, PROCEDURE, Y, AAATM8AAEAAABV0AAU)
(OPS$TKYTE, SEQUENCE, S, AAATM8AAEAAABV0AAV) (OPS$TKYTE, TABLE, ALL_DATA,
AAATM8AAEAAABV0AAW) (OPS$TKYTE, TABLE, AUDIT_TRAIL, AAATM8AAEAAABV0AAX)
(OPS$TKYTE, TABLE, BIND_DATA, AAATM8AAEAAABV0AAY) (OPS$TKYTE, TABLE, C,
AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa)
(OPS$TKYTE, PROCEDURE, MAINTAIN_T, AAATM8AAEAAABV0AAP)(OPS$TKYTE, PROCEDURE,
P, AAATM8AAEAAABV0AAQ)(OPS$TKYTE, PROCEDURE, P1, AAATM8AAEAAABV0AAR)
(OPS$TKYTE, PROCEDURE, P2, AAATM8AAEAAABV0AAS) (OPS$TKYTE, PROCEDURE,
SHOW_SPACE, AAATM8AAEAAABV0AAT) (OPS$TKYTE, PROCEDURE, Y, AAATM8AAEAAABV0AAU)
(OPS$TKYTE, SEQUENCE, S, AAATM8AAEAAABV0AAV) (OPS$TKYTE, TABLE, ALL_DATA,
AAATM8AAEAAABV0AAW) (OPS$TKYTE, TABLE, AUDIT_TRAIL, AAATM8AAEAAABV0AAX)
(OPS$TKYTE, TABLE, BIND_DATA, AAATM8AAEAAABV0AAY) (OPS$TKYTE, TABLE, C,
AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa)
OPS$TKYTE, PROCEDURE (MAINTAIN_T, AAATM8AAEAAABV0AAP)(P,
AAATM8AAEAAABV0AAQ)(P1, AAATM8AAEAAABV0AAR) (P2, AAATM8AAEAAABV0AAS)
(SHOW_SPACE, AAATM8AAEAAABV0AAT) (Y, AAATM8AAEAAABV0AAU) OPS$TKYTE, SEQUENCE
(S, AAATM8AAEAAABV0AAV) OPS$TKYTE, TABLE (ALL_DATA, AAATM8AAEAAABV0AAW)
( AUDIT_TRAIL, AAATM8AAEAAABV0AAX) ( BIND_DATA, AAATM8AAEAAABV0AAY) ( C,
AAATM8AAEAAABV0AAZ) ( CHAINED_ROWS, AAATM8AAEAAABV0AAa) ( DBA_DATA,
AAATM8AAEAAABV0AAb) ( DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) ( EMP,
AAATM8AAEAAABV0AAd) ( EMPLOYEES, AAATM8AAEAAABV0AAe) ( GTT,
• Index on t(owner,object_type,object_name) compress 2
AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa)
(OPS$TKYTE, TABLE, DBA_DATA, AAATM8AAEAAABV0AAb) (OPS$TKYTE, TABLE,
DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) (OPS$TKYTE, TABLE, EMP,
AAATM8AAEAAABV0AAd) (OPS$TKYTE, TABLE, EMPLOYEES, AAATM8AAEAAABV0AAe)
(OPS$TKYTE, TABLE, GTT, AAATM8AAEAAABV0AAf) (OPS$TKYTE, TABLE, IOT,
AAATM8AAEAAABV0AAg) (OPS$TKYTE, TABLE, LINEITEMS, AAATM8AAEAAABV0AAh)
(OPS$TKYTE, TABLE, MV, AAATM8AAEAAABV0AAi) (OPS$TKYTE, TABLE, ORDERS,
AAATM8AAEAAABV0AAj) (OPS$TKYTE, TABLE, SELECT, AAATM8AAEAAABV0AAk)
(OPS$TKYTE, TABLE, T, AAATM8AAEAAABV0AAl) (OPS$TKYTE, TABLE, T1,
AAATM8AAEAAABV0AAm) (OPS$TKYTE, TABLE, T2, AAATM8AAEAAABV0AAn) (OPS$TKYTE,
TABLE, T3, AAATM8AAEAAABV0AAo) (OPS$TKYTE, TABLE, TEST_FA,
AAATM8AAEAAABV0AAp) (OPS$TKYTE, TABLE, TEST_LONG, AAATM8AAEAAABV0AAq)
(OPS$TKYTE, TABLE, USER_DATA, AAATM8AAEAAABV0AAr)
AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa)
(OPS$TKYTE, TABLE, DBA_DATA, AAATM8AAEAAABV0AAb) (OPS$TKYTE, TABLE,
DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) (OPS$TKYTE, TABLE, EMP,
AAATM8AAEAAABV0AAd) (OPS$TKYTE, TABLE, EMPLOYEES, AAATM8AAEAAABV0AAe)
(OPS$TKYTE, TABLE, GTT, AAATM8AAEAAABV0AAf) (OPS$TKYTE, TABLE, IOT,
AAATM8AAEAAABV0AAg) (OPS$TKYTE, TABLE, LINEITEMS, AAATM8AAEAAABV0AAh)
(OPS$TKYTE, TABLE, MV, AAATM8AAEAAABV0AAi) (OPS$TKYTE, TABLE, ORDERS,
AAATM8AAEAAABV0AAj) (OPS$TKYTE, TABLE, SELECT, AAATM8AAEAAABV0AAk) (OPS$TKYTE,
TABLE, T, AAATM8AAEAAABV0AAl) (OPS$TKYTE, TABLE, T1, AAATM8AAEAAABV0AAm)
(OPS$TKYTE, TABLE, T2, AAATM8AAEAAABV0AAn) (OPS$TKYTE, TABLE, T3,
AAATM8AAEAAABV0AAo) (OPS$TKYTE, TABLE, TEST_FA, AAATM8AAEAAABV0AAp)
(OPS$TKYTE, TABLE, TEST_LONG, AAATM8AAEAAABV0AAq) (OPS$TKYTE, TABLE,
USER_DATA, AAATM8AAEAAABV0AAr)
AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa)
(OPS$TKYTE, TABLE, DBA_DATA, AAATM8AAEAAABV0AAb) (OPS$TKYTE, TABLE,
DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) (OPS$TKYTE, TABLE, EMP,
AAATM8AAEAAABV0AAd) (OPS$TKYTE, TABLE, EMPLOYEES, AAATM8AAEAAABV0AAe)
(OPS$TKYTE, TABLE, GTT, AAATM8AAEAAABV0AAf) (OPS$TKYTE, TABLE, IOT,
AAATM8AAEAAABV0AAg) (OPS$TKYTE, TABLE, LINEITEMS, AAATM8AAEAAABV0AAh)
(OPS$TKYTE, TABLE, MV, AAATM8AAEAAABV0AAi) (OPS$TKYTE, TABLE, ORDERS,
AAATM8AAEAAABV0AAj) (OPS$TKYTE, TABLE, SELECT, AAATM8AAEAAABV0AAk)
(OPS$TKYTE, TABLE, T, AAATM8AAEAAABV0AAl) (OPS$TKYTE, TABLE, T1,
AAATM8AAEAAABV0AAm) (OPS$TKYTE, TABLE, T2, AAATM8AAEAAABV0AAn) (OPS$TKYTE,
TABLE, T3, AAATM8AAEAAABV0AAo) (OPS$TKYTE, TABLE, TEST_FA,
AAATM8AAEAAABV0AAp) (OPS$TKYTE, TABLE, TEST_LONG, AAATM8AAEAAABV0AAq)
(OPS$TKYTE, TABLE, USER_DATA, AAATM8AAEAAABV0AAr)
AAATM8AAEAAABV0AAd) ( EMPLOYEES, AAATM8AAEAAABV0AAe) ( GTT,
AAATM8AAEAAABV0AAf) ( IOT, AAATM8AAEAAABV0AAg) ( LINEITEMS,
AAATM8AAEAAABV0AAh) ( MV, AAATM8AAEAAABV0AAi) ( ORDERS, AAATM8AAEAAABV0AAj)
( SELECT, AAATM8AAEAAABV0AAk) ( T, AAATM8AAEAAABV0AAl) ( T1,
AAATM8AAEAAABV0AAm) ( T2, AAATM8AAEAAABV0AAn) ( T3, AAATM8AAEAAABV0AAo)
( TEST_FA, AAATM8AAEAAABV0AAp) ( TEST_LONG, AAATM8AAEAAABV0AAq) (USER_DATA,
AAATM8AAEAAABV0AAr)
Index Key Compression
• Some Facts
– Available with Oracle8i R1 (version 8.1.5) and above
– Index probably consumes less disk space
– Can reduce I/Os on the system -- both physical and
logical
– Can improve buffer cache efficiency, there is less to– Can improve buffer cache efficiency, there is less to
cache
– May increase contention as there are now more rows
per leaf block
– May require increased CPU to access
Indc.sql
Indc2.sql
B*Tree
When to useWhen to use
B*Tree When to use
• I do not like rules of thumb (ROT)
• Why? Consider these two – both are valid:
– Use a B*Tree index to index columns if you are going to access a
very small number of the rows in the table via the index.
– Use a B*Tree index if you are going to process many/most/all of
the rows in a table via the index
– They conflict – but they are both valid– They conflict – but they are both valid
– Discuss
• What is small
• What is initial response versus total throughput about
• What about when the index can be used instead of the table
• I like to understand how something works – and use that to
decide
B*Tree When to use
• So, the ‘rules are’
– As the means to access rows in a table: You will read the index
to get to a row in the table. Here you want to access a very small
number of the rows in the table.
– As the means to answer a query: The index contains enough
information to answer the entire query—we will not have to go to
the table at all. The index will be used as a “thinner” version of thethe table at all. The index will be used as a “thinner” version of the
table.
– As the means to optimize for initial response time: You want to
retrieve all of the rows in a table, including columns that are not in
the index itself – in some sorted order – the index will possibly
allow for immediate response (but slower overall throughput).
B*Tree When to use
• Organization counts
– Index on primary key populated by sequence/SYSDATE.
• Data in table is mostly sorted by sequence/SYSDATE
• Data in index is sorted by sequence/SYSDATE.
• Index very efficient for range scans
• But, how often do you range scan on a primary key populated
by sequence?by sequence?
• How often by date range?
– Index on LAST_NAME
• Data in table is randomly organized (your don’t hire everyone
with a last name of ‘A%’ on the same day)
• Data in index is sorted
• Index is not efficient for large range scans
o It would skip all around in the table
B*Tree When to use
• Enter the CLUSTERING FACTOR
– A measure of how sorted the table is by the key in the
index
– It measures how many IO’s it would take to read the
entire table via the index – row after row after row
– If table is sorted by key, clustering factor near number
of blocks in the table.
– If table is not sorted by key, clustering factor nearer
number of ROWS in table.
– Please ask yourself, how many ways can the table be
sorted on disk?
cf.sql
2 total IO’S
Against the
Table
0..50
51..100
101..150
….
10000.. 10050
0..10
11..19
20..25
….
47.. 50
51..58
59..63
64..75
….
98.. 100
10000.. 10009
10010.. 10020
10021..10028
…
10046..10050
….
Create index nm_idx on name)
Select * from t where pk between 1 and 8
1,Alice
2,Bob
3,Candy
4,Doug
5,Ellen
6,Frank
7,George
8,Hank
….
….
….
….
….
… …
…
…
…
….
Pk Name
1 Alice
2 Sue
3 Victor
4 Will
Pk Name
5 Irene
6 Kelly
7 Melanie
8 Oliver
Pk Name
9 George
10 Candy
11 Uwe
12 Wally
Pk Name
13 Ellen
14 Tom
15 Rick
16 Paul
Pk Name
17 Doug
18 Irene
19 Lance
20 Jack
Pk Name
21 Hank
22 Frank
23 Nicole
24 Bob
0..50
51..100
101..150
….
10000.. 10050
0..10
11..19
20..25
….
47.. 50
51..58
59..63
64..75
….
98.. 100
10000.. 10009
10010.. 10020
10021..10028
…
10046..10050
….
Create index nm_idx on name)
Select * from t where Name between ‘Alice’ and ‘Hank’
8 total IO’S
Against the
Table
cf.sql
1,Alice
2,Bob
3,Candy
4,Doug
5,Ellen
6,Frank
7,George
8,Hank
….
….
….
….
….
… …
…
…
…
….
Pk Name
1 Alice
2 Sue
3 Victor
4 Will
Pk Name
5 Irene
6 Kelly
7 Melanie
8 Oliver
Pk Name
9 George
10 Candy
11 Uwe
12 Wally
Pk Name
13 Ellen
14 Tom
15 Rick
16 Paul
Pk Name
17 Doug
18 Irene
19 Lance
20 Jack
Pk Name
21 Hank
22 Frank
23 Nicole
24 Bob
B*Tree in summary
• Most common
• Well understood (and mis-understood!)
• Very scalable access times
– To return a row from a 1,000 row index takes about as
much work as from a 10,000,000 row indexmuch work as from a 10,000,000 row index
• Indexing should be thought of as a design time
thing
• You might index to retrieve a few rows, all rows, or
to avoid the table in the first place
Bitmap
Bitmap Index
• Introduced in version 7.3, EE
• Designed for read mostly or read only application
• Specifically not designed or usable with OLTP
tables
– Tables undergoing concurrent modification– Tables undergoing concurrent modification
– Tables undergoing single row modifications
• A single bitmap key entry points to many rows
– In contrast to b*tree where there is a 1:1 relation
between keys in the index and rows in the table
bm1.sql
Bitmap Index – bitwise operations
JOB BITS
--------- ------------------------------
ANALYST 0-0-0-0-0-0-0-1-0-0-0-0-1-0
CLERK 1-0-0-0-0-0-0-0-0-0-1-1-0-1
MANAGER 0-0-0-1-0-1-1-0-0-0-0-0-0-0
PRESIDENT 0-0-0-0-0-0-0-0-1-0-0-0-0-0PRESIDENT 0-0-0-0-0-0-0-0-1-0-0-0-0-0
SALESMAN 0-1-1-0-1-0-0-0-0-1-0-0-0-0
CLERK OR 1-0-0-1-0-1-1-0-0-0-1-1-0-1
MANAGER
CLERK AND 0-0-0-0-0-0-0-0-0-0-0-0-0-0
MANAGER
Bitmap Index – structure
JOB LO-ROWID HI-ROWID BITS
--------- -------- -------- --------------------------
ANALYST AAAR4AAA AAABEEAAH 0-0-0-0-0-0-0-1-0-0-0-0-1-0
ANALYST AAAR4AAB AAABEEAAM 1-0-0-0-0-0-0-0-0-0-1-1-0-1
ANALYST AAAR4AAC AAABEEAAN 0-0-0-1-0-1-1
PRESIDENT AAAR4AAA AAABEEAAI 0-0-0-0-0-0-0-0-1-0-0-0-0-0
PRESIDENT AAAR4AAX AAABEEAAC 0-1-1-0-1-0-0-0-0-1-0-0-0-0
PRESIDENT AAAR4AAY AAABEEAAJ 1-0-1-0-0-1-1
• Key + Lo Rowid – Hi Rowid + Bitmap
• 0’s and 1’s map to rowids in that range
• If we know max number of rows/block – simple math
• alter table emp minimize records_per_block;
• Note the multiple entries per JOB!
Bitmap Index
• Can answer questions like:
– How many of this match (count 0’s and 1’s)
– How many of this that or the other thing match
• Bitwise and/or bitmaps
• Count 0’s and 1’s• Count 0’s and 1’s
– Good for accessing a few rows (just like B*Tree)
– Good for counting, identifying many, all, some of the
rows (just like B*Tree)
Bitmap Index - when
• Most common rule of thumb going is “low distinct
cardinality”
• Now, I defy you to define “low distinct cardinality”
– Is 2 “low distinct cardinality”?
– Yes it is
– No it isn’t
– It depends
• In pure ad-hoc, even high distinct cardinality
columns could/should be considered for bitmaps
• Consider
Bitmap Index - when
• How many men in regions 1, 10 and 30 are there in the 41
and over age group?
• How many men in region 20 or women in region 22 are 18
and under?
• How many people are in regions 11, 20 or 30
• How many over 41 year olds are there that are women?• How many over 41 year olds are there that are women?
• Etc etc etc
• Now, come up with an indexing scheme using B*Trees for
that
• And then maintain it as the questions change (and change
and change)
bm2.sql
Function Based
Function Based Indexes
• Added in Oracle 8i release 1 (8.1.5) as a feature of
EE and PE
• In 9i, a feature of SE, EE and PE
• Great for
– Case insensitive searches/sorts– Case insensitive searches/sorts
– Searching on derived attributes -- complex formulas
• Provide immediate, transparent value to the
application
• Function you index must be “pure” - deterministic
pure.sql
• Thinking outside the box with FBI's
– Two facts
• B*Tree indexes will never have an entirely NULL
entry. If the entire key is NULL, it will not be placed
in the B*Tree
• We have function based indexes that allow us to
Function Based Indexes
• We have function based indexes that allow us to
incorporate complex, procedural logic in them
– We can solve common problems
• Indexing only some of the rows in a table (like
indexing a where clause)
• Enforcing complex integrity in the database
• Using an index for “where column is null”
• Selective Indexing
– You have a table with a flag column
– You want to index this column when the flag = 'x'
– A small % of the table is accessed by this values
– Sounds like what you've read about bitmap indexes but
• This table is modified all day long
Function Based Indexes
• This table is modified all day long
• Bitmaps would kill concurrency
• The bitmap would grow to outrageous sizes quickly
– The answer -- a function based index
• Or a better model
• Or a better structure (AQ) fbi.sql
• Selective Uniqueness
– You have a table with versioned information in it
• A project table with status "ACTIVE" and
"INACTIVE"
– When status is "ACTIVE", some set of columns must be
unique
Function Based Indexes
unique
– When status is "INACTIVE", those columns may
contain any values -- any number of duplicates
– How can you do it?
selind.sql
• Where column is NULL
– Nulls are not indexed right?
– Wrong – entirely NULL key entries are not, but if *any*
bit of a concatenated index is not null Entry is made.
• Fear no longer the NULL value!
Function Based Indexes
null.sql
Mythology
And other interestingAnd other interesting
anti-facts and facts
• Do nulls and indexes work together?
– Obviously, we’ve seen an example with FBI’s
– Bitmap indexes – always index nulls.
– B*Tree cluster indexes – always index nulls.
– Conventional B*Tree indexes do not if and only if the
entire key is null (all of the columns)
Mythology
entire key is null (all of the columns)
• Why is that? See null2.sql
null2.sql
• Do I need to index foreign keys?
– Probably
– If you
• Update the parent table primary key OR
• Delete from parent OR
• Merge into parent
– 9i and later – lock taken on child table for duration of update or
Mythology
– 9i and later – lock taken on child table for duration of update or
delete
• Which could take long since the table lock gets blocked,
blocking others
• Which could take long due to full scan of child, since there is no
index!
– 8i and before – lock taken for duration of transaction
fkey.sql
• Maybe we are not using the leading edge?
• Create index I on T(x,y)
– Where y = value will tend to not use the index
– Unless
• We index skip scan
• We select x,y from t where y = value – and we use
Mythology – why isn’t it using my index
• We select x,y from t where y = value – and we use
the index I as a skinny table to full scan
case1.sql
• Select count(*) from t
• Full scanning table, not using any existing index
• Two causes
– You are still using the RBO
– None of the columns indexed was defined “NOT NULL”
Mythology – why isn’t it using my index
• Select * from table where indexed_column = value
• Indexed column is on the leading edge
• No index being used
• Likely an implicit conversion
Mythology – why isn’t it using my index
case2.sql
• This is my favorite one
• Because if the index were to be used, the query
would run incredibly slow.
• Remember:
– Loop
Mythology – why isn’t it using my index
• Say indexes are not all goodness
• Say full scans are not evil
• Exit when (you really believe it)
– End loop
• Following example from asktom..
So, joe (or josephine) sql coder needs to run the following query:
select t1.object_name, t2.object_name
from t t1, t t2
where t1.object_id = t2.object_id
and t1.owner = 'WMSYS'
Rows Row Source Operation
Mythology – why isn’t it using my index
Rows Row Source Operation
------- ---------------------------------------------------
528384 HASH JOIN
8256 TABLE ACCESS FULL T
1833856 TABLE ACCESS FULL T
suppose they ran it or explain planned it -- and saw that plan. "Stupid
stupid CBO" they say -- "I have indexes, why won't it use them. We all know
that indexes mean fast=true! Ok, let me use the faithful RBO and see what
happens"
select /*+ RULE */ t1.object_name, t2.object_name
from t t1, t t2
where t1.object_id = t2.object_id
and t1.owner = 'WMSYS'
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=HINT: RULE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T'
Mythology – why isn’t it using my index
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T'
2 1 NESTED LOOPS
3 2 TABLE ACCESS (FULL) OF 'T'
4 2 INDEX (RANGE SCAN) OF 'T_IDX' (NON-UNIQUE)
See, now that’s what I’m talking about – indexes are good…
Or are they?
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 35227 5.63 9.32 23380 59350 0 528384
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 35229 5.63 9.33 23380 59350 0 528384
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Mythology – why isn’t it using my index
Optimizer goal: CHOOSE
Parsing user id: 80
Rows Row Source Operation
------- ---------------------------------------------------
528384 HASH JOIN
8256 TABLE ACCESS FULL T
1833856 TABLE ACCESS FULL T
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 35227 912.07 3440.70 1154555 121367981 0 528384
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 35229 912.07 3440.70 1154555 121367981 0 528384
Misses in library cache during parse: 0
Optimizer goal: RULE
Mythology – why isn’t it using my index
Optimizer goal: RULE
Parsing user id: 80
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=HINT: RULE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T'
2 1 NESTED LOOPS
3 2 TABLE ACCESS (FULL) OF 'T'
4 2 INDEX (RANGE SCAN) OF 'T_IDX' (NON-UNIQUE)
1 SELECT phy.value,
2 cur.value,
3 con.value,
4 1-((phy.value)/((cur.value)+(con.value))) "Cache hit ratio"
5 FROM v$sysstat cur, v$sysstat con, v$sysstat phy
6 WHERE cur.name='db block gets'
7 AND con.name='consistent gets'
8* AND phy.name='physical reads'
Mythology – why isn’t it using my index
VALUE VALUE VALUE Cache hit ratio
-------- ---------- ---------- ---------------
1277377 58486 121661490 .989505609
98.9% cache hit, not bad eh?
• Space is never reused in an index
– Indexes are a complex data structures
– Data has a location
• If you insert monotonically increasing values
(1,2,3, )
• And you delete many – not all, many – of the older
values over time (1,3,5,7, .)
Mythology
values over time (1,3,5,7, .)
• Then, since the value 123456 does not fit “near” the
value 2 – that space won’t be reused (the block that
2 is on)
• But indexes on say “last name” or a reverse key
index
• Most discriminating elements should go first
– Say you have copy of all objects
– You ask
• What does scott own?
• What tables does scott own?
• What about that EMP table scott owns?
Mythology
• What about that EMP table scott owns?
– The only sensible index would be on
(owner,object_type,object_name).
– Object_name is the most ‘discriminating’
– Object_name would be the worst thing to put first
– How you query the data dictates the ordering
order.sql
• NOSEGMENT
– What would happen to my plan if I created this index?
– Would the optimizer likely choose to use it?
– ALTER SESSION SET “_use_nosegment_indexes” =
true;
– Dbms_stats.set_index_stats with your best guess might
Interesting
– Dbms_stats.set_index_stats with your best guess might
be necessary
nosegment.sql
• INVISIBLE
– What would happen to my plan if I created this index?
– Would the optimizer likely choose to use it?
– Invisible indexes actually
• Create the index
• Maintain the index
Interesting – but wait, there’s more!
• Maintain the index
• But keep the index from the optimizers view!
• alter session set
OPTIMIZER_USE_INVISIBLE_INDEXES =true;
invisible.sql
• Where string like ‘%stuff’
– B*tree – nope
– Bitmap – nope
– Text – yes
• Indexes the substrings
• Case insensitive even
Interesting – and inclosing
• Case insensitive even
• Everyone has it
leading.sql
<Insert Picture Here>
AQ&AQ&

More Related Content

What's hot

Oracle eCommerce (ATG) Database Best Practices
Oracle eCommerce (ATG) Database  Best Practices Oracle eCommerce (ATG) Database  Best Practices
Oracle eCommerce (ATG) Database Best Practices
Kate Semizhon
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
Nicole Ryan
 
Dramatically increase your database's performance using hierarchical and recu...
Dramatically increase your database's performance using hierarchical and recu...Dramatically increase your database's performance using hierarchical and recu...
Dramatically increase your database's performance using hierarchical and recu...
rcmoutinho
 
Sql functions
Sql functionsSql functions
Sql functions
ilias ahmed
 
Postgres rules
Postgres rulesPostgres rules
Postgres rules
gisborne
 
MY SQL
MY SQLMY SQL
MY SQL
sundar
 
Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011
David Fetter
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
Shubham Shukla
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releases
Georgi Sotirov
 

What's hot (11)

Les10
Les10Les10
Les10
 
Oracle eCommerce (ATG) Database Best Practices
Oracle eCommerce (ATG) Database  Best Practices Oracle eCommerce (ATG) Database  Best Practices
Oracle eCommerce (ATG) Database Best Practices
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
 
Dramatically increase your database's performance using hierarchical and recu...
Dramatically increase your database's performance using hierarchical and recu...Dramatically increase your database's performance using hierarchical and recu...
Dramatically increase your database's performance using hierarchical and recu...
 
Sql functions
Sql functionsSql functions
Sql functions
 
Postgres rules
Postgres rulesPostgres rules
Postgres rules
 
MY SQL
MY SQLMY SQL
MY SQL
 
Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011Writeable ct es_pgcon_may_2011
Writeable ct es_pgcon_may_2011
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
Sql Tags
Sql TagsSql Tags
Sql Tags
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releases
 

Viewers also liked

Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfInSync2011
 
Embase: An introduction to indexing 20 October 2014
Embase: An introduction to indexing 20 October 2014Embase: An introduction to indexing 20 October 2014
Embase: An introduction to indexing 20 October 2014
Ann-Marie Roche
 
Last But Not Least - Managing The Indexing Process
Last But Not Least  - Managing The Indexing ProcessLast But Not Least  - Managing The Indexing Process
Last But Not Least - Managing The Indexing Process
Fred Leise
 
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfInSync2011
 
imr504 classification and filing system week 3
imr504 classification and filing system week 3imr504 classification and filing system week 3
imr504 classification and filing system week 3
Ahmad Shahir Mohamed Jalil
 
imr504 classification and filing system week 1
imr504 classification and filing system week 1imr504 classification and filing system week 1
imr504 classification and filing system week 1
Ahmad Shahir Mohamed Jalil
 
Introduction to indexing
Introduction to indexingIntroduction to indexing
Introduction to indexingDaryl Superio
 
Introduction to indexing (presentation1)
Introduction to indexing (presentation1)Introduction to indexing (presentation1)
Introduction to indexing (presentation1)Mary May Porto
 
Chain indexing
Chain indexingChain indexing
Chain indexingsilambu111
 
5013 Indexing Presentation
5013 Indexing Presentation5013 Indexing Presentation
5013 Indexing Presentation
lmartin8
 
Indexing or dividing_head
Indexing or dividing_headIndexing or dividing_head
Indexing or dividing_headJavaria Chiragh
 
What is Document Indexing? A tutorial for intelligent data capture.
What is Document Indexing? A tutorial for intelligent data capture.What is Document Indexing? A tutorial for intelligent data capture.
What is Document Indexing? A tutorial for intelligent data capture.
DocuFi, offering HAI and Infection Prevention Analytics
 

Viewers also liked (16)

Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
 
Indexing report
Indexing reportIndexing report
Indexing report
 
Embase: An introduction to indexing 20 October 2014
Embase: An introduction to indexing 20 October 2014Embase: An introduction to indexing 20 October 2014
Embase: An introduction to indexing 20 October 2014
 
Indexing Present1
Indexing Present1Indexing Present1
Indexing Present1
 
Last But Not Least - Managing The Indexing Process
Last But Not Least  - Managing The Indexing ProcessLast But Not Least  - Managing The Indexing Process
Last But Not Least - Managing The Indexing Process
 
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
 
imr504 classification and filing system week 3
imr504 classification and filing system week 3imr504 classification and filing system week 3
imr504 classification and filing system week 3
 
imr504 classification and filing system week 1
imr504 classification and filing system week 1imr504 classification and filing system week 1
imr504 classification and filing system week 1
 
Introduction to indexing
Introduction to indexingIntroduction to indexing
Introduction to indexing
 
Introduction to indexing (presentation1)
Introduction to indexing (presentation1)Introduction to indexing (presentation1)
Introduction to indexing (presentation1)
 
Chain indexing
Chain indexingChain indexing
Chain indexing
 
5013 Indexing Presentation
5013 Indexing Presentation5013 Indexing Presentation
5013 Indexing Presentation
 
Indexing
IndexingIndexing
Indexing
 
Indexing or dividing_head
Indexing or dividing_headIndexing or dividing_head
Indexing or dividing_head
 
Indexing
IndexingIndexing
Indexing
 
What is Document Indexing? A tutorial for intelligent data capture.
What is Document Indexing? A tutorial for intelligent data capture.What is Document Indexing? A tutorial for intelligent data capture.
What is Document Indexing? A tutorial for intelligent data capture.
 

Similar to [INSIGHT OUT 2011] B24 effective indexing(tom kyte)

MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB plc
 
What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3
MariaDB plc
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Mattersafa reg
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
oysteing
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
PRAKHAR JHA
 
Lecture_5_Stack.pptx
Lecture_5_Stack.pptxLecture_5_Stack.pptx
Lecture_5_Stack.pptx
LabibHossain5
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table ExpressionsMySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
oysteing
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10Umair Amjad
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricksYanli Liu
 
Most useful queries
Most useful queriesMost useful queries
Most useful queriesSam Depp
 
Appendix A Tables
Appendix A   TablesAppendix A   Tables
Appendix A TablesLiquidHub
 
6. list
6. list6. list

Similar to [INSIGHT OUT 2011] B24 effective indexing(tom kyte) (20)

MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
 
What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3
 
Writeable CTEs: The Next Big Thing
Writeable CTEs: The Next Big ThingWriteable CTEs: The Next Big Thing
Writeable CTEs: The Next Big Thing
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
Lecture_5_Stack.pptx
Lecture_5_Stack.pptxLecture_5_Stack.pptx
Lecture_5_Stack.pptx
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table ExpressionsMySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
Most useful queries
Most useful queriesMost useful queries
Most useful queries
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql1
Mysql1Mysql1
Mysql1
 
Appendix A Tables
Appendix A   TablesAppendix A   Tables
Appendix A Tables
 
6. list
6. list6. list
6. list
 

More from Insight Technology, Inc.

グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?
Insight Technology, Inc.
 
Docker and the Oracle Database
Docker and the Oracle DatabaseDocker and the Oracle Database
Docker and the Oracle Database
Insight Technology, Inc.
 
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Insight Technology, Inc.
 
事例を通じて機械学習とは何かを説明する
事例を通じて機械学習とは何かを説明する事例を通じて機械学習とは何かを説明する
事例を通じて機械学習とは何かを説明する
Insight Technology, Inc.
 
仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン
仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン
仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン
Insight Technology, Inc.
 
MBAAで覚えるDBREの大事なおしごと
MBAAで覚えるDBREの大事なおしごとMBAAで覚えるDBREの大事なおしごと
MBAAで覚えるDBREの大事なおしごと
Insight Technology, Inc.
 
グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?
Insight Technology, Inc.
 
DBREから始めるデータベースプラットフォーム
DBREから始めるデータベースプラットフォームDBREから始めるデータベースプラットフォーム
DBREから始めるデータベースプラットフォーム
Insight Technology, Inc.
 
SQL Server エンジニアのためのコンテナ入門
SQL Server エンジニアのためのコンテナ入門SQL Server エンジニアのためのコンテナ入門
SQL Server エンジニアのためのコンテナ入門
Insight Technology, Inc.
 
Lunch & Learn, AWS NoSQL Services
Lunch & Learn, AWS NoSQL ServicesLunch & Learn, AWS NoSQL Services
Lunch & Learn, AWS NoSQL Services
Insight Technology, Inc.
 
db tech showcase2019オープニングセッション @ 森田 俊哉
db tech showcase2019オープニングセッション @ 森田 俊哉 db tech showcase2019オープニングセッション @ 森田 俊哉
db tech showcase2019オープニングセッション @ 森田 俊哉
Insight Technology, Inc.
 
db tech showcase2019 オープニングセッション @ 石川 雅也
db tech showcase2019 オープニングセッション @ 石川 雅也db tech showcase2019 オープニングセッション @ 石川 雅也
db tech showcase2019 オープニングセッション @ 石川 雅也
Insight Technology, Inc.
 
db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー
db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー
db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー
Insight Technology, Inc.
 
難しいアプリケーション移行、手軽に試してみませんか?
難しいアプリケーション移行、手軽に試してみませんか?難しいアプリケーション移行、手軽に試してみませんか?
難しいアプリケーション移行、手軽に試してみませんか?
Insight Technology, Inc.
 
Attunityのソリューションと異種データベース・クラウド移行事例のご紹介
Attunityのソリューションと異種データベース・クラウド移行事例のご紹介Attunityのソリューションと異種データベース・クラウド移行事例のご紹介
Attunityのソリューションと異種データベース・クラウド移行事例のご紹介
Insight Technology, Inc.
 
そのデータベース、クラウドで使ってみませんか?
そのデータベース、クラウドで使ってみませんか?そのデータベース、クラウドで使ってみませんか?
そのデータベース、クラウドで使ってみませんか?
Insight Technology, Inc.
 
コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...
コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...
コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...
Insight Technology, Inc.
 
複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。
複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。 複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。
複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。
Insight Technology, Inc.
 
Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...
Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...
Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...
Insight Technology, Inc.
 
レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]
レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]
レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]
Insight Technology, Inc.
 

More from Insight Technology, Inc. (20)

グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?
 
Docker and the Oracle Database
Docker and the Oracle DatabaseDocker and the Oracle Database
Docker and the Oracle Database
 
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
Great performance at scale~次期PostgreSQL12のパーティショニング性能の実力に迫る~
 
事例を通じて機械学習とは何かを説明する
事例を通じて機械学習とは何かを説明する事例を通じて機械学習とは何かを説明する
事例を通じて機械学習とは何かを説明する
 
仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン
仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン
仮想通貨ウォレットアプリで理解するデータストアとしてのブロックチェーン
 
MBAAで覚えるDBREの大事なおしごと
MBAAで覚えるDBREの大事なおしごとMBAAで覚えるDBREの大事なおしごと
MBAAで覚えるDBREの大事なおしごと
 
グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?グラフデータベースは如何に自然言語を理解するか?
グラフデータベースは如何に自然言語を理解するか?
 
DBREから始めるデータベースプラットフォーム
DBREから始めるデータベースプラットフォームDBREから始めるデータベースプラットフォーム
DBREから始めるデータベースプラットフォーム
 
SQL Server エンジニアのためのコンテナ入門
SQL Server エンジニアのためのコンテナ入門SQL Server エンジニアのためのコンテナ入門
SQL Server エンジニアのためのコンテナ入門
 
Lunch & Learn, AWS NoSQL Services
Lunch & Learn, AWS NoSQL ServicesLunch & Learn, AWS NoSQL Services
Lunch & Learn, AWS NoSQL Services
 
db tech showcase2019オープニングセッション @ 森田 俊哉
db tech showcase2019オープニングセッション @ 森田 俊哉 db tech showcase2019オープニングセッション @ 森田 俊哉
db tech showcase2019オープニングセッション @ 森田 俊哉
 
db tech showcase2019 オープニングセッション @ 石川 雅也
db tech showcase2019 オープニングセッション @ 石川 雅也db tech showcase2019 オープニングセッション @ 石川 雅也
db tech showcase2019 オープニングセッション @ 石川 雅也
 
db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー
db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー
db tech showcase2019 オープニングセッション @ マイナー・アレン・パーカー
 
難しいアプリケーション移行、手軽に試してみませんか?
難しいアプリケーション移行、手軽に試してみませんか?難しいアプリケーション移行、手軽に試してみませんか?
難しいアプリケーション移行、手軽に試してみませんか?
 
Attunityのソリューションと異種データベース・クラウド移行事例のご紹介
Attunityのソリューションと異種データベース・クラウド移行事例のご紹介Attunityのソリューションと異種データベース・クラウド移行事例のご紹介
Attunityのソリューションと異種データベース・クラウド移行事例のご紹介
 
そのデータベース、クラウドで使ってみませんか?
そのデータベース、クラウドで使ってみませんか?そのデータベース、クラウドで使ってみませんか?
そのデータベース、クラウドで使ってみませんか?
 
コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...
コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...
コモディティサーバー3台で作る高速処理 “ハイパー・コンバージド・データベース・インフラストラクチャー(HCDI)” システム『Insight Qube』...
 
複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。
複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。 複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。
複数DBのバックアップ・切り戻し運用手順が異なって大変?!運用性の大幅改善、その先に。。
 
Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...
Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...
Attunity社のソリューションの日本国内外適用事例及びロードマップ紹介[ATTUNITY & インサイトテクノロジー IoT / Big Data フ...
 
レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]
レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]
レガシーに埋もれたデータをリアルタイムでクラウドへ [ATTUNITY & インサイトテクノロジー IoT / Big Data フォーラム 2018]
 

Recently uploaded

Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

[INSIGHT OUT 2011] B24 effective indexing(tom kyte)

  • 1. <Insert Picture Here> Effective Indexing Thomas Kyte http://asktom.oracle.com/
  • 2. Who am I • Been with Oracle since 1993 • User of Oracle since 1987 • The “Tom” behind AskTom in Oracle Magazine www.oracle.com/oramag • Expert Oracle Database• Expert Oracle Database Architecture • Effective Oracle by Design • Expert One on One Oracle • Beginning Oracle
  • 4. B*Tree • What I call ‘conventional’ indexes • Most common, some people might have only used this type and nothing else • Similar in implementation to a binary search tree – Only not “binary” – they are N-ary, branches don’t go just left or rightright • Goal: minimize time to find small amounts of data – Go ahead, define small • Structurally they look like
  • 5. 0..50 51..100 101..150 …. 10000.. 10050 0..10 51..58 10000.. 10009 Create index I on T(numColumn) Lowest level blocks are called Leaf blocks Contain every indexed key and a rowid Interior blocks are known as branch blocks, navigational Leaf Nodes are actually a doubly linked list – once we find where to start – range scanning is easyIt all starts with a 0..10 11..19 20..25 …. 47.. 50 51..58 59..63 64..75 …. 98.. 100 10000.. 10009 10010.. 10020 10021..10028 … 10046..10050 0,rowid 0,rowid 1,rowid …. 10,rowid 11,rowid 11,rowid 12,rowid …. 19,rowid 10046,rowid 10048,rowid 10048,rowid …. 10050,rowid …. …. 10021,rowid 10022,rowid 10023,rowid …. 10028,rowid …. Leaf blocksrowid scanning is easyIt all starts with a root block, root could be all there is
  • 6. B*Tree Facts • No such thing as a non-unique index under the covers – Create index I on T(x,y) is sort of like Create UNIQUE index I on T(x,y,rowid) • All leaf blocks are at the same level – Level is also known as the HEIGHT, BLEVEL (another metric reported frequently) differs from height by one (does not count leafreported frequently) differs from height by one (does not count leaf blocks) – Any traversal from root to leaf takes the same number of IO’s • Select indexed_col from T where indexed_col = :x will take same number of IO’s regardless of the value of :x at runtime. – Most B*Trees will have a height of 2 or 3, even for millions of records, for example
  • 7. B*Tree Facts ops$tkyte%ORA11GR1> create table t 2 as 3 select level x, level y 4 from dual 5 connect by level <= 10000000; Table created. ops$tkyte%ORA11GR1> alter table t add constraint t_pk primary key(x); Table altered. ops$tkyte%ORA11GR1> select index_name, blevel, num_rows 2 from user_indexes 3 where index_name = 'T_PK'; INDEX_NAME BLEVEL NUM_ROWS ------------------------------ ---------- ---------- T_PK 2 10000000
  • 8. B*Tree Facts ops$tkyte%ORA11GR1> set autotrace traceonly statistics ops$tkyte%ORA11GR1> select x from t where x = 1; 3 consistent gets ops$tkyte%ORA11GR1> select * from t where x = 1; 4 consistent gets ops$tkyte%ORA11GR1> select x from t where x = 5000000; 3 consistent gets ops$tkyte%ORA11GR1> select * from t where x = 5000000; 4 consistent gets ops$tkyte%ORA11GR1> select x from t where x = 10000000; 3 consistent gets ops$tkyte%ORA11GR1> select * from t where x = 10000000; 4 consistent gets
  • 9. B*Tree Facts • Index_stats is an important “V$” table – Only one row – Result of last validate structure – Validate structure is an OFFLINE (blocking) operation • Excellent General Purpose Indexing Mechanism • Works well for small tables• Works well for small tables • Works well for large tables • Experiences little, if any, degradation in retrieval performance as the size of the underlying table grows • We’ll investigate when to use them shortly – But first, compression and reverse key Index_stats.sql
  • 10. Index Key Compression • Remove redundant leading edge values in index keys – Break key into “prefix” and “suffix” – Repeating prefix values are not stored on leaf block – only stored once – Each leaf block is self contained– Each leaf block is self contained – For example
  • 11. Index Key Compression • Index on t(owner,object_type,object_name) (OPS$TKYTE, PROCEDURE, MAINTAIN_T, AAATM8AAEAAABV0AAP)(OPS$TKYTE, PROCEDURE, P, AAATM8AAEAAABV0AAQ)(OPS$TKYTE, PROCEDURE, P1, AAATM8AAEAAABV0AAR) (OPS$TKYTE, PROCEDURE, P2, AAATM8AAEAAABV0AAS) (OPS$TKYTE, PROCEDURE, SHOW_SPACE, AAATM8AAEAAABV0AAT) (OPS$TKYTE, PROCEDURE, Y, AAATM8AAEAAABV0AAU) (OPS$TKYTE, SEQUENCE, S, AAATM8AAEAAABV0AAV) (OPS$TKYTE, TABLE, ALL_DATA, AAATM8AAEAAABV0AAW) (OPS$TKYTE, TABLE, AUDIT_TRAIL, AAATM8AAEAAABV0AAX) (OPS$TKYTE, TABLE, BIND_DATA, AAATM8AAEAAABV0AAY) (OPS$TKYTE, TABLE, C, AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa) (OPS$TKYTE, PROCEDURE, MAINTAIN_T, AAATM8AAEAAABV0AAP)(OPS$TKYTE, PROCEDURE, P, AAATM8AAEAAABV0AAQ)(OPS$TKYTE, PROCEDURE, P1, AAATM8AAEAAABV0AAR) (OPS$TKYTE, PROCEDURE, P2, AAATM8AAEAAABV0AAS) (OPS$TKYTE, PROCEDURE, SHOW_SPACE, AAATM8AAEAAABV0AAT) (OPS$TKYTE, PROCEDURE, Y, AAATM8AAEAAABV0AAU) (OPS$TKYTE, SEQUENCE, S, AAATM8AAEAAABV0AAV) (OPS$TKYTE, TABLE, ALL_DATA, AAATM8AAEAAABV0AAW) (OPS$TKYTE, TABLE, AUDIT_TRAIL, AAATM8AAEAAABV0AAX) (OPS$TKYTE, TABLE, BIND_DATA, AAATM8AAEAAABV0AAY) (OPS$TKYTE, TABLE, C, AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa) (OPS$TKYTE, PROCEDURE, MAINTAIN_T, AAATM8AAEAAABV0AAP)(OPS$TKYTE, PROCEDURE, P, AAATM8AAEAAABV0AAQ)(OPS$TKYTE, PROCEDURE, P1, AAATM8AAEAAABV0AAR) (OPS$TKYTE, PROCEDURE, P2, AAATM8AAEAAABV0AAS) (OPS$TKYTE, PROCEDURE, SHOW_SPACE, AAATM8AAEAAABV0AAT) (OPS$TKYTE, PROCEDURE, Y, AAATM8AAEAAABV0AAU) (OPS$TKYTE, SEQUENCE, S, AAATM8AAEAAABV0AAV) (OPS$TKYTE, TABLE, ALL_DATA, AAATM8AAEAAABV0AAW) (OPS$TKYTE, TABLE, AUDIT_TRAIL, AAATM8AAEAAABV0AAX) (OPS$TKYTE, TABLE, BIND_DATA, AAATM8AAEAAABV0AAY) (OPS$TKYTE, TABLE, C, AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa) OPS$TKYTE, PROCEDURE (MAINTAIN_T, AAATM8AAEAAABV0AAP)(P, AAATM8AAEAAABV0AAQ)(P1, AAATM8AAEAAABV0AAR) (P2, AAATM8AAEAAABV0AAS) (SHOW_SPACE, AAATM8AAEAAABV0AAT) (Y, AAATM8AAEAAABV0AAU) OPS$TKYTE, SEQUENCE (S, AAATM8AAEAAABV0AAV) OPS$TKYTE, TABLE (ALL_DATA, AAATM8AAEAAABV0AAW) ( AUDIT_TRAIL, AAATM8AAEAAABV0AAX) ( BIND_DATA, AAATM8AAEAAABV0AAY) ( C, AAATM8AAEAAABV0AAZ) ( CHAINED_ROWS, AAATM8AAEAAABV0AAa) ( DBA_DATA, AAATM8AAEAAABV0AAb) ( DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) ( EMP, AAATM8AAEAAABV0AAd) ( EMPLOYEES, AAATM8AAEAAABV0AAe) ( GTT, • Index on t(owner,object_type,object_name) compress 2 AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa) (OPS$TKYTE, TABLE, DBA_DATA, AAATM8AAEAAABV0AAb) (OPS$TKYTE, TABLE, DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) (OPS$TKYTE, TABLE, EMP, AAATM8AAEAAABV0AAd) (OPS$TKYTE, TABLE, EMPLOYEES, AAATM8AAEAAABV0AAe) (OPS$TKYTE, TABLE, GTT, AAATM8AAEAAABV0AAf) (OPS$TKYTE, TABLE, IOT, AAATM8AAEAAABV0AAg) (OPS$TKYTE, TABLE, LINEITEMS, AAATM8AAEAAABV0AAh) (OPS$TKYTE, TABLE, MV, AAATM8AAEAAABV0AAi) (OPS$TKYTE, TABLE, ORDERS, AAATM8AAEAAABV0AAj) (OPS$TKYTE, TABLE, SELECT, AAATM8AAEAAABV0AAk) (OPS$TKYTE, TABLE, T, AAATM8AAEAAABV0AAl) (OPS$TKYTE, TABLE, T1, AAATM8AAEAAABV0AAm) (OPS$TKYTE, TABLE, T2, AAATM8AAEAAABV0AAn) (OPS$TKYTE, TABLE, T3, AAATM8AAEAAABV0AAo) (OPS$TKYTE, TABLE, TEST_FA, AAATM8AAEAAABV0AAp) (OPS$TKYTE, TABLE, TEST_LONG, AAATM8AAEAAABV0AAq) (OPS$TKYTE, TABLE, USER_DATA, AAATM8AAEAAABV0AAr) AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa) (OPS$TKYTE, TABLE, DBA_DATA, AAATM8AAEAAABV0AAb) (OPS$TKYTE, TABLE, DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) (OPS$TKYTE, TABLE, EMP, AAATM8AAEAAABV0AAd) (OPS$TKYTE, TABLE, EMPLOYEES, AAATM8AAEAAABV0AAe) (OPS$TKYTE, TABLE, GTT, AAATM8AAEAAABV0AAf) (OPS$TKYTE, TABLE, IOT, AAATM8AAEAAABV0AAg) (OPS$TKYTE, TABLE, LINEITEMS, AAATM8AAEAAABV0AAh) (OPS$TKYTE, TABLE, MV, AAATM8AAEAAABV0AAi) (OPS$TKYTE, TABLE, ORDERS, AAATM8AAEAAABV0AAj) (OPS$TKYTE, TABLE, SELECT, AAATM8AAEAAABV0AAk) (OPS$TKYTE, TABLE, T, AAATM8AAEAAABV0AAl) (OPS$TKYTE, TABLE, T1, AAATM8AAEAAABV0AAm) (OPS$TKYTE, TABLE, T2, AAATM8AAEAAABV0AAn) (OPS$TKYTE, TABLE, T3, AAATM8AAEAAABV0AAo) (OPS$TKYTE, TABLE, TEST_FA, AAATM8AAEAAABV0AAp) (OPS$TKYTE, TABLE, TEST_LONG, AAATM8AAEAAABV0AAq) (OPS$TKYTE, TABLE, USER_DATA, AAATM8AAEAAABV0AAr) AAATM8AAEAAABV0AAZ) (OPS$TKYTE, TABLE, CHAINED_ROWS, AAATM8AAEAAABV0AAa) (OPS$TKYTE, TABLE, DBA_DATA, AAATM8AAEAAABV0AAb) (OPS$TKYTE, TABLE, DEPARTMENTS_OBJ_T, AAATM8AAEAAABV0AAc) (OPS$TKYTE, TABLE, EMP, AAATM8AAEAAABV0AAd) (OPS$TKYTE, TABLE, EMPLOYEES, AAATM8AAEAAABV0AAe) (OPS$TKYTE, TABLE, GTT, AAATM8AAEAAABV0AAf) (OPS$TKYTE, TABLE, IOT, AAATM8AAEAAABV0AAg) (OPS$TKYTE, TABLE, LINEITEMS, AAATM8AAEAAABV0AAh) (OPS$TKYTE, TABLE, MV, AAATM8AAEAAABV0AAi) (OPS$TKYTE, TABLE, ORDERS, AAATM8AAEAAABV0AAj) (OPS$TKYTE, TABLE, SELECT, AAATM8AAEAAABV0AAk) (OPS$TKYTE, TABLE, T, AAATM8AAEAAABV0AAl) (OPS$TKYTE, TABLE, T1, AAATM8AAEAAABV0AAm) (OPS$TKYTE, TABLE, T2, AAATM8AAEAAABV0AAn) (OPS$TKYTE, TABLE, T3, AAATM8AAEAAABV0AAo) (OPS$TKYTE, TABLE, TEST_FA, AAATM8AAEAAABV0AAp) (OPS$TKYTE, TABLE, TEST_LONG, AAATM8AAEAAABV0AAq) (OPS$TKYTE, TABLE, USER_DATA, AAATM8AAEAAABV0AAr) AAATM8AAEAAABV0AAd) ( EMPLOYEES, AAATM8AAEAAABV0AAe) ( GTT, AAATM8AAEAAABV0AAf) ( IOT, AAATM8AAEAAABV0AAg) ( LINEITEMS, AAATM8AAEAAABV0AAh) ( MV, AAATM8AAEAAABV0AAi) ( ORDERS, AAATM8AAEAAABV0AAj) ( SELECT, AAATM8AAEAAABV0AAk) ( T, AAATM8AAEAAABV0AAl) ( T1, AAATM8AAEAAABV0AAm) ( T2, AAATM8AAEAAABV0AAn) ( T3, AAATM8AAEAAABV0AAo) ( TEST_FA, AAATM8AAEAAABV0AAp) ( TEST_LONG, AAATM8AAEAAABV0AAq) (USER_DATA, AAATM8AAEAAABV0AAr)
  • 12. Index Key Compression • Some Facts – Available with Oracle8i R1 (version 8.1.5) and above – Index probably consumes less disk space – Can reduce I/Os on the system -- both physical and logical – Can improve buffer cache efficiency, there is less to– Can improve buffer cache efficiency, there is less to cache – May increase contention as there are now more rows per leaf block – May require increased CPU to access Indc.sql Indc2.sql
  • 14. B*Tree When to use • I do not like rules of thumb (ROT) • Why? Consider these two – both are valid: – Use a B*Tree index to index columns if you are going to access a very small number of the rows in the table via the index. – Use a B*Tree index if you are going to process many/most/all of the rows in a table via the index – They conflict – but they are both valid– They conflict – but they are both valid – Discuss • What is small • What is initial response versus total throughput about • What about when the index can be used instead of the table • I like to understand how something works – and use that to decide
  • 15. B*Tree When to use • So, the ‘rules are’ – As the means to access rows in a table: You will read the index to get to a row in the table. Here you want to access a very small number of the rows in the table. – As the means to answer a query: The index contains enough information to answer the entire query—we will not have to go to the table at all. The index will be used as a “thinner” version of thethe table at all. The index will be used as a “thinner” version of the table. – As the means to optimize for initial response time: You want to retrieve all of the rows in a table, including columns that are not in the index itself – in some sorted order – the index will possibly allow for immediate response (but slower overall throughput).
  • 16. B*Tree When to use • Organization counts – Index on primary key populated by sequence/SYSDATE. • Data in table is mostly sorted by sequence/SYSDATE • Data in index is sorted by sequence/SYSDATE. • Index very efficient for range scans • But, how often do you range scan on a primary key populated by sequence?by sequence? • How often by date range? – Index on LAST_NAME • Data in table is randomly organized (your don’t hire everyone with a last name of ‘A%’ on the same day) • Data in index is sorted • Index is not efficient for large range scans o It would skip all around in the table
  • 17. B*Tree When to use • Enter the CLUSTERING FACTOR – A measure of how sorted the table is by the key in the index – It measures how many IO’s it would take to read the entire table via the index – row after row after row – If table is sorted by key, clustering factor near number of blocks in the table. – If table is not sorted by key, clustering factor nearer number of ROWS in table. – Please ask yourself, how many ways can the table be sorted on disk? cf.sql
  • 18. 2 total IO’S Against the Table 0..50 51..100 101..150 …. 10000.. 10050 0..10 11..19 20..25 …. 47.. 50 51..58 59..63 64..75 …. 98.. 100 10000.. 10009 10010.. 10020 10021..10028 … 10046..10050 …. Create index nm_idx on name) Select * from t where pk between 1 and 8 1,Alice 2,Bob 3,Candy 4,Doug 5,Ellen 6,Frank 7,George 8,Hank …. …. …. …. …. … … … … … …. Pk Name 1 Alice 2 Sue 3 Victor 4 Will Pk Name 5 Irene 6 Kelly 7 Melanie 8 Oliver Pk Name 9 George 10 Candy 11 Uwe 12 Wally Pk Name 13 Ellen 14 Tom 15 Rick 16 Paul Pk Name 17 Doug 18 Irene 19 Lance 20 Jack Pk Name 21 Hank 22 Frank 23 Nicole 24 Bob
  • 19. 0..50 51..100 101..150 …. 10000.. 10050 0..10 11..19 20..25 …. 47.. 50 51..58 59..63 64..75 …. 98.. 100 10000.. 10009 10010.. 10020 10021..10028 … 10046..10050 …. Create index nm_idx on name) Select * from t where Name between ‘Alice’ and ‘Hank’ 8 total IO’S Against the Table cf.sql 1,Alice 2,Bob 3,Candy 4,Doug 5,Ellen 6,Frank 7,George 8,Hank …. …. …. …. …. … … … … … …. Pk Name 1 Alice 2 Sue 3 Victor 4 Will Pk Name 5 Irene 6 Kelly 7 Melanie 8 Oliver Pk Name 9 George 10 Candy 11 Uwe 12 Wally Pk Name 13 Ellen 14 Tom 15 Rick 16 Paul Pk Name 17 Doug 18 Irene 19 Lance 20 Jack Pk Name 21 Hank 22 Frank 23 Nicole 24 Bob
  • 20. B*Tree in summary • Most common • Well understood (and mis-understood!) • Very scalable access times – To return a row from a 1,000 row index takes about as much work as from a 10,000,000 row indexmuch work as from a 10,000,000 row index • Indexing should be thought of as a design time thing • You might index to retrieve a few rows, all rows, or to avoid the table in the first place
  • 22. Bitmap Index • Introduced in version 7.3, EE • Designed for read mostly or read only application • Specifically not designed or usable with OLTP tables – Tables undergoing concurrent modification– Tables undergoing concurrent modification – Tables undergoing single row modifications • A single bitmap key entry points to many rows – In contrast to b*tree where there is a 1:1 relation between keys in the index and rows in the table bm1.sql
  • 23. Bitmap Index – bitwise operations JOB BITS --------- ------------------------------ ANALYST 0-0-0-0-0-0-0-1-0-0-0-0-1-0 CLERK 1-0-0-0-0-0-0-0-0-0-1-1-0-1 MANAGER 0-0-0-1-0-1-1-0-0-0-0-0-0-0 PRESIDENT 0-0-0-0-0-0-0-0-1-0-0-0-0-0PRESIDENT 0-0-0-0-0-0-0-0-1-0-0-0-0-0 SALESMAN 0-1-1-0-1-0-0-0-0-1-0-0-0-0 CLERK OR 1-0-0-1-0-1-1-0-0-0-1-1-0-1 MANAGER CLERK AND 0-0-0-0-0-0-0-0-0-0-0-0-0-0 MANAGER
  • 24. Bitmap Index – structure JOB LO-ROWID HI-ROWID BITS --------- -------- -------- -------------------------- ANALYST AAAR4AAA AAABEEAAH 0-0-0-0-0-0-0-1-0-0-0-0-1-0 ANALYST AAAR4AAB AAABEEAAM 1-0-0-0-0-0-0-0-0-0-1-1-0-1 ANALYST AAAR4AAC AAABEEAAN 0-0-0-1-0-1-1 PRESIDENT AAAR4AAA AAABEEAAI 0-0-0-0-0-0-0-0-1-0-0-0-0-0 PRESIDENT AAAR4AAX AAABEEAAC 0-1-1-0-1-0-0-0-0-1-0-0-0-0 PRESIDENT AAAR4AAY AAABEEAAJ 1-0-1-0-0-1-1 • Key + Lo Rowid – Hi Rowid + Bitmap • 0’s and 1’s map to rowids in that range • If we know max number of rows/block – simple math • alter table emp minimize records_per_block; • Note the multiple entries per JOB!
  • 25. Bitmap Index • Can answer questions like: – How many of this match (count 0’s and 1’s) – How many of this that or the other thing match • Bitwise and/or bitmaps • Count 0’s and 1’s• Count 0’s and 1’s – Good for accessing a few rows (just like B*Tree) – Good for counting, identifying many, all, some of the rows (just like B*Tree)
  • 26. Bitmap Index - when • Most common rule of thumb going is “low distinct cardinality” • Now, I defy you to define “low distinct cardinality” – Is 2 “low distinct cardinality”? – Yes it is – No it isn’t – It depends • In pure ad-hoc, even high distinct cardinality columns could/should be considered for bitmaps • Consider
  • 27. Bitmap Index - when • How many men in regions 1, 10 and 30 are there in the 41 and over age group? • How many men in region 20 or women in region 22 are 18 and under? • How many people are in regions 11, 20 or 30 • How many over 41 year olds are there that are women?• How many over 41 year olds are there that are women? • Etc etc etc • Now, come up with an indexing scheme using B*Trees for that • And then maintain it as the questions change (and change and change) bm2.sql
  • 29. Function Based Indexes • Added in Oracle 8i release 1 (8.1.5) as a feature of EE and PE • In 9i, a feature of SE, EE and PE • Great for – Case insensitive searches/sorts– Case insensitive searches/sorts – Searching on derived attributes -- complex formulas • Provide immediate, transparent value to the application • Function you index must be “pure” - deterministic pure.sql
  • 30. • Thinking outside the box with FBI's – Two facts • B*Tree indexes will never have an entirely NULL entry. If the entire key is NULL, it will not be placed in the B*Tree • We have function based indexes that allow us to Function Based Indexes • We have function based indexes that allow us to incorporate complex, procedural logic in them – We can solve common problems • Indexing only some of the rows in a table (like indexing a where clause) • Enforcing complex integrity in the database • Using an index for “where column is null”
  • 31. • Selective Indexing – You have a table with a flag column – You want to index this column when the flag = 'x' – A small % of the table is accessed by this values – Sounds like what you've read about bitmap indexes but • This table is modified all day long Function Based Indexes • This table is modified all day long • Bitmaps would kill concurrency • The bitmap would grow to outrageous sizes quickly – The answer -- a function based index • Or a better model • Or a better structure (AQ) fbi.sql
  • 32. • Selective Uniqueness – You have a table with versioned information in it • A project table with status "ACTIVE" and "INACTIVE" – When status is "ACTIVE", some set of columns must be unique Function Based Indexes unique – When status is "INACTIVE", those columns may contain any values -- any number of duplicates – How can you do it? selind.sql
  • 33. • Where column is NULL – Nulls are not indexed right? – Wrong – entirely NULL key entries are not, but if *any* bit of a concatenated index is not null Entry is made. • Fear no longer the NULL value! Function Based Indexes null.sql
  • 34. Mythology And other interestingAnd other interesting anti-facts and facts
  • 35. • Do nulls and indexes work together? – Obviously, we’ve seen an example with FBI’s – Bitmap indexes – always index nulls. – B*Tree cluster indexes – always index nulls. – Conventional B*Tree indexes do not if and only if the entire key is null (all of the columns) Mythology entire key is null (all of the columns) • Why is that? See null2.sql null2.sql
  • 36. • Do I need to index foreign keys? – Probably – If you • Update the parent table primary key OR • Delete from parent OR • Merge into parent – 9i and later – lock taken on child table for duration of update or Mythology – 9i and later – lock taken on child table for duration of update or delete • Which could take long since the table lock gets blocked, blocking others • Which could take long due to full scan of child, since there is no index! – 8i and before – lock taken for duration of transaction fkey.sql
  • 37. • Maybe we are not using the leading edge? • Create index I on T(x,y) – Where y = value will tend to not use the index – Unless • We index skip scan • We select x,y from t where y = value – and we use Mythology – why isn’t it using my index • We select x,y from t where y = value – and we use the index I as a skinny table to full scan case1.sql
  • 38. • Select count(*) from t • Full scanning table, not using any existing index • Two causes – You are still using the RBO – None of the columns indexed was defined “NOT NULL” Mythology – why isn’t it using my index
  • 39. • Select * from table where indexed_column = value • Indexed column is on the leading edge • No index being used • Likely an implicit conversion Mythology – why isn’t it using my index case2.sql
  • 40. • This is my favorite one • Because if the index were to be used, the query would run incredibly slow. • Remember: – Loop Mythology – why isn’t it using my index • Say indexes are not all goodness • Say full scans are not evil • Exit when (you really believe it) – End loop • Following example from asktom..
  • 41. So, joe (or josephine) sql coder needs to run the following query: select t1.object_name, t2.object_name from t t1, t t2 where t1.object_id = t2.object_id and t1.owner = 'WMSYS' Rows Row Source Operation Mythology – why isn’t it using my index Rows Row Source Operation ------- --------------------------------------------------- 528384 HASH JOIN 8256 TABLE ACCESS FULL T 1833856 TABLE ACCESS FULL T suppose they ran it or explain planned it -- and saw that plan. "Stupid stupid CBO" they say -- "I have indexes, why won't it use them. We all know that indexes mean fast=true! Ok, let me use the faithful RBO and see what happens"
  • 42. select /*+ RULE */ t1.object_name, t2.object_name from t t1, t t2 where t1.object_id = t2.object_id and t1.owner = 'WMSYS' Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=HINT: RULE 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' Mythology – why isn’t it using my index 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' 2 1 NESTED LOOPS 3 2 TABLE ACCESS (FULL) OF 'T' 4 2 INDEX (RANGE SCAN) OF 'T_IDX' (NON-UNIQUE) See, now that’s what I’m talking about – indexes are good… Or are they?
  • 43. call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 35227 5.63 9.32 23380 59350 0 528384 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 35229 5.63 9.33 23380 59350 0 528384 Misses in library cache during parse: 1 Optimizer goal: CHOOSE Mythology – why isn’t it using my index Optimizer goal: CHOOSE Parsing user id: 80 Rows Row Source Operation ------- --------------------------------------------------- 528384 HASH JOIN 8256 TABLE ACCESS FULL T 1833856 TABLE ACCESS FULL T
  • 44. call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 35227 912.07 3440.70 1154555 121367981 0 528384 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 35229 912.07 3440.70 1154555 121367981 0 528384 Misses in library cache during parse: 0 Optimizer goal: RULE Mythology – why isn’t it using my index Optimizer goal: RULE Parsing user id: 80 Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=HINT: RULE 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' 2 1 NESTED LOOPS 3 2 TABLE ACCESS (FULL) OF 'T' 4 2 INDEX (RANGE SCAN) OF 'T_IDX' (NON-UNIQUE)
  • 45. 1 SELECT phy.value, 2 cur.value, 3 con.value, 4 1-((phy.value)/((cur.value)+(con.value))) "Cache hit ratio" 5 FROM v$sysstat cur, v$sysstat con, v$sysstat phy 6 WHERE cur.name='db block gets' 7 AND con.name='consistent gets' 8* AND phy.name='physical reads' Mythology – why isn’t it using my index VALUE VALUE VALUE Cache hit ratio -------- ---------- ---------- --------------- 1277377 58486 121661490 .989505609 98.9% cache hit, not bad eh?
  • 46. • Space is never reused in an index – Indexes are a complex data structures – Data has a location • If you insert monotonically increasing values (1,2,3, ) • And you delete many – not all, many – of the older values over time (1,3,5,7, .) Mythology values over time (1,3,5,7, .) • Then, since the value 123456 does not fit “near” the value 2 – that space won’t be reused (the block that 2 is on) • But indexes on say “last name” or a reverse key index
  • 47. • Most discriminating elements should go first – Say you have copy of all objects – You ask • What does scott own? • What tables does scott own? • What about that EMP table scott owns? Mythology • What about that EMP table scott owns? – The only sensible index would be on (owner,object_type,object_name). – Object_name is the most ‘discriminating’ – Object_name would be the worst thing to put first – How you query the data dictates the ordering order.sql
  • 48. • NOSEGMENT – What would happen to my plan if I created this index? – Would the optimizer likely choose to use it? – ALTER SESSION SET “_use_nosegment_indexes” = true; – Dbms_stats.set_index_stats with your best guess might Interesting – Dbms_stats.set_index_stats with your best guess might be necessary nosegment.sql
  • 49. • INVISIBLE – What would happen to my plan if I created this index? – Would the optimizer likely choose to use it? – Invisible indexes actually • Create the index • Maintain the index Interesting – but wait, there’s more! • Maintain the index • But keep the index from the optimizers view! • alter session set OPTIMIZER_USE_INVISIBLE_INDEXES =true; invisible.sql
  • 50. • Where string like ‘%stuff’ – B*tree – nope – Bitmap – nope – Text – yes • Indexes the substrings • Case insensitive even Interesting – and inclosing • Case insensitive even • Everyone has it leading.sql