I created a bitmap index for my table on column_x
. Keep in mind that column x has low cardinality, only 20 unique values out of 100,000 rows of data.
Then I query
SELECT * FROM table_1
WHERE column_x = 'xyz'
But instead of doing an index scan, it used full table scan.
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 53295 | 8483K| 3413 (1)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMPLOYEE | 53295 | 8483K| 3413 (1)| 00:00:01 |
----------------------------------------------------------------------------------
Now if I added an index for another column y
, then I query with
SELECT column_x,column_y FROM table_1
WHERE column_x = 'xyz'
the result would be
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 53295 | 676K| 8 (75)| 00:00:01 |
|* 1 | VIEW | index$_join$_001 | 53295 | 676K| 8 (75)| 00:00:01 |
|* 2 | HASH JOIN | | | | | |
| 3 | BITMAP CONVERSION TO ROWIDS| | 53295 | 676K| 1 (0)| 00:00:01 |
|* 4 | BITMAP INDEX SINGLE VALUE | DIVISION_IDX | | | | |
| 5 | BITMAP CONVERSION TO ROWIDS| | 53295 | 676K| 1 (0)| 00:00:01 |
| 6 | BITMAP INDEX FULL SCAN | STATUS_IDX | | | | |
--------------------------------------------------------------------------------------------------
Why can't I select all columns? There's no way I should create an index for every column right? Because some of the columns would have high cardinality or would be less put on a where condition. Also my query only return about 5% of the all data.
Did I do something wrong here?