Index ignored in query??

This is probably a basic question about indexes, thanks for your insights.
I have a table VOUCHER with some columns including a TICKETNO column for which there is a primary key index, defined as follows:
CREATE UNIQUE INDEX VOUCHER_PK ON VOUCHER (TICKETNO)
The table contain approximately 20 million records.
We are using Oracle 9i RAC on HP-UX 11.11
I am running the following query, which runs for 20 minutes and then fails:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning and Real Application Clusters options
JServer Release 9.2.0.8.0 - Production
SQL> select count(*) from VOUCHER
2 where TICKETNO between 100000 and 100100
3
SQL> /
select count(*) from VOUCHER
ERROR at line 1:
ORA-01555: snapshot too old: rollback segment number 741 with name
"_SYSSMU741$" too small
I am confused... Why counting 100 records with an indexed column takes so long and fail?

Thanks for the feedback. I am going to run the ANALYZE suggestion tonight.
Here are the results of the queries asked for:
SELECT Table_Name, Status FROM User_Indexes WHERE Index_Name = 'VOUCHER_PK';
OWNER TABLE_NAME STATUS
SMVDBA VOUCHER VALID
SELECT Column_Name FROM User_Ind_Columns WHERE Index_Name = 'VOUCHER_PK';
COLUMN_NAME
TICKETNO
SELECT Last_Analyzed FROM User_Indexes WHERE Index_Name = 'VOUCHER_PK';
LAST_ANAL
SELECT Last_Analyzed FROM User_Tables WHERE Table_Name = 'VOUCHER';
LAST_ANAL
21-FEB-08
EXPLAIN PLAN FOR
select count(*) from VOUCHER
where TICKETNO between 100000 and 100100;
Explained
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY('', '', 'ALL'));
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | | | |
| 1 | SORT AGGREGATE | | | | |
| 2 | TABLE ACCESS FULL | VOUCHER | | | |
Note: rule based optimization, PLAN_TABLE' is old version
10 rows selected.
EXPLAIN PLAN FOR
select /*+ INDEX(V VOUCHER_PK) */ count(*) from VOUCHER V
where TICKETNO between 100000 and 100100;
Explained.
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY('', '', 'ALL'));
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1 | 18 | 5 |
| 1 | SORT AGGREGATE | | 1 | 18 | |
| 2 | INDEX FAST FULL SCAN| VOUCHER_PK | 83788 | 1472K| 5 |
Note: cpu costing is off, PLAN_TABLE' is old version
10 rows selected.

