SQL QUERY NOT USING BITMAP INDEX [message #123398] |
Mon, 13 June 2005 03:47 |
puneetsachar
Messages: 97 Registered: March 2005 Location: New Delhi, India
|
Member |
|
|
HI, group
I have a Simple SQL query and its not using the bitmap index I have created on it.
Following are details which help you to understand my problem
Desc stock_transaction
Name Null? Type
----------------------------------------- -------- --------------
ID NOT NULL NUMBER(10)
STOCK_BREAK_ID NUMBER(10)
ISIN NOT NULL VARCHAR2(12)
SECURITY_NUMBER NOT NULL VARCHAR2(12)
ACCOUNT_ID VARCHAR2(5)
TRANSACTION_NUMBER NOT NULL VARCHAR2(16)
AMOUNT NOT NULL NUMBER(30,4)
MARKET_VALUE NUMBER(30,4)
DEPARTMENT_ID VARCHAR2(5)
CATEGORY_ID VARCHAR2(10)
STATUS NOT NULL VARCHAR2(1)
LEDGER_STATEMENT NOT NULL VARCHAR2(3)
CUSTOMER_ID NOT NULL VARCHAR2(3)
VALUE_DATE NOT NULL DATE
STOCK_TYPE NOT NULL VARCHAR2(3)
SEC_LONGNAME NOT NULL VARCHAR2(100)
REMINDER DATE
BOOKING_DATE NOT NULL DATE
TRANSACTION_OWNER_ID VARCHAR2(5)
FUNCTIONAL_OWNER_ID VARCHAR2(5)
BUSINESS_OWNER_ID VARCHAR2(5)
ACCOUNT_NO VARCHAR2(15)
LAST_UPDATE DATE
EE2_USER_ID VARCHAR2(10)
Data --> 80,000
Select department_id, count(*) from stock_transaction group by department_id
DEPAR COUNT(*)
----- ----------
CAIN 20000
CAST 20000
CTRL 20000
SDM 19999
VAUL 1
Index --> Bitmap index on Department_ID
Select * from stock_transaction where DEPARTMENT_ID = 'VAUL'
Index USEAGE -- NO
Explain plan-- Full table Scan
Select department_id from stock_transaction where DEPARTMENT_ID = 'VAUL'
Index USEAGE -- Yes
Explain Plan -- Index used
INDEX_NAME --> TEST_IDX
INDEX_TYPE --> BITMAP
TABLE_OWNER --> XXBEAT
TABLE_NAME --> STOCK_TRANSACTION
I'm stuck can you please help me out from this.
Why my index is not been used.
what will i do so that my index work.
Why my index is working when I have entered department_id in select statement.
Please answer my queries...
Puneet
|
|
|
|
|
|
|
Re: SQL QUERY NOT USING BITMAP INDEX [message #123460 is a reply to message #123398] |
Mon, 13 June 2005 10:17 |
smartin
Messages: 1803 Registered: March 2005 Location: Jacksonville, Florida
|
Senior Member |
|
|
The optimizer doesn't know the distribution of your data. If those counts are correct. Gather histograms when you gather statistics.
exec dbms_stats.gather_table_stats(user, 'table_name', cascade=>true, method_opt=>'for all indexed columns size 250');
|
|
|
|
|
Re: SQL QUERY NOT USING BITMAP INDEX [message #123712 is a reply to message #123398] |
Tue, 14 June 2005 09:30 |
smartin
Messages: 1803 Registered: March 2005 Location: Jacksonville, Florida
|
Senior Member |
|
|
When you select just the department_id, your index "is working" because all oracle has to do is read the index to get the value you requested in your select statement. But when you do select *, you are asking for something totally different. For each row, oracle has to go to the table data to retrieve the values for all the columns. So in that case it has to read both the index and the table data, which is much more costly than just reading the index. This is why it is generally better to only select the columns you need.
Did you gather statistics as I suggested above? What was the result after that?
|
|
|