Case 1: Using BITMAP for BULK Load.
To illustrate this, I have created a table called bitmapdemotable as provided below:
create table bitmapdemotable (runnumber number(6), runname varchar2(15), runtype number(2));
I have also created a procedure to populate this table. Please note that I am using a "While Loop" here to simulate row-by-row insert operation.
create or replace procedure bitmapproc(noofrecords in number) is
counter number;
begin
counter := 1;
while (counter <= noofrecords)
loop
insert into bitmapdemotable values (counter, 'a' || counter,mod(counter,2));
counter := counter + 1;
end loop;
commit;
end;
Next, I have created an index on this table for the column "runtype" which actually holds either 0 or 1.
create bitmap index bitmapidx on bitmapdemotable(runtype);
In order to study the behaviour, we need to use TKPROF. For this we need to change the configuration settings of TIMED_STATISTICS and SQL_TRACE
alter session set timed_statistics=true;
alter session set sql_trace=true;
Now, I am executing the procedure by passing the value as 50000.
exec bitmapproc(50000)
When we see the trace file (after extracting the contents of the trace file into a local text file using TKPROF), it looks like the following figure:
The initial is for the procedure as a whole (does not include the data for the insert statement as it is separately captured) and the second is for the insert statement. Please note that the insert statement took more CPU, elapsed time and logical I/Os (both query and current). Now, please also note that ELAPSED is greater than CPU, which may be due to some wait events.
Now, instead of row-by-row insert we have captured the statistics for the bulk load and the result is shown in the following figure:
As expected, the SELECT statement, led to FULL TABLE SCAN. But, when we look at the statistics, we can observe vast difference between the row-by-row and BULK load. The reason being, when we do a row-by-row insert, the B-tree is used to locate the leaf nodes that contain bitmap segments for a given value of the key. Start ROWID and the bitmap segments are used to locate the rows that contain the key value. When changes are made to the key column in the table, bitmaps must be modified. This results in the locking of the relevant bitmap segments. Because locks are acquired on the whole bitmap segment, a row that is covered by the bitmap cannot be updated by other transactions until the first transaction ends. Oracle server should repeat this for every row that gets either inserted or updated. Hence row by row manipulation on the rows consists of bitmap index is costly.