Similar Messages

  • How to enforce index in oracle query

    Hi all
    how to enforce index in oracle query
    Regards

    Use INDEX hint to force Optimizer to use the specfied index.
    You really need to investigate why Optimizer doesn't choose the index. Remember, INDEX SCAN are not always GOOD.
    Jaffar

  • Index ignored by optimizer

    Hi All,
    I have a table with email id as one of the column. There is a query generated by packaged application to search email id's along with some other details.
    This query has an in-definite elapsed time. After some research i found out that query is not using one of the index on email id column. hence i have hinted the index and the query elapsed time reduced to 1 minute.
    But now the issue is i cannot implement hint since the query is generated dynamically from packaged application.
    The stats are upto date and there exists a height based histogram on email id column. Even then the query is still not picking up the index.
    How to help optimizer to choose the right index which was hinted?
    Please help...
    Thanks in advance
    regards
    sunil

    PrafullaNath wrote:
    If your optimizer is not using the index then you can think of setting the parameter "optimizer_index_cost_adj"
    The optimizer_index_cost_adj parameter was created to allow use to change the relative costs of full-scan versus index operations. This is the most important parameter of all, and the default setting of 100 . For some OLTP systems, re-setting this parameter to a smaller value (between 10- to 30) may result in huge performance gains! and it will force to use the index.This is not good advice - the OP is not running Oracle 8i, and probably doesn't want to wreck the rest of his system just to improve the probability that one of his queries might go faster some of the time.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>

  • How to re-index a modified query?

    Hi community,
    Due to a change to a BO I had also to adjust a already created query used to support an advanced search pane.
    Now every time I open my OWL, the OWL is empty and a message is raised saying "The index is temporary not available;index=.c016:1fs:jdx_zby003542_iptfrmv1yxsig7".
    Even though the message uses the word "temporary" this problem did not solve itself over time so I ask here:
    Is it possible/how can I force the re-indexing of a query?
    Best regards,
    Ludger

    Hi everyone
    This issue still persists in spite of my second message - i am pretty helpless.
    First I thought a clean solves the issue but it only prevents the "index temporary not available" message as long as no BO is present.
    As soon as a new BO is created, the situation occurs again.
    What can I do?

  • How to make sql to use index/make to query to perform better

    Hi,
    I have 2 sql query which results the same.
    But both has difference in SQL trace.
    create table test_table
    (u_id number(10),
    u_no number(4),
    s_id number(10),
    s_no number(4),
    o_id number(10),
    o_no number(4),
    constraint pk_test primary key(u_id, u_no));
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030301, 1, 1001, 1, 2001, 1);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030302, 1, 1001, 1, 2001, 2);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030303, 1, 1001, 1, 2001, 3);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030304, 1, 1001, 1, 2001, 4);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030305, 1, 1002, 1, 1001, 2);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030306, 1, 1002, 1, 1002, 1);
    commit;
    CREATE INDEX idx_test_s_id ON test_table(s_id, s_no);
    set autotrace on
    select s_id, s_no, o_id, o_no
    from test_table
    where s_id <> o_id
    and s_no <> o_no
    union all
    select o_id, o_no, s_id, s_no
    from test_table
    where s_id <> o_id
    and s_no <> o_no;
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    3 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    Statistics
    223 recursive calls
    2 db block gets
    84 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    5 sorts (memory)
    0 sorts (disk)
    8 rows processed
    -- i didnt understand why the above query is not using the index idx_test_s_id.
    -- But still it is faster
    select s_id, s_no, o_id, o_no
    from test_table
    where (u_id, u_no) in
    (select u_id, u_no from test_table
    minus
    select u_id, u_no from test_table
    where s_id = o_id
    or s_no = o_no)
    union all
    select o_id, o_no, s_id, s_no
    from test_table
    where (u_id, u_no) in
    (select u_id, u_no from test_table
    minus
    select u_id, u_no from test_table
    where s_id = o_id
    or s_no = o_no);
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=16 Card=2 Bytes=156)
    1 0 UNION-ALL
    2 1 FILTER
    3 2 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=6 Bytes=468)
    4 2 MINUS
    5 4 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=26)
    6 4 TABLE ACCESS (BY INDEX ROWID) OF 'TEST_TABLE' (TABLE) (Cost=2 Card=1 Bytes=78)
    7 6 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1)
    8 1 FILTER
    9 8 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=6 Bytes=468)
    10 8 MINUS
    11 10 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=26)
    12 10 TABLE ACCESS (BY INDEX ROWID) OF 'TEST_TABLE' (TABLE) (Cost=2 Card=1 Bytes=78)
    13 12 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1)
    Statistics
    53 recursive calls
    8 db block gets
    187 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    4 sorts (memory)
    0 sorts (disk)
    8 rows processed
    -- The above query is using index PK_TEST. But still it has FULL SCAN to the
    -- table two times it has the more cost.
    1st query --> SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    2nd query --> SELECT STATEMENT Optimizer=ALL_ROWS (Cost=16 Card=2 Bytes=156)
    My queries are:
    1) performance wise which query is better?
    2) how do i make the 1st query to use an index
    3) is there any other method to get the same result by using any index
    Appreciate your immediate help.
    Best regards
    Muthu

    Hi William
    Nice...it works.. I have added "o_id" and "o_no" are in part of the index
    and now the query uses the index
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    3 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    Statistics
    7 recursive calls
    0 db block gets
    21 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    But my questions are:
    1) In a where clause, if "<>" condition is used, then, whether the system will use the index. Because I have observed in several situations even though the column in where clause is indexed, since the where condition is "like" or "is null/is not null"
    then the index is not used. Same as like this, i assumed, if we use <> then indexes will not be used. Is it true?
    2) Now, after adding "o_id" and "o_no" columns to the index, the Execution plan is:
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    3 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    Before it was :
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    3 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    Difference only in Cost (reduced), not in Card, Bytes.
    Can you explain, how can i decide which makes the performace better (Cost / Card / Bytes). Full Scan / Range Scan?
    On statistics also:
    Before:
    Statistics
    52 recursive calls
    0 db block gets
    43 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    After:
    Statistics
    7 recursive calls
    0 db block gets
    21 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    Difference in recursive calls & consistent gets.
    Which one shows the query with better performance?
    Please explain..
    Regards
    Muthu

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • Getting error "Column is not indexed " when executing query on ORACLE 10g

    Hi all,
    When executing the below query im getting the error "ORA-20000:Column is not indexed"
    query:
    select xmlelement("nexml:result",xmlattributes('http://namespaces.nextance.com/nex/xml' as "xmlns:nexml"),xmlelement("nexml:value",count(*))).getClobVal()
    from "permission"
    where ( ((contains(object_value,'(searchDocument) inpath(/permission/action)') > 0)) and ((existsNode(object_value,'/permission[resource/resourcekey/@type[. = "document"]]') = 1)) and ((contains(object_value,'(GeneralUser) inpath(/permission/principal/@name)') > 0)) and ((existsNode(object_value,'/permission[principal/@type[. = "group"]]') = 1)) and ((existsNode(object_value,'/permission[type[. = "allow"]]') = 1)) and ((contains(object_value,'(nexip) inpath(/permission/resource/resourcekey/field/@value)') > 0) or (contains(object_value,'(Corporate) inpath(/permission/resource/resourcekey/field/@value)') > 0) or (contains(object_value,'(ProcurementAgreement) inpath(/permission/resource/resourcekey/field/@value)') > 0) or (contains(object_value,'(Procurement) inpath(/permission/resource/resourcekey/field/@value)') > 0) or (contains(object_value,'(SalesAgreement) inpath(/permission/resource/resourcekey/field/@value)') > 0)) )
    Then after checking some forum, i replaced "contains" with "ora:contains" and executed the query. Now im not getting the first error but got a new error "invalid relational operator"
    So please help me in resolving the errors?
    Thanks in advance.

    Anil kumar wrote:
    Hi,
    Thanks for your reply. Could you please explain your solution in detail?Hi,
    I just have a try...
    create table t (id int,my_lob clob)
    begin
    insert into t values(101,'Oracle redwood shores USA');
    insert into t values (102,'HP palo alto USA');
    insert into t values(103,'Capgemini  FRANCE');;
    end;
    create index my_idx on t(my_lob) indextype is ctxsys.context
    select *
    from t
    where contains(my_lob,'USA',1)>0
    Output
    ID      MY_LOB
    101     Oracle redwood shores USA
    102     HP palo alto USA Hope it helps,
    CKLP

  • Use of Indexes in select query

    Hello,
    This is on a 9i install.
    There is an index called form_id_idx on the form_id column.
    Why does this query use the index (autotrace indicates range scan on the index):
    select count(*) from table_name where form_id=123456;
    but this query does NOT use the index (autotrace indicates full table scan):
    select accepted from table_name where form_id=123456;
    This second query runs much faster when I use a hint on the index. Any help/suggestions?
    Thanks.

    The first query does NOT have to go to the Table it all. It can read the index to count the number of rows for "form_id=123456". An Index Range Scan would be fast.
    The second query has to go to the table to get the values for the "accepted" column for all the rows that have "form_id=123456". Remember that every get can require a read of 2 or more blocks -- at least one, probably 2 or 3, from the index and 1 from the table. If the number of rows is likely to be large then the number of block get operations would be high. In such cases, Oracle computes that it is faster to do a small set of multiblock reads to read the whole table (Table FullScan).
    Therefore, the optimzer weighs :
    a. how many rows it thinks will satisfy "form_id=123456"
    b. how many index + table block gets it would have to execute (all as single block read calls to the OS)
    versus
    x. how many multiblock read calls it thinks it has to execute to read the whole table
    If the available statistics on number of rows, cardinality or density and the size of the table indicate that operation "x" would be cheaper then operations "a" + "b", Oracle would prefer the latter.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • How to mention index in select query?

    Hi All,
       If I am using fields of two diffrent secondary index in a single select query on a table how I can mention that data should be picked according to first index used in the query?
    Regards
    Deepak

    Please search before asking basic questions.
    Thread locked.
    Rob

  • Appropriate index for a query with 3 ands

    Hi,
    I have the following table:
    PAGES
    BOOK_ID DIMENSION BEGIN_POS END_POS PAGE_TEXT
    where book_id is 64-bits, dimension is 32-bits, begin_pos is 32-bits, end_pos is 32-bits, and page_text is a blob (UTF-8)
    My query is:
    select * from PAGES
    where BOOK_ID = 1234 and DIMENSION = -2 and BEGIN_POS <= 10000 and 10000 < END_POS
    Which is sure to return 1 result.
    My question is what kind of (multi-column?) index or indices do I need for this query whose WHERE clause uses 4 columns?
    Thanks,
    Andy

    book_id is 64-bits, dimension is 32-bits, begin_pos is 32-bits, end_pos is 32-bitsI'm sorry, I don't understand how a column could be 64-bits an other one 32-bits, the wordsize is for all the database. Well, I maybe miss the point.
    My question is what kind of (multi-column?) index or indices do I need for this query whose WHERE clause uses 4 columns?That really depend, but you should not base your index creation on one query, but more than that. Maybe book_id is a unique key, then have a PK on it could be nice. For the other columns, it is difficult, they don't mean nothing for me.
    Nicolas.

  • Spatial Index problem with query

    I created a spatial index with user A. When i do a spatail query, i receive a good result. But, when i execute the same query with user B, i receive the following error :
    ERROR at line 1:
    ORA-13226: interface not supported without a spatial index
    ORA-06512: at "MDSYS.MD", line 1723
    ORA-06512: at "MDSYS.MDERR", line 8
    ORA-06512: at "MDSYS.SDO_3GL", line 58
    I don't understand why user B seems not to be able to see or use the spatal index created by user A.

    Hi,
    What version of spatial are you using? You might have to grant select access on the spatial index table to user b in older versions of spatial.

  • Index On In query columns

    Hi Alll,
    I have one query...can we have Index on: example:
    SELECT col1, col2
    FROM (SELECT Col1 as A, Col2 as B
              FROM tb) t1,
            (SELECT *
              FROM ts) t2
    WHERE t1.col1 = t2.col2Question can we have a virtual on Index on t1's column i.e. t1.A and t1.B

    Hi,
    you can have index on COL1 and COL2 on table tb. I think Virtual index are undocumented feature used by Oracle.
    thanks
    This likk will give you more info.
    http://www.dba-oracle.com/oracle_news/2005_6_29_inside_virtual_indexes.htm
    Edited by: Himanshu Kandpal on Jul 29, 2009 7:23 AM added the link

  • Using index in a query return few records than full table access

    Today we have an issue with a query, when it use the ok index the returned are not all records that apply to where clause condition.
    See bellow
    explain plan for
    select * from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 136999
    SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1882720105
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | TABLE ACCESS BY INDEX ROWID| ZAN_M03 |
    |* 2 | INDEX RANGE SCAN | PK_ZAN_M03 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    2 - access("M00AF"=TO_DATE('11/01/28','YY/MM/DD') AND "M00ZA"=10 AND
    "M00AC"=50 AND "M00AD">=136906 AND "M00AD"<=137141)
    filter("M00AD"<=137141 AND "M00AD">=136906)
    Note
    - rule based optimizer used (consider using cbo)
    20 rows selected.
    The query above return only one row insted 1579 record that apply to this conditions.
    When forcing a full table acess with a hint, the query return all records that apply, the 1579 record.
    select /*+ FULL(zan_m03) */ M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 137141
    Can you help me to identify what's happening?
    I am with Oracle 10g R2 10.2.0.4 standard edition
    the statistics are up to date
    the opitimizer_mode are rule, but altering in session level to all_rows happens the same issue.
    Nothing about corruption in the alert log.
    Thanks in advance
    Regards
    Cristiano

    Yes the query are the same and correct restriction for where clause are M00AD between 136906 and 137141.
    I've pasted, by mistake, another test query
    The corrects are:
    select M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 137141
    This use pk index and return one row
    select /*+ FULL(zan_m03) */ M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 137141
    This does a full table access and return 1579 records
    I´ve been searching for wrong results bugs on my oracle support, but not found one that mentions something like our issue.
    I checked the dba_tables and dba indexes and the number of rows are different, and I think this would be the same because it's is a pk.
    Look this
    SQL> select NUM_ROWS from dba_tables where table_name = 'ZAN_M03'
    2 /
    NUM_ROWS
    228527878
    select NUM_ROWS from dba_indexes where index_name = 'PK_ZAN_M03';
    SQL> select NUM_ROWS from dba_indexes where index_name = 'PK_ZAN_M03';
    NUM_ROWS
    217510185
    Is normal a index for pk having much fewer rows than table? I think not, but not sure.
    Again
    Thanks in advance
    Regards
    Cristiano

  • BITMAP indexes ignored with large IN(...)

    I have a fact table with 20 million records joined to a few dimension tables using 10g BITMAP INDEXes but if I add more than two or three items to my SELECT query the optimizer does not choose to use the bitmaps. For example, the first query
    SELECT p.period_date, po.agent_id, count(*), SUM(ah.charge_amt)
    FROM Travel_History ah, Period p, Agent po
    WHERE ah.primary_agent_key = po.agent_key
    AND ah.period_key = p.period_key
    AND po.agent_id IN( 'DGF ', '001MG ' )
    AND p.period_date =
    TO_DATE( '20010701', 'YYYYMMDD' )
    AND p.period_date =
    TO_DATE( '20010801', 'YYYYMMDD' )
    GROUP BY po.agent_id, p.period_date
    definitely uses my BITMAPs as I see that in my EXECUTION PLAN (i.e. I have set autotrace on):
    | 0 | SELECT STATEMENT | | 1 | 32
    | 1 | HASH GROUP BY | | 1 | 32
    |* 2 | FILTER | | |
    | 3 | NESTED LOOPS | | 1 | 32
    |* 4 | HASH JOIN | | 1 | 19
    |* 5 | TABLE ACCESS FULL | PERIOD | 1 | 10
    | 6 | TABLE ACCESS BY INDEX ROWID | TRAVEL_HISTORY | 4000K| 34
    | 7 | BITMAP CONVERSION TO ROWIDS | | |
    | 8 | BITMAP AND | | |
    | 9 | BITMAP OR | | |
    |* 10 | BITMAP INDEX SINGLE VALUE| XIF4TRAVEL_HISTORY | |
    |* 11 | BITMAP INDEX SINGLE VALUE| XIF4TRAVEL_HISTORY | |
    | 12 | BITMAP MERGE | | |
    |* 13 | BITMAP INDEX RANGE SCAN | TRVLHIST_MULTI3_BMIX | |
    |* 14 | BITMAP INDEX SINGLE VALUE | XIF1TRAVEL_HISTORY | |
    |* 15 | TABLE ACCESS BY INDEX ROWID | AGENT | 1 | 13
    |* 16 | INDEX UNIQUE SCAN | XPKAGENT | 1 |
    There are only a few hundred records for those two dates, and the above query returns in
    less than a second.
    However, if I replace the two "period_date =" with IN(...) as:
    SELECT /*+ INDEX_COMBINE( Travel_history
    AcctHist_MULTI3_bmix
    XIF4TRAVEL_HISTORY
    XIF1TRAVEL_HISTORY )
    p.period_date, po.agent_id, count(*), SUM(ah.charge_amt)
    FROM Travel_History ah, Period p, Agent po
    WHERE ah.primary_agent_key = po.agent_key
    AND ah.period_key = p.period_key
    AND po.agent_id IN( 'DGF ', '001MG ' )
    AND p.period_date IN (
    TO_DATE( '20010701', 'YYYYMMDD' ),
    TO_DATE( '20010801', 'YYYYMMDD' ) )
    GROUP BY po.agent_id, p.period_date
    the execution plan goes back to
    | 0 | SELECT STATEMENT | | 747 | 23904 | 45760 (7)|
    | 1 | HASH GROUP BY | | 747 | 23904 | 45760 (7)|
    |* 2 | FILTER | | | | |
    |* 3 | HASH JOIN | | 5000K| 152M| 44897 (5)|
    | 4 | MERGE JOIN CARTESIAN| | 860 | 19780 | 26 (0)|
    |* 5 | TABLE ACCESS FULL | PERIOD | 4 | 40 | 6 (0)|
    | 6 | BUFFER SORT | | 215 | 2795 | 20 (0)|
    | 7 | TABLE ACCESS FULL | AGENT | 215 | 2795 | 5 (0)|
    | 8 | TABLE ACCESS FULL | TRAVEL_HISTORY | 20M| 171M| 44527 (4)|
    If I do a UNION with two SELECTs each with a unique period then the BITMAPs get used. I don't get it.
    Is there any reason this would be happening???

    There are no bitmap indexes, there is a 64k tablespace header block containing the bitmap of occupied and free extents.
    Sybrand Bakker
    Senior Oracle DBA

  • Index slows down query execution

    Hello everybody,
    I have reordered the join conditions for the query...
    select (first_name||' '||middle_name||' '||last_name) name,regn_no,age,gender,
    (select loc_name from locations where loc_id=location_code and loc_h_id='L6') district,
    person_id from persons p,musers u where reg_center_id=u.center_id and
    p.ipop='RG' and u.user_id = '8832' and u.eff_end_dt is null and p.CID = '1' order by p.crt_dt desc
    like this...
    select (first_name||' '||middle_name||' '||last_name) name,regn_no,age,gender,
    (select loc_name from locations where loc_id=location_code and loc_h_id='L6') district,
    person_id from musers u, persons p where reg_center_id=u.center_id and u.user_id = '8832'
    and p.ipop='RG' and u.eff_end_dt is null and p.CID = '1'
    because
    select count(*) from persons p, musers u where reg_center_id=u.center_id and
    p.ipop='RG' is 13002
    and
    select count(*) from persons p, musers u where reg_center_id=u.center_id and u.user_id = '8832' is 1007.
    In this excercise I have a couple of questions..
    1. This did not show any difference in the CPU time.
    and,
    I have created an index 'idx_ipop_persons' on persons(ipop) "create index idx_ipop_persons on persons(ipop)".
    2. The query is taking more time to execute than it was before creating the index.
    Please help me...
    Thanks,
    Aswin.

    Please post the execution plan for your query.
    And also i need some details:
    select count(*) from person where ipop='RG';
    How many records fetch?
    select distinct ipop from persons; --How many
    records fetch?
    Regards
    RajaBaskar
    Execution plan:
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=921 Card=176 Bytes
    =11088)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATIONS' (TABLE)
    (Cost=2 Card=1 Bytes=38)
    2 1 INDEX (RANGE SCAN) OF 'IDX_LOCID_LOCHDR_LOCATIONS' (INDE
    X) (Cost=1 Card=1)
    3 0 TABLE ACCESS (BY INDEX ROWID) OF 'PERSONS' (TABLE) (
    Cost=918 Card=176 Bytes=9152)
    4 3 NESTED LOOPS (Cost=921 Card=176 Bytes=11088)
    5 4 TABLE ACCESS (BY INDEX ROWID) OF 'MUSERS' (TA
    BLE) (Cost=3 Card=1 Bytes=11)
    6 5 INDEX (RANGE SCAN) OF 'PK_MUSERS' (INDEX (UNIQUE)
    ) (Cost=2 Card=1)
    7 4 INDEX (RANGE SCAN) OF 'IDX2_PERSONS' (INDEX) (Co
    st=1 Card=1464)
    select count(*) from person where ipop='RG';
    count(*)
    12135
    select distinct ipop from persons;
    distinct ipop
    RG
    OP
    IP
    RF
    CR

Maybe you are looking for