Welcome to the Oracle community forum and interact with 2 million technical staff. bitmap indexing is another index type. It is organized in the same way as B-tree Indexing and is also a balance tree. The difference between B-tree index and B-tree index is that the method for storing index entries in leaf nodes is different. We know from the above that in the leaf node of the B-tree index
Welcome to the Oracle community forum and interact with 2 million technical staff> bitmap indexing is another index type, which is organized in the same way as B-tree Indexing, it is also a balance tree. The difference between B-tree index and B-tree index is that the method for storing index entries in leaf nodes is different. We know from the above that in the leaf node of the B-tree index
Welcome to the Oracle community forum and interact with 2 million technical staff> enter
Bitmap indexes are another index type. They are organized in the same way as B-tree indexes and are also a balance tree. The difference between B-tree index and B-tree index is that the method for storing index entries in leaf nodes is different. As we know above, in the leaf node indexed by the B tree, if the value of the indexed column is not empty for each data row in the table, A corresponding index entry is maintained for the record row in the leaf node.
This is not the case for Bitmap indexes. The index entries in the leaf nodes are shown in.
Assume that all records in table T have only three values on column C1: 01, 02, and 03. After creating a bitmap index on the C1 column of table T, the content of the leaf node is 9-14. As you can see, the bitmap index has only three index entries, that is, the value of each C1 column corresponds to one index entry. Bitmap index entries also contain the ROWID corresponding to the first record in the table and the ROWID corresponding to the last record. The last part of the index entry is a bitmap consisting of multiple bit bits. Each bit corresponds to a record.
Bitmap Index Structure
When an SQL statement such as where c1 = '01' is issued, oracle searches for the index entry where 01 is located, and then scans all the bit bits in the bitmap. If the first bit is 1, the C1 value on the first record is 01, returns the ROWID of the first record (the ROWID of the record is obtained based on the start ROWID of the record in the index entry and the row number ). If the second bit is 0, the C1 value on the second record is not 01, and so on. In addition, if the index column is empty, it will be recorded in the bitmap index, that is, set the corresponding bit to 0.
If the number of different values on the index column is relatively small, such as for gender columns (male or female), bitmap indexes will be better, because it occupies a very small amount of space (because bit is used to represent the data rows in the table), the number of index blocks scanned is also relatively small during indexing. You can imagine that if you create Bitmap indexes on columns with many different values, such as primary key columns, the index entries generated are equal to the number of records in the table, at the same time, there is only one bitmap in each index entry, and the rest is 0. This is not as efficient as B-tree indexes.
If the indexed columns are updated frequently, bitmap indexes are not suitable. Because when updating the column where the bitmap is located, the bit needs to be modified between different index entries. For example, the first record is changed from 01 to 02, you must change the first bit of the index entry where 01 is located to 0, and then change the first bit of the index entry where 02 is located to 1. Therefore, when an index entry is updated, multiple index entries in the bitmap index are locked. That is, only one user can update table T at the same time, thus reducing the concurrency.
Bitmap indexes are suitable for Data Warehouse systems and not OLTP systems.
SQL> create table t_bitmap_test
2 select rownum as id, trunc (dbms_random.value (1, 4) as bitcol
3 from dba_objects where rownum <= 20;
SQL> select * from t_bitmap_test;
ID BITCOL
--------------------
1 3
2 2
3 1
4 3
5 3
6 1
7 1
8 2
9 3
10 2
11 3
12 1
13 1
14 3
15 2
16 2
17 3
18 2
19 1
20 3
SQL> connect hr/hr
Connected.
SQL> alter session set events '10608 trace name context forever, level 10 ';
The session has been changed.
SQL> create bitmap index idx_t_bitmap_test on t_bitmap_test (bitcol );
The index has been created.
SQL> alter session set events '10608 trace name context off ';
The session has been changed.
SQL> select object_id from user_objects where object_name = 'idx _ T_BITMAP_TEST ';
OBJECT_ID
----------
24499
SQL> alter session set events 'immediate trace name TREEDUMP level 100 ';
The session has been changed.
10608 events are used to track the process of creating a bitmap index. TREEDUMP is used to dump the tree structure of the index. Open the dumped file:
* ** Session id: (7.13) 14:33:46. 000
QerbiARwo: bitmap size is 8168
QerbiIPI default pctfree = 10
QerbiIPI length = 0
QerbiAllocate pfree = 127 space = 8168
QerbiStart first start
QerbiRop: rid = 00c01ce4. 0000, new = Y, key: (2): c1 04
QerbiCmpSz notfound pctfree = 10
QerbiCmpSz adjblksize = 7351 length = 0
QerbiRop keysize = 4 maxbm = 3531
Kdibcoinit (3116714): srid = 00c01ce4. 0000
QerbiRop: rid = 00c01ce4. 0001, new = Y, key: (2): c1 03
Kdibcoinit (3116698): srid = 00c01ce4. 0001
QerbiRop: rid = 00c01ce4. 0002, new = Y, key: (2): c1 02
Kdibcoinit (311661c): srid = 00c01ce4. 0002.
QerbiRop: rid = 00c01ce4. 0003, new = N, key: (2): c1 04
QerbiRop: rid = 00c01ce4. 0004, new = N, key: (2): c1 04
QerbiRop: rid = 00c01ce4. 0005, new = N, key: (2): c1 02
QerbiRop: rid = 00c01ce4. 0006, new = N, key: (2): c1 02
QerbiRop: rid = 00c01ce4. 0007, new = N, key: (2): c1 03
QerbiRop: rid = 00c01ce4. 0008, new = N, key: (2): c1 04
QerbiRop: rid = 00c01ce4. 0009, new = N, key: (2): c1 03
QerbiRop: rid = 00c01ce4. 000a, new = N, key: (2): c1 04
QerbiRop: rid = 00c01ce4. 000b, new = N, key: (2): c1 02
QerbiRop: rid = 00c01ce4. 000c, new = N, key: (2): c1 02
QerbiRop: rid = 00c01ce4. 000d, new = N, key: (2): c1 04
QerbiRop: rid = 00c01ce4. 000e, new = N, key: (2): c1 03
QerbiRop: rid = 00c01ce4. 000f, new = N, key: (2): c1 03
QerbiRop: rid = 00c01ce4. 0010, new = N, key: (2): c1 04
QerbiRop: rid = 00c01ce4. 0011, new = N, key: (2): c1 03
QerbiRop: rid = 00c01ce4. 0012, new = N, key: (2): c1 02
QerbiRop: rid = 00c01ce4. 0013, new = N, key: (2): c1 04
Kdibcoend (3116714): erid = 00c01ce4. 0017 status = 3
[1] [2] [3]