Why doesn't Oracle use my index?

Hi guys, imagine I have a table with columns A, B, C, D

It has a (non-unique) index on column D

When I run the query:

"SELECT A, B and C WHERE D > = ' 1.1.2010.

the index is never used, and it takes 20 minutes. The table has about 7 million lines. It doesn't matter what size of my result set is (even for a few lines), the plan of execution always shows me a full table scan. Only when I create an index on all 4 columns, the index is used. But this isn't a solution, because in my real application, I have about 20 columns in my SELECT clause. I also rebuilt the indexes and statistics.

Can someone help me?

Thank you!

890408 wrote:
Well, then this is the result of 3 queries:

Well, Oracle did what I thought it would be then. Don't you see how your density changed (and now matches the 1/NUM_DISTINCT)? Before this etait.33333 and now it's de.0024. So the estimated cardinalities went from 2 624 862 to 19 492 making it much more attractive index the optimizer.

As I mentioned in my previous post, you should be aware of your inclination of data. A large part of your data in this column is in the period of 01/01/1970. If someone asks for this Oracle is likely to try to use an index to chase these data that is not optimal.

Tags: Database

Similar Questions

  • How it warns Oracle to use an index for the join of two tables...

    How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?

    O.K. I think I should explain what I mean:

    When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.

    I have two tables: table A and table B.

    Table A has 4,000,000 entries and table B has 700,000 entries.

    I have a join of two tables with a numeric column as join criteria.

    There is an index on this column in A table.

    So I instead of
      where (A.col = B.col)
    I want to use
      where (A.col+0 = B.col)
    in order to avoid Oracle using the index.

    When I use the join in a select query, it works.

    But when I use the join as inline in an update statement I get the error ORA-01779.

    When I remove the '+ 0' the update statement works. (The column is unique in table B).

    Any ideas why this happens?

    Thank you very much in advance for any help.

    Hartmut cordially

    You plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html

  • Why the CBO will ignore my index?

    I have a strange situation with a "simple" query

    This is my table:
    CREATE TABLE 'BAG_MOVEMENTS '.
    ('MOVEMENT_ID' NUMBER(*,0) NOT NULL ACTIVATE,)
    ACTIVATE THE 'BAG_ID' NUMBER(*,0) NOT NULL,
    * "TRANSACTION_ID" ACTIVATE VARCHAR2 (255 BYTE) NOT NULL, * "
    ACTIVATE THE 'AMOUNT' FLOAT (126) NOT NULL,
    ACTIVATE "INSERT_DATE" STAMP (6) NOT NULL,
    NUMBER(*,0) "RATER_ID"
    NUMBER(*,0) "RATER_PLAN_ID"
    'START_DATE' TIMESTAMP (6).
    'END_DATE' TIMESTAMP (6).
    NUMBER(*,0) "SUBSERVICE_ID"
    NUMBER(*,0) "LEVEL_ID"
    VARCHAR2 (24 BYTE) "RATER_TYPE."
    'PK__BAG_MOVEMENTS' CONSTRAINT PRIMARY KEY ('MOVEMENT_ID'),
    KEY FOREIGN CONSTRAINT "FK_BA_REF_19553_BA" ("BAG_ID")
    SELECT REFERENCES 'BAG' ('BAG_ID') ON DELETE CASCADE
    );
    Here are the clues:
    CREATE INDEXES ' IDX$ $_53670001 ' ON 'BAG_MOVEMENTS' ("TRANSACTION_ID");

    CREATE INDEXES '_BAG_MOVEMENTS_FK1' ON 'BAG_MOVEMENTS' ('BAG_ID');

    CREATE AN INDEX UNIQUE 'BAG_MOVEMENTS_PK' ON 'BAG_MOVEMENTS' ('MOVEMENT_ID');

    I expect that the following query should use the IDX index $ $_53670001... and he does.
    Select * from BAG_MOVEMENTS
    where transaction_id = "32260-3gpp.org@9af63e37-521e-4fda-85d5-afb5768227fceebce62d-bc87-4915-8b56-ca255eb2a163"
    and rater_id <>- 1

    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 1805212729

    ---------------------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ---------------------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | 1. 141. 5 (0) | 00:00:01 |
    |* 1 | TABLE ACCESS BY INDEX ROWID | BAG_MOVEMENTS | 1. 141. 5 (0) | 00:00:01 |
    |* 2 | INDEX RANGE SCAN | IDX$ $_53670001 | 1 | | 4 (0) | 00:00:01 |
    ---------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 Filter ("RATER_ID" <>(-1))
    2 - access ("TRANSACTION_ID" = '32260-3gpp.org@9af63e37-521e-4fda-85d5-afb5768227fceebce62d-bc87-4915-8b56-ca255eb2a163')


    Statistics
    ----------------------------------------------------------
    1 recursive calls
    0 db block Gets
    6 compatible Gets
    2 physical reads
    0 redo size
    1434 bytes sent via SQL * Net to client
    492 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed


    When I use another TRANSACTION_ID I get FULL TABLE SCAN with a cost of 11887 (previous was 5!):
    Select *.
    of BAG_MOVEMENTS
    where transaction_id = "[email protected]@nov2902.mydomain.com;9998;1257262489;6458"
    and rater_id <>- 1;

    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 2308301958

    -----------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    -----------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | 802K | 107 M | 11887 (2) | 00:02:23 |
    |* 1 | TABLE ACCESS FULL | BAG_MOVEMENTS | 802K | 107 M | 11887 (2) | 00:02:23 |
    -----------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 - Filter ("TRANSACTION_ID" = "[email protected]@nov2902.mydomain.com;9998;1257262489;6458" AND "RATER_ID" <>(-1))


    Statistics
    ----------------------------------------------------------
    1 recursive calls
    0 db block Gets
    44365 compatible Gets
    0 physical reads
    0 redo size
    1501 bytes sent via SQL * Net to client
    492 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    2 rows processed

    If I force Oracle to use the index of the cost increases to 711685!
    Select / * + INDEX (IDX BAG_MOVEMENTS $$ _53670001) * / *.
    of BAG_MOVEMENTS
    where transaction_id = "[email protected]@nov2902.mydomain.com;9998;1257262489;6458"
    and rater_id <>- 1;

    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 1805212729

    ---------------------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ---------------------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | 802K | 107 M | 711K (1) | 02:22:21 |
    |* 1 | TABLE ACCESS BY INDEX ROWID | BAG_MOVEMENTS | 802K | 107 M | 711K (1) | 02:22:21 |
    |* 2 | INDEX RANGE SCAN | IDX$ $_53670001 | 810K | 8845 (1) | 00:01:47 |
    ---------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 Filter ("RATER_ID" <>(-1))
    2 - access ("TRANSACTION_ID" = '[email protected]@nov2902.mydomain.com;9998;1257262489;6458')


    Statistics
    ----------------------------------------------------------
    1 recursive calls
    0 db block Gets
    Gets 7 compatible
    2 physical reads
    0 redo size
    1501 bytes sent via SQL * Net to client
    492 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    2 rows processed

    Oracle is selecting the right plan for TRANSACTION_ID * "[email protected]@nov2902.mydomain.com;9998;1257262489;6458."
    But why he does not use the index in what concerns the TRANSACTION_ID * "32260-3gpp.org@9af63e37-521e-4fda-85d5-afb5768227fceebce62d-bc87-4915-8b56-ca255eb2a163?"

    Thank you

    Background stats task gathers the outdated statistics, so you could either turn it off completely and replace it with your own job (perhaps exaggerated if it works for most good for you), or lock the statistics for a table or set the table to NOMONITORING to prevent his stats being marked as stale. Then you need a job to collect statistics on a table using dbms_stats.gather_table_stats and passage of your own custom settings.

    To collect default statistics on only specified columns, you will need something like this:

    BEGIN
        DBMS_STATS.GATHER_TABLE_STATS
        ( 'yourtableowner'
        , 'bag_movements'
        , method_opt =>
          'for columns size auto movement_id bag_id amount insert_date rater_id rater_plan_id start_date end_date subservice_id level_id rater_type'
        , force => TRUE );
    END;
    

    Or collect transaction_id basic stats but no histograms.

    BEGIN
        DBMS_STATS.GATHER_TABLE_STATS
        ( 'yourtableowner'
        , 'bag_movements'
        , method_opt =>
          'for columns size auto movement_id bag_id amount insert_date rater_id rater_plan_id start_date end_date subservice_id level_id rater_type ' ||
          'for columns size 1 transaction_id'
        , force => TRUE );
    END;
    

    There is no syntax of ' all columns except ", so you'll have all the columns you need for statistics on the list. You might want to consider the option "size" for the other columns while you're there. The option 'force' is for when you have locked the stats to prevent the background stats task collect default statistics.

    Obviously, test to make sure it's doing what you want it to do, especially as the method_opt syntax is not clearly documented.

    Edited by: William Robertson on November 25, 2009 18:40

  • Why doesn't the cursor disappears whenever I use it to move the window (Windows: 32.0 FF)?

    Why doesn't the cursor disappears whenever I use it to move the window (Windows: 32.0 FF)? How to bring back the cursor?

    Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem.

    • Put yourself in the DEFAULT theme: Firefox/tools > Modules > appearance
    • Do NOT click on the reset button on the startup window Mode safe
  • Why doesn't a USB drive I have previously used with AirPort extreme appear in the finder when used locally with my Mac?

    Why doesn't a USB drive I have previously used with AirPort extreme appear in the finder when used locally with my Mac?

    I tried to plug it into my mac to transfer files locally but will not be displayed in the finder or disk utility. Anyone know why?

    MacBook Pro (2015 retina) OS X 10.11.2 El Capitan

    Have you shut down / turning your Mac off... power off the USB drive... Connect the drive to the Mac... start up the Mac... then, turn on the USB drive?

    If no help, there are a number of posts to the thread in the forum El Capitan of support from users who have problems on their Mac USB.  You can post there to see if anyone has the answers.

    OS X El Capitan

  • Why doesn't use Lightroom CC NOT my cpu to generate a slideshow?

    Why doesn't use Lightroom CC NOT my cpu to generate a slideshow? When I open the Task Manager, it shows that lightroom uses less than 1%. I have an i7 chip with 32g ram. After an hour, it is only 2% of fact.

    Hey Mohit;

    Thanks for the reply.

    My GPU is checked, and I found the problem. One of the photos in the slide show was missing. As soon as I removed the missing picture in slideshow, it works beautifully.

    Cheers, Paul

  • How Oracle use Index?

    RDBMS 11.2.0.3

    Hi all

    Suppose I have create the following table and the primary key:
    CREATE TABLE DUMMY_I( BOC NUMBER, START_TIME DATE, END_TIME DATE);
    
    ALTER TABLE DUMMY_I  
    MODIFY (BOC NOT NULL);
    
    ALTER TABLE DUMMY_I  
    MODIFY (START_TIME NOT NULL);
    
    ALTER TABLE DUMMY_I
    ADD CONSTRAINT DUMMY_I_PK PRIMARY KEY 
    ( BOC, START_TIME) ENABLE;
    A query with Oracle will use a PK Index:
    SELECT * FROM
    DUMMY_I 
    WHERE BOC = :v01
    AND START_TIME = :v02
    But the my dobout is when I need to add field in my query:
    SELECT * FROM
    DUMMY_I
    WHERE  BOC = :v01
    AND START_TIME = :v02
    AND END_TIME != :v03
    In the example above: how to create an Index to optimize my request?

    Given that BOC and START_TIME already have an index. Then I should create an Index unique addition field END_TIME and Oracle will use both indexes to optimize my request?
    Or
    I need to create a new Index with BOC, START_TIME, END_TIME?

    Hello

    Take a look at this, especially the Index scan to the chapter

    http://docs.Oracle.com/CD/E29597_01/server.1111/e16638/optimops.htm#autoId9

    Oracle uses indexes in several different ways, which will have much more to understand than a forum thread
    of course, if you have a specific question, pull :)

    on your original question:

    both cases are possible, but

    (a) index on BOC, START_TIME, END_TIME - its pretty simple so that it works and as simple good

    (b) index on BOC, START_TIME and END_TIME index
    Oracle can (but not necessarily will!) use both indexes in a JOIN INDEX, also a long time that you reference that these and any additional unindexed columns (if there is one)

    Given this example with queries, one is more appropriate here, but he cannot say in general.

  • Help for Oracle to use an index

    Unfortunately, I'm stuck with Oracle 8i. I have a fairly complex view which, at the time of the call, will have values specified for the columns in the view.

    The full view will look something like this - even if real life tables are slightly different and a little more complex. (view has been developed [another post | http://forums.oracle.com/forums/thread.jspa?threadID=1043162 & messageID = 4163818 #4163818]):
    select  a.skuid,
            sum(a.qty) qty,
            a.lot,
            b.status
            status
      from  (
             select  skuid,
                     lot,
                     1 qty,
                     row_number() over(partition by skuid order by lot) rn
               from  lot,
                     (
                      select  rownum rnum
                        from  all_objects
                        where rownum <= (select sum(qty) from lot)
                     )
               where rnum <= qty
            ) a,
            (
             select  skuid,
                     status,
                     sum(qty) over(order by qty desc) - qty + 1 start_rn,
                     sum(qty) over(order by qty desc) end_rn
               from  status
            ) b
      where b.skuid = a.skuid
        and a.rn between b.start_rn and end_rn
      group by  a.skuid,
                b.status,
                a.lot
      order by  a.skuid,
                b.status,
                a.lot
    When this view is called, there will certainly skuid and skuid is indexed. The problem I'm having becomes Oracle to bring the skuid specified in the Interior selects.

    For now, concentrate on the online portion "a":
     select  skuid,
          lot,
          1 qty,
          row_number() over(partition by skuid order by lot) rn
       from  lot,
          (
           select  rownum rnum
             from  row_gen
          )
       where rnum <= qty
    If I put this part of the display within a select statement as follows:
    select skuid, lot, sum(qty) from
    (
     select  skuid,
          lot,
          1 qty,
          row_number() over(partition by skuid order by lot) rn
       from  lot,
          (
           select  rownum rnum
             from  row_gen
             where rownum <= (select max(qty) from lot)
          )
       where rnum <= qty
       AND SKUID = 'SKUA' -- <--- Note indexed column here
    )
    group by skuid, lot
    Can I get a good result of query performance. Similar to this execution plan:
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=RULE
       1    0   SORT (GROUP BY)
       2    1     VIEW
       3    2       WINDOW (SORT)
       4    3         COUNT
       5    4           NESTED LOOPS
       6    5             VIEW
       7    6               COUNT (STOPKEY)
       8    7                 TABLE ACCESS (FULL) OF 'ROW_GEN'
       9    5             TABLE ACCESS (BY INDEX ROWID) OF 'LOT'
      10    9               INDEX (RANGE SCAN) OF 'LOT_SKU' (UNIQUE)
    However, when I move the indexed column outside the Interior view (where it will be in real life), like this:
    select skuid, lot, sum(qty) from
    (
     select  skuid,
          lot,
          1 qty,
          row_number() over(partition by skuid order by lot) rn
       from  lot,
          (
           select  rownum rnum
             from  row_gen
             where rownum <= (select max(qty) from lot)
          )
       where rnum <= qty
    )
    WHERE SKUID = 'SKUA' -- <--- Note indexed column here, 
                         --      since inner view will be an Oracle view, not inline view
    group by skuid, lot
    So in this case, the performance is very poor, with a similar to this execution plan:
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=RULE
       1    0   SORT (GROUP BY)
       2    1     VIEW
       3    2       WINDOW (SORT)
       4    3         COUNT
       5    4           NESTED LOOPS
       6    5             VIEW
       7    6               COUNT (STOPKEY)
       8    7                 TABLE ACCESS (FULL) OF 'ROW_GEN'
       9    5             TABLE ACCESS (FULL) OF 'LOT'
    In the example of real life, the unique key is actually 5 columns, but the principle, I think, it's the same.

    So, is it possible to write this request (which will be a view) such as Oracle (8i) realizes he can carry the values specified in the Interior selects and use the index for them?

    Published by: kent b on March 16, 2010 08:29

    Adding a / * + INDEX() * / index in the Interior, select help a little, but is still nowhere near as fast when the skuid is specified in the internal selection.

    Hello

    Here is another solution to this problem that uses any CONNECT BY and does not assume that this amount represents an integer.

    In your previous thread
    Re: Very challenging FINDS to write (call for help)
    Solomon has shown how we can avoid "explode" status in units, using a total cumulative.
    The solution below does the same thing for many, as well.

    SELECT       l.skuid
    ,            LEAST (l.max_qty, s.max_qty)
           - GREATEST (l.min_qty, s.min_qty)     AS qty
    ,       l.lot
    ,       s.status
    FROM       (     -- Begin in-line view l to get data from lot
                SELECT      skuid
              ,      lot
              ,      SUM (qty) OVER ( PARTITION BY  skuid
                                       ORDER BY       SUBSTR (lot, 1, 1)
                               ,          TO_NUMBER (SUBSTR (lot, 2))
                             )  - qty     AS min_qty
              ,      SUM (qty) OVER ( PARTITION BY  skuid
                                       ORDER BY       SUBSTR (lot, 1, 1)
                               ,          TO_NUMBER (SUBSTR (lot, 2))
                             )           AS max_qty
              FROM     lot
           ) l     -- End in-line view l to get data from lot
    ,       (      -- Begin in-line view s to get data from status
                SELECT      skuid
              ,      status
              ,      SUM (qty) OVER ( PARTITION BY  skuid
                                                 ORDER BY       CASE
                                            WHEN  status = 'AVAIL'  THEN  1
                                            WHEN  status = 'RES'     THEN  2
                                            WHEN  status = 'HOLD'     THEN  3
                                               END
                                 ) - qty     AS min_qty
              ,      SUM (qty) OVER ( PARTITION BY  skuid
                                                 ORDER BY       CASE
                                            WHEN  status = 'AVAIL'  THEN  1
                                            WHEN  status = 'RES'     THEN  2
                                            WHEN  status = 'HOLD'     THEN  3
                                               END
                                 )           AS max_qty
              FROM     status
           ) s     -- End in-line view s to get data from status
    WHERE       l.skuid      = s.skuid
    AND       l.min_qty    < s.max_qty
    AND       s.min_qty    < l.max_qty
    ORDER BY  l.skuid
    ,            l.max_qty
    ,       s.max_qty
    ;
    

    Published by: Frank Kulash, March 16, 2010 13:23

    It might be easier to manage if we pull the min_qty of the max_qty, like this:

    SELECT       l.skuid
    ,            LEAST (l.max_qty, s.max_qty)
           - GREATEST (l.min_qty, s.min_qty)     AS qty
    ,       l.lot
    ,       s.status
    FROM       (     -- Begin in-line view l to get data from lot
                SELECT      skuid,      lot
              ,      max_qty
              ,      max_qty - qty     AS min_qty
              FROM      (      -- Begin in-line view to get max_qty
                          SELECT      skuid,      lot,  qty
                         ,      SUM (qty) OVER ( PARTITION BY  skuid
                                                         ORDER BY       SUBSTR (lot, 1, 1)
                                           ,          TO_NUMBER (SUBSTR (lot, 2))
                                         )  AS max_qty
              FROM     lot
                    )      -- End in-line view to get max_qty
           ) l     -- End in-line view l to get data from lot
    ,       (      -- Begin in-line view s to get data from status
                SELECT      skuid,      status
              ,      max_qty
              ,      max_qty - qty     AS min_qty
              FROM      (      -- Begin in-line view to get max_qty
                          SELECT  skuid,  status,  qty
                         ,      SUM (qty) OVER ( PARTITION BY  skuid
                                                                  ORDER BY       CASE
                                                      WHEN  status = 'AVAIL'  THEN  1
                                                      WHEN  status = 'RES'     THEN  2
                                                      WHEN  status = 'HOLD'     THEN  3
                                                         END
                                           )  AS max_qty
              FROM     status
                    )      -- End in-line view to get max_qty
           ) s     -- End in-line view s to get data from status
    WHERE       l.skuid      = s.skuid
    AND       l.min_qty    < s.max_qty
    AND       s.min_qty    < l.max_qty
    ORDER BY  l.skuid
    ,            l.max_qty
    ,       s.max_qty
    ;
    
  • SDO_NN giving ORA-13249: SDO_NN cannot be assessed without using the index

    Hi people,

    I do not understand why the SDO_NN gives ORA-13249 in circumstances.

    SQL > SELECT SlavaTest WHERE SDO_NN s s.title (s.geometry, SDO_GEOMETRY (2001, 4326, SDO_POINT (14.0, 49.0, NULL), null, null)) = 'TRUE' and title like '%' and rownum < 10;

    TITLE
    --------------------------------------------------------------------------------
    MultiPoint_305199
    LineString_691779
    MultiPolygon_180478
    MultiPolygon_358113
    MultiPolygon_53008
    MultiPolygon_249905
    MultiPolygon_204076
    MultiPolygon_636994
    MultiPoint_464514

    9 selected lines.

    SQL > SELECT SlavaTest WHERE SDO_NN s s.title (s.geometry, SDO_GEOMETRY (2001, 4326, SDO_POINT (14.0, 49.0, NULL), null, null)) = 'TRUE' and timestamp > = to_timestamp (January 6, 2011 ', ' dd/mm/yyyy') and rownum < 10;
    SELECT SlavaTest WHERE SDO_NN s s.title (s.geometry, SDO_GEOMETRY (2001, 4326, SDO_POINT (14.0, 49.0, NULL), null, null)) = 'TRUE' and timestamp > = to_timestamp (January 6, 2011 ', ' dd/mm/yyyy') and rownum < 10
    *
    ERROR on line 1:
    ORA-13249: SDO_NN cannot be assessed without using the index
    ORA-06512: at the 'MDSYS. MD", line 1723
    ORA-06512: at the 'MDSYS. MDERR", line 17
    ORA-06512: at the 'MDSYS. PRVT_IDX', line 49

    The spatial index is created with:
    CREATE the INDEX SlavaTest_geometry_idx_spatial ON SlavaTest (geometry) INDEXTYPE IS mdsys.spatial_index;

    'Title' and 'timestamp' columns have an index.

    Note the query comes from Hibernate and I can't change it's arbitrary.

    Slava2 wrote:
    What this means - there is a bug in Oracle?

    Well, it could probably be considered a, but [url http://docs.oracle.com/cd/E11882_01/appdev.112/e11830/sdo_operat.htm#i78067] documentation on SDO_NN warns you:

    Documentation says:
    However, if the column in the WHERE clause predicate specifies a non-space column in the table for geometry1 with an associated index, make sure that this index is not used by specifying the NO_INDEX indicator for this index.

    See you soon,.
    Stefan

  • SELECT on a table in the INSERT statement uses the INDEX

    Hello world

    I have a strange problem with EA Oracle 10 g (64-bit) running on a Linux system. The situation is, I developed a Java program to migrate one client system to another. One of the steps in the migration fills a new table with the data from the old system. Given that the data on the old system structure is fundamentally different from that new, I have to check each time I read a line from the old system, if I have already created an entity on the new table, and if so, update certain attributes. The WHERE clause of this audit uses a key of the company indexed on the new table. The problem is now, that Oracle does not use the index on the key attribute of the company, but it makes table scans complete to select the line. As you can imagine, the lines first thousand or so go fast, but the amount increases, the program becomes slower and slower.

    If I do a "scan" when executing the migration program, Oracle change the execution plan and use the index on the attribute key and everything works fast and smooth. However, if I do the analysis on the empty table first, nothing changes (which I understand it perfectly, since there is nothing to analyze, at this point). By integrating a hint of 'INDEX' (table) in the statement SELECT does not change the full implementation plan (also table scans).

    Is it possible to change this behavior, in order to SELECT it uses the index of key business from the beginning?

    Greetings from Cologne,

    Thorsten.

    Published by: thkitz on 13.03.2012 18:27

    thkitz wrote:

    SELECT STATEMENT  ALL_ROWSCost: 2  Bytes: 76  Cardinality: 2
         7 TABLE ACCESS BY INDEX ROWID TABLE AIDATINT.PRVVSSCHADENKORRESPONDENZ Cost: 2  Bytes: 76  Cardinality: 2
              6 BITMAP CONVERSION TO ROWIDS
                   5 BITMAP OR
                        2 BITMAP CONVERSION FROM ROWIDS
                             1 INDEX RANGE SCAN INDEX AIDATINT.I_PRVVSSCHADENKORRESPONDENZ_1 Cost: 1
                        4 BITMAP CONVERSION FROM ROWIDS
                             3 INDEX RANGE SCAN INDEX AIDATINT.I_PRVVSSCHADENKORRESPONDENZ_2 Cost: 1  
    

    I would have thought that as a plan as possible. It is not a concatenation, is a btree/bitmap conversion.
    Allude to this plan you need / * + index_combine (table_alias index1 index2) * /.
    For 10g and later the index can be specified by name or by description

    I'm a bit puzzled why the plan changes after truncate - but maybe my comment about not cleared statistics is no longer true. It is easy enough to check if I'm right or wrong on your version of Oracle.

    Concerning
    Jonathan Lewis
    http://jonathanlewis.WordPress.com
    Author: core Oracle

  • Why hp disables the use of scanning and faxing because of the low level of ink on my photosmart c4385?

    Why hp disables the use of scanning and faxing because of the low level of ink? Printer says print cartridge missing or not detected. Doesn't make sense to me because the ink has absolutely nothing to do with the other functions. Since I bought this all in one I replace ink twice and I only printed about 10 pieces of paper for nine, making these extremely expensive 10 sheets!

    try reseating the cartridges once more & switch off the printer and remove power & other cables connected to the printer & press & hold the power for 20 seconds & then reconnect all cables back & then turn on the pritner & try to use that will solve the problem...

  • Why can I not use ready boost with flash player in my home premiun wvista?

    Why can I not use ready boost with flash player in my home premiun wvista?

    Hello

    This Flash drive is probably too slow for configure ReadyBoost.

    Here is some information that should help you:

    ReadyBoost
    http://www.vista4beginners.com/ReadyBoost

    What is ReadyBoost
    http://www.winvistatips.com/ReadyBoost-T25.html
    Explore the features: Windows ReadyBoost
    http://Windows.Microsoft.com/en-us/Windows7/products/features/ReadyBoost

    Understand the ReadyBoost and the question of whether it will Speed Up your system
    http://TechNet.Microsoft.com/en-us/magazine/ff356869.aspx

    DON'T GO OUT AND JUST BUY A READER WHO CLAIMS THAT IT IS READYBOOST
    LOAN - many are lying or stretching at least the truth. Look at the sides of the player below
    and buy one you know is FAST.

    Don't forget that the readyboost max cache is 4 GB Vista and 256 GB Windows 7. If your device
    is more than you can use it for storage. And you need a fast reader.

    ReadyBoost - list of speed Flash memory
    http://www.techcrater.com/2007/04/05/ReadyBoost-Flash-memory-speed-list/

    How to find the index of ReadyBoost speed
    http://www.techcrater.com/2007/04/06/how-to-find-ReadyBoost-speed-rating/

    Speed tests USB Flash Drive - any size car - link to the utility USBDeview
    http://usbspeed.NirSoft.NET/

    Publish a speed test of your USB - also a link to the utility USBDeview flash drive
    http://usbspeed.NirSoft.NET/publish_usb_flash_drive_speed.html

    http://www.grantgibson.co.uk/misc/ReadyBoost/?make=SanDisk

    http://www.techcrater.com/2007/04/05/ReadyBoost-Flash-memory-speed-list/

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • Why doesn't my itunes file drop-down 'show duplicates '?

    Why doesn't my itunes file drop-down 'show duplicates '?

    Support for products Apple is located in the Apple Forums:
    https://discussions.Apple.com/index.jspa

  • Why I can't use the nested aggregate function?

    Hello Experts,

    Why I can't use the nested aggregate function? There is not an ora-00979 group by error of expression.

    Oracle Database 11 g Release 11.2.0.4.0 - 64 bit Production

    Select

       SUM (BOX WHEN (KSD_CREATEDATE BETWEEN TRUNC((KSD_CREATEDATE)) AND TRUNC(MIN(KSD_CREATEDATE)) +60) THEN 1  ELSE 0 END) AS col

    DE TABLE_3_4

    GROUP BY STC_FIRMANO

    Thank you

    GROUP BY will manage the SUM function, but the MIN is used incorrectly - use another SELECTION to get it, or work with only with a single line. Otherwise, you could do WITH... get the SUM of SELECT MIN...

  • SDO_NN cannot be assessed without using the index when put inside subquery

    Hi all

    I met a problem when you use the function sdo_nn to find the nearest neighbor. Here is my scenario:

    _ I have 2 customer and store tables.

    Customer table _ a client_ID and a 2D sdo_geom point

    _ Store table has store_ID and a 2D polygon sdo_geom.

    In the beginning, I have this query to find the nearest store to each customer as below:

    Select s.STORE_ID, c.CLIENT_ID

    store customer, s c

    where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE";

    _It works as expected when it returns a table showing the nearest store each customer.

    _Now I want to count the number of customers who have the same nearest store:

    Select / * + INDEX (store store_spatial_idx, client_spatial_idx client) * / count (nearest_store. CLIENT_ID)
    from (select s.STORE_ID, c.CLIENT_ID
    store customer, s c
    where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE") nearest_store
    Group of nearest_store. STORE_ID;

    This query generates the following error:

    Error report-
    SQL error: ORA-13249: SDO_NN cannot be assessed without using the index
    ORA-06512: at the 'MDSYS. MD", line 1723
    ORA-06512: at the 'MDSYS. MDERR", line 17
    ORA-06512: at the 'MDSYS. PRVT_IDX', line 9
    13249 00000 - '%s '.

    I'm pretty new to spatial databases and hope get help to go further. Thank you in advance!

    Hello Pinball,

    Oracle space tends to be a quite complex with many variables and moving parts.  We chatted about the group to a sort of FAQ or guidelines to help people like you submit questions that actually answers.  First of all, you really have to tell us the version of Oracle you are using.  Particularly the problems involving the optimizer, version down to the exact defined patch number is a good idea.  Secondly, you took the time to submit the question so I guess you want a response.  If you really want to see the answer and then providing an example is one of the most important things that you can do.  I'm going to do here for you, but in general people on this forum come and go and are often pushed into lurkitude, so if you want the coax to provide you with an example of work is the key.

    DROP TABLE store1 PURGE;
    CREATE TABLE store1(
        store_id INTEGER NOT NULL
       ,shape    MDSYS.SDO_GEOMETRY
       ,PRIMARY KEY(store_id)
    );
    
    DROP TABLE client2 PURGE;
    CREATE TABLE client2(
        client_id INTEGER NOT NULL
       ,shape    MDSYS.SDO_GEOMETRY
       ,PRIMARY KEY(client_id)
    );
    
    CREATE OR REPLACE PROCEDURE seeder(
        p_client_count IN NUMBER
       ,p_store_count IN NUMBER
    )
    AS
      sdo_foo MDSYS.SDO_GEOMETRY;
      int_counter NUMBER;
      FUNCTION random_point
      RETURN MDSYS.SDO_GEOMETRY
      AS
          num_x1 NUMBER;
          num_y1 NUMBER;
    
      BEGIN
          num_x1 := dbms_random.value(-179,179);
          num_y1 := dbms_random.value(-89,89);
    
          RETURN MDSYS.SDO_GEOMETRY(
              2001
             ,8265
             ,MDSYS.SDO_POINT_TYPE(
                  num_x1
                 ,num_y1
                 ,NULL
              )
             ,NULL
             ,NULL
          );
    
      END random_point;
    
    BEGIN
      int_counter := 1;
      FOR i IN 1 .. p_client_count
      LOOP
          -- Create a client point
          sdo_foo := random_point();
          INSERT INTO client2
          VALUES (
              int_counter
             ,sdo_foo
          );
          int_counter := int_counter + 1;
    
      END LOOP;
    
      int_counter := 1;
      FOR i IN 1 .. p_store_count
      LOOP
          -- Create a store polygon of some kind
          sdo_foo := MDSYS.SDO_GEOM.SDO_ARC_DENSIFY(
              MDSYS.SDO_GEOM.SDO_BUFFER(
                  random_point()
                 ,5000
                 ,0.05
              )
             ,0.05
             ,'arc_tolerance=0.05'
          );
          INSERT INTO store1
          VALUES (
              int_counter
             ,sdo_foo
          );
          int_counter := int_counter + 1;
    
      END LOOP;
    
      COMMIT;
    
    END seeder;
    /
    
    BEGIN
      seeder(10000,200);
    END;
    /
    
    BEGIN
      INSERT INTO user_sdo_geom_metadata(
          table_name
         ,column_name
         ,diminfo
         ,srid
      ) VALUES (
          'STORE1'
         ,'SHAPE'
         ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05))
         ,8265
      );
    
      COMMIT;
    
    EXCEPTION
      WHEN OTHERS
      THEN
          NULL;
    
    END;
    /
    
    BEGIN
      INSERT INTO user_sdo_geom_metadata(
          table_name
         ,column_name
         ,diminfo
         ,srid
      ) VALUES (
          'CLIENT2'
         ,'SHAPE'
         ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05))
         ,8265
      );
    
      COMMIT;
    
    EXCEPTION
      WHEN OTHERS
      THEN
         NULL;
    
    END;
    /
    
    CREATE INDEX store1_spx ON store1
    (shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX
    NOPARALLEL;
    
    CREATE INDEX client2_spx ON client2
    (shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX
    NOPARALLEL;
    
    /* Works as expected */
    SELECT
    s.store_id
    ,c.client_id
    ,MDSYS.SDO_NN_DISTANCE(1)
    FROM
    store1 s
    ,client2 c
    WHERE
    MDSYS.SDO_NN(
        s.shape
       ,c.shape
       ,'sdo_num_res=1'
       ,1
    ) = 'TRUE';
    
    /* No worky? Works for me */
    SELECT
    ns.store_id
    ,COUNT(ns.client_id)
    FROM (
       SELECT
        s.store_id
       ,c.client_id
       FROM
        store1 s
       ,client2 c
       WHERE
       MDSYS.SDO_NN(
           s.shape
          ,c.shape
          ,'sdo_num_res=1'
          ,1
       ) = 'TRUE'
    ) ns
    GROUP BY
    ns.store_id
    ORDER BY
    ns.store_id;
    

    So I wrote this about 12 c (12.1.0.2.0) and everything works fine for me.  Then I moved back from 11 GR 2 (11.2.0.4.0) and of course, there are questions.  So I guess that you don't use flavor of 11g.  So at this point we can look at the docs and see for 11g, have you often need to specify which table is the head and that is the one that has the spatial index to use.
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_operat.htm#SPATL1032

    Its rather interesting that the optimizer of 12 c knows what you want, when I had to squint myself at your request and to play a little with the refining.  Note that SDO_NN is sensitive, because the geometry of the main table should come second in the operator.  I did not know that on the top of my head.

    
    SELECT
    /*+ LEADING(c) INDEX(s store1_spx)  */
     s.store_id
    ,c.client_id
    ,MDSYS.SDO_NN_DISTANCE(1)
    FROM
     store1 s
    ,client2 c
    WHERE
    MDSYS.SDO_NN(
        s.shape
       ,c.shape
       ,'sdo_num_res=1'
       ,1
    ) = 'TRUE';
    
    SELECT
     ns.store_id
    ,COUNT(ns.client_id)
    FROM (
       SELECT
       /*+ LEADING(c) INDEX(s store1_spx)  */
        s.store_id
       ,c.client_id
       ,MDSYS.SDO_NN_DISTANCE(1)
       FROM
        store1 s
       ,client2 c
       WHERE
       MDSYS.SDO_NN(
           s.shape
          ,c.shape
          ,'sdo_num_res=1'
          ,1
       ) = 'TRUE'
    ) ns
    GROUP BY
    ns.store_id
    ORDER BY
    ns.store_id;
    

    So I think that is your answer.  Give it a shot and see if this fits the Bill.  Of course, moving to 12 c would be useful for such things.  It would be interesting to collect more examples of this kind of space thing where 12 c is the answer. Also, would be nice if we could mark somehow this discussion as applying only to 11g and earlier versions.

    See you soon,.

    Paul

Maybe you are looking for