Académique Documents
Professionnel Documents
Culture Documents
Internals
Julian Dyke
Independent Consultant
Web Version
1
Agenda
Introduction
Bitmap
Row Sources
Internal Structures
Bitmap Index DML
Conclusion
Introduction
Bitmap Indexes
Bitmap indexes
Must be non-unique
Include NULL values (B*Tree indexes do not)
Maximum 30 columns (B*Tree indexes max 32 columns)
Can be locally partitioned (8.1.5 and above)
Cannot be globally partitioned
Can be function-based indexes (built-in or user-defined)
Can be IOT secondary indexes (9.2 and above)
Can be created on global temporary tables
Cannot be compressed
Cannot be reversed
Bitmap Indexes
For example
CREATE TABLE property
(
property_code NUMBER,
bedrooms NUMBER,
receptions NUMBER,
garages NUMBER
);
CREATE BITMAP INDEX index1 ON property (bedrooms);
CREATE BITMAP INDEX index2 ON property (receptions);
CREATE BITMAP INDEX index3 ON property (garages);
SELECT property_code FROM property
WHERE bedrooms = 4
AND receptions = 3
AND garages = 2
Logical Operations
A AND B
A OR B
NOT A
Bitmap Row
Sources
Operation
Version
7.3.2
7.3.2
7.3.2
9.0.1
BITMAP AND
7.3.2
BITMAP OR
7.3.2
BITMAP MINUS
7.3.2
BITMAP MERGE
7.3.2
7.3.2
7.3.2
7.3.2
7.3.2
BITMAP CONSTRUCTION
7.3.2
BITMAP COMPACTION
7.3.2
Introduced in 7.3
Options are
BITMAP INDEX (SINGLE VALUE)
Builds a single bitmap for a given value
0
1
2
2
Bitmap Or Operation
0
1
2
3
3
0
1
2
3
4
4
3
0
1
2
3
3
5
0
1
2
3
4
The statement
SELECT /*+ STAR_TRANSFORMATION */
fact.factkey,
dim1.dim1key,
dim2.dim2key
FROM fact, dim1, dim2
WHERE dim1.dim1key = fact.dim1key
AND dim2.dim2key = fact.dim2key
AND dim1.dim1desc = 100
AND dim2.dim2desc = 200;
0
1
2
3
4
5
6
Internal
Structure
Description
Column Value
Start ROWID
End ROWID
Bitmap
Key
Start ROWID
211/0
211/0
211/0
End ROWID
212/3
212/3
212/3
Bitmap
10000010
00110101
01001000
PROPERTY_CODE
1
2
1
0
BEDROOMS
RECEPTIONS
GARAGES
2
4
3
2
Block 211
3
3
2
1
4
3
2
1
5
4
3
2
6
3
2
1
Block 212
7
2
1
1
8
3
2
2
Start ROWID
End ROWID
Bitmap
Key
ROWID
Bitmap Pieces
A bitmap piece
covers a contiguous set of rows in one or more extents
may cross extent boundaries
may split within a block
Bitmap Pieces
End 533/15
Start 532/0
Start 211/0
Start 211/0
End 532/7
Start 211/8
Block 211
Extent 1
2005 Julian Dyke
End 533/15
Start 532/8
End 533/15
End 533/7
Start 532/8
End 532/15
Block 532
Block 533
Extent 2
Compression Algorithm
First Byte
Description
< 192
Single-byte group
>= 192
Multi-byte group
Single-Byte Groups
Bitmap
00
10000000
01
01000000
02
00100000
03
00010000
08
00000000 10000000
0F
00000000 00000001
10
11
17
18
19
Multi-Byte Groups
Multi-Byte Groups
Examples
Code
Hex
Binary
Number of
Zero Bytes
Number of
Zero Bits
C8
11001000
D0
11010000
D8
11011000
16
E0
11100000
24
E8
11101000
32
F0
11110000
40
F8 00
11111000 00000000
48
F8 01
11111000 00000001
56
F8 02
11111000 00000010
64
F8 7F
11111000 01111111
133
1064
F8 80 01
134
1072
F8 81 01
135
1080
Multi-Byte Groups
Number of
bytes
C8
11001000
C8 FF
C9
11001001
C9 FF FF
CA
11001010
CA FF FF FF
CB
11001011
CB FF FF FF FF
CC
11001100
CC FF FF FF FF FF
CD
11001101
CD FF FF FF FF FF FF
CE
11001110
CE FF FF FF FF FF FF FF
CF
11001111
CF FF FF FF FF FF FF FF FF
Hex
Example
Hkan Factor
Maximum
Rows per Block
2048
178
4096
364
8192
736
16384
1481
Hkan Factor
This command
Scans entire table
Counts number of rows in each block
Sets Hkan Factor in SPARE1 to maximum row count
Sets bit 0x8000 in SPARE1 to indicate value has been set
Subsequently modified blocks will be limited to the new Hkan
Factor
Command is reversed using
Hkan Factor
Nulls
Distinct Keys
B*Tree
Bitmap
237
237
237
13
10
237
25
100
237
50
1000
237
48
10000
237
87
50000
237
210
100000
237
363
Clustering
Column2
(Clustered)
Height
Blocks
24
Leaf Rows
100
100
Leaf Blocks
20
Branch Rows
19
Branch Blocks
Bitmap Index
DML
Inserts
Inserts
Key
Key
Key
Start 573/0
Start 574/8
Start
575/0
Start
575/8
End 574/7
End 574/15
End
575/7
End
575/15
Block 573
Table Rows
Key
Block 574
Block 575
Key = 2
Key <> 2
Inserts
Key
Start 573/0
End 574/7
575/15
575/7
574/15
Block 573
Table Rows
Block 574
Block 575
Key = 2
Key <> 2
Updates
Locking
The index leaf entry contains a bitmap which may cover many
rows across a number of blocks
Locking
CREATE BITMAP INDEX i1 ON t1 (c2);
Lock
0
1
Lock
Lock
0
1
Key
Key
Key
Start
211/0
Start
211/0
Start
213/0
Start
211/0
End
214/3
End
212/3
End
214/3
End
214/3
c1
77
78
80
83
86
88
89
90
92
94
97
98
99
c2
4
3
c3
25
10
10
20
15
25
10
15
20
15
20
10
Block 211
Table Rows
Block 212
Block 213
UPDATE t1
SET c2 = 4
WHERE c1 = 88;
Block 214
Updated
Locked
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
001000
000100
000010
000001
100000
START
END
000010
000001
100000
010000
001000
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
001000
000100
000010
000001
100000
START
END
000100
000010
000001
100000
010000
Initial state. Branch rows initial contain index key values only
Branch
Block
Leaf
Blocks
Updated
Deleted
1
2
START
END
100000
010000
001000
000100
000010
Branch
Block
START
END
010000
001000
000100
000010
000001
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
100000
010000
001000
000100
000010
START
END
001000
000100
000010
000001
100000
START
END
000010
000001
100000
010000
001000
START
END
100000
010000
001000
000100
000010
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
001000
000100
000010
000001
100000
START
END
000100
000010
000001
100000
010000
Deleted row is retained until end of transaction. Leaf block splits between
updated and deleted rows. Branch row must contain bitmap
Leaf
Blocks
START
END
100000
010000
001000
000100
000010
Updated
Deleted
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
010000
001000
000100
000010
000001
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
100000
010000
001000
000100
000010
START
END
001000
000100
000010
000001
100000
START
END
000010
000001
100000
010000
001000
START
END
100000
010000
001000
000100
000010
START
END
100000
010000
001000
000100
000010
START
END
010000
001000
000100
000010
000001
START
END
100000
010000
001000
000100
000010
START
END
001000
000100
000010
000001
100000
START
END
000100
000010
000001
100000
010000
START
END
000010
000001
100000
010000
001000
Conclusions
In Oracle 10g bitmap indexes are viable for volatile tables if all
updates are made by one session
References
Jonathan Lewis
Understanding Bitmap Indexes (http://www.dbazine.com)
Optimising Oracle Performance by Design 2001-2003
Steve Adams
Miracle Master Class 2003