Different Cost values for full table scans

I have a very simple query that I run in two environments (Prod (20 CPU) and Dev (12 CPU)). Both environemtns are HPUX, oracle 9i.
The query looks like this:
SELECT prd70.jde_item_n
FROM gdw.vjda_gdwprd68_bom_cmpnt prd68
,gdw.vjda_gdwprd70_gallo_item prd70
WHERE prd70.jde_item_n = prd68.parnt_jde_item_n
AND prd68.last_eff_t+nvl(to_number(prd70.auto_hld_dy_n),0)>= trunc(sysdate)
GROUP BY prd70.jde_item_n
When I look at the explain plans, there is a significant difference in cost and I can't figure out why they would be different. Both queries do full table scans, both instances have about the same number of rows, statistics on both are fresh.
Production Plan:
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=18398 Card=14657 B
ytes=249169)
1 0 SORT (GROUP BY) (Cost=18398 Card=14657 Bytes=249169)
2 1 HASH JOIN (Cost=18304 Card=14657 Bytes=249169)
3 2 TABLE ACCESS (FULL) OF 'GDWPRD70_GALLO_ITEM' (Cost=949
4 Card=194733 Bytes=1168398)
4 2 TABLE ACCESS (FULL) OF 'GDWPRD68_BOM_CMPNT' (Cost=5887
Card=293149 Bytes=3224639)
Development plan:
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3566 Card=14754 B
ytes=259214)
1 0 HASH GROUP BY (GROUP BY) (Cost=3566 Card=14754 Bytes=259214)
2 1 HASH JOIN (Cost=3558 Card=14754 Bytes=259214)
3 2 TABLE ACCESS (FULL) OF 'GDWPRD70_GALLO_ITEM' (Cost=1914
4 Card=193655 Bytes=1323598)
4 2 TABLE ACCESS (FULL) OF 'GDWPRD68_BOM_CMPNT' (Cost=1076
Card=295075 Bytes=3169542)
There seems to be no reason for the costs to be so different, but I'm hoping that someone will be able to lead me in the right direction.
Thanks,
Jdelao

This link may help:
http://jaffardba.blogspot.com/2007/07/change-behavior-of-group-by-clause-in.html
But looking at the explain plans one of them uses a SORT (GROUP BY) (higher cost query) and the other uses a HASH GROUP BY (GROUP BY) (lower cost query). From my searches on the `Net the HASH GROUP BY is a more efficient algorithm than the SORT (GROUP BY) which would lead me to believe that this is one of the reasons why the cost values are so different. I can't find which version HASH GROUP BY came in but quick searches indicate 10g for some reason.
Are your optimizer features parameter set to the same value? In general you could compare relevant parameters to see if there is a difference.
Hope this helps!

Similar Messages

  • Bitmap index column goes for full table scan

    Hi all,
    Database : 10g R2
    OS : Windows xp
    my select query is :
    SELECT tran_id, city_id, valid_records
    FROM transaction_details
    WHERE type_id=101;
    And the Explain Plan is :
    Plan
    SELECT STATEMENT ALL_ROWSCost: 29 Bytes: 8,876 Cardinality: 634
    1 TABLE ACCESS FULL TABLE TRANSACTION_DETAILS** Cost: 29 Bytes: 8,876 Cardinality: 634
    total number of rows in the table = 1800 ;
    distinct value of type_ids are 101,102,103
    so i created a bit map index on it.
    CREATE BITMAP INDEX btmp_typeid ON transaction_details
    (type_id)
    LOGGING
    NOPARALLEL;
    after creating the index, the explain plan shows the same. why it goes for full table scan?.
    Kindly share ur idea on this.
    Edited by: 887268 on Apr 3, 2013 11:01 PM
    Edited by: 887268 on Apr 3, 2013 11:02 PM

    >
    I am sorry for being ignorant, can you please cite any scenario of locking due to bitmap indices? A link can be useful as well.
    >
    See my full reply in this thread
    Bitmap index for FKs on Fact tables
    >
    ETL is affected because DML operations (INSERT/UPDATE/DELETE) on tables with bitmapped indexes can have serious performance issues due to the serialization involved. Updating a single bit-mapped column value (e.g. from 'M' to 'F' for gender) requires both bitmapped index blocks to be locked until the update is complete. A bitmap index stored ROWID ranges (min rowid - max rowid) than can span many, many records. The entire 'range' of rowids is locked in order to change just one value.
    To change from 'M' the 'M' rowid range for that one row is locked and the ROWID must be removed from the range byt clearing the bit. To change to 'F' the 'F' rowid id range needs to be found, locked and the bit set that corresponds to that rowid. No other rows with rowids in the range can be changed since this is a serial operation. If the range includes 1000 rows and they all need changed it takes 1000 serial operations.

  • "db file scattered read" too high and Query going for full table scan-Why ?

    Hi,
    I had a big table of around 200mb and had a index on it.
    In my query I am using the where clause which has to use the
    index. I am neither using any not null condition
    nor using any function on the index fields.
    Still my query is not using the index.
    It is going for full table scan.
    Also the statspack report is showing the
    "db file scattered read" too high.
    Can any body help and suggest me why this is happenning.
    Also tell me the possible solution for it.
    Thanks
    Arun Tayal

    "db file scattered read" are physical reads/multi block reads. This wait occurs when the session reading data blocks from disk and writing into the memory.
    Take the execution plan of the query and see what is wrong and why the index is not being used.
    However, FTS are not always bad. By the way, what is your db_block_size and db_file_multiblock_read_count values?
    If those values are set to high, Optimizer always favour FTS thinking that reading multiblock is always faster than single reads (index scans).
    Dont see oracle not using index, just find out why oracle is not using index. Use the INDEX hint to force optimizer to use index. Take the execution with/witout index and compare the cardinality,cost and of course, logical reads.
    Jaffar
    Message was edited by:
    The Human Fly

  • SIDs for Full table scan wait events in db

    Guys,
    10.2.0.5/ 2 node RAC / RHEL-3
    CanAnyone provide me an sql to find all SID doing full table scans in a db?
    Thanks!
    Hari

    You ought to be able to query v$sql_plan for those sql plans with a full scan in them and if you want all the recent plans that contain a full table scan in them. You can join this back to v$session for those session currently executing a full table scan but if the sql in question was a previous statement executed by the session the join will not show the session because that statement is no longer the current statement.
    1 select p.sql_id, s.sid, p.object_name, p.operation, p.options
    2 from v$sql_plan p, v$session s
    3 where p.options like '%FULL%'
    4* and s.sql_id = p.sql_id
    You will probably want to filter out internal operations (operation = "FIXED TABLE")
    HTH -- Mark D Powell --

  • Avod full table scan help...

    HI ,
    I have sql with some filter and all the have index. the table size is huge index is there in explain plan though index it's going for full table scan it's not recognizing index. i used index hint/*+ INDEX (SYM.SYM_DEPL,SYM.SYDB_DE_N18) */ though it's not recoginizing index in explian plan going for full table scan. and qury take more time.
    please help to resolve the issue and it should recognize index rather than full table scan..

    user13301356 wrote:
    HI ,
    I have sql with some filter and all the have index. the table size is huge index is there in explain plan though index it's going for full table scan it's not recognizing index. i used index hint/*+ INDEX (SYM.SYM_DEPL,SYM.SYDB_DE_N18) */ though it's not recoginizing index in explian plan going for full table scan. and qury take more time.
    please help to resolve the issue and it should recognize index rather than full table scan..What is database version? Are all columns in the table indexed? Copy and paste the query that you are executing.

  • Full Table Scans for small tables... in Oracle10g v.2

    Hi,
    The Query optimizer may select to do a full table scan instead of an index scan when the table is small (it consists of blocks the number of which is less than the the value of db_file_multiblock_read_count).
    So , i tried to see it using the dept table......
    SQL> select blocks , extents , bytes from USER_segments where segment_name='DEPT';
        BLOCKS    EXTENTS      BYTES
             8          1      65536
    SQL> SHOW PARAMETER DB_FILE_MULTIBLOCK_READ_COUNT;
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     16
    SQL> explain plan for SELECT * FROM DEPT
      2    WHERE DEPTNO=10
      3  /
    Explained
    SQL>
    SQL>  select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2852011669
    | Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Tim
    |   0 | SELECT STATEMENT            |         |     1 |    23 |     1   (0)| 00:
    |   1 |  TABLE ACCESS BY INDEX ROWID| DEPT    |     1 |    23 |     1   (0)| 00:
    |*  2 |   INDEX UNIQUE SCAN         | PK_DEPT |     1 |       |     0   (0)| 00:
    Predicate Information (identified by operation id):
       2 - access("DEPTNO"=10)
    14 rows selectedSo , according to the above remarks
    What may be the reason of not performing full table scan...????
    Thanks...
    Sim

    No i have not generalized.... In the Oracle's extract
    i have posted there is the word "might".....
    I just want to find an example in which selecting
    from a small table... query optimizer does perform a
    full scan instead of a type of index scan...Sorry for that... I don't mean to be rude :)
    See following...
    create table index_test(id int, name varchar2(10));
    create index index_test_idx on index_test(id);
    insert into index_test values(1, 'name');
    commit;
    -- No statistics
    select * from index_test where id = 1;
    SELECT STATEMENT ALL_ROWS-Cost : 3
      TABLE ACCESS FULL MAXGAUGE.INDEX_TEST(1) ("ID"=1)
    -- If first rows mode?
    alter session set optimizer_mode = first_rows;
    select * from index_test where id = 1;
    SELECT STATEMENT FIRST_ROWS-Cost : 802
      TABLE ACCESS BY INDEX ROWID MAXGAUGE.INDEX_TEST(1)
       INDEX RANGE SCAN MAXGAUGE.INDEX_TEST_IDX (ID) ("ID"=1)
    -- If statistics is gathered
    exec dbms_stats.gather_table_stats(user, 'INDEX_TEST', cascade=>true);
    alter session set optimizer_mode = first_rows;
    select * from index_test where id = 1;
    SELECT STATEMENT ALL_ROWS-Cost : 2
      TABLE ACCESS BY INDEX ROWID MAXGAUGE.INDEX_TEST(1)
       INDEX RANGE SCAN MAXGAUGE.INDEX_TEST_IDX (ID) ("ID"=1)
    alter session set optimizer_mode = all_rows;
    select * from index_test where id = 1;
    SELECT STATEMENT ALL_ROWS-Cost : 2
      TABLE ACCESS BY INDEX ROWID MAXGAUGE.INDEX_TEST(1)
       INDEX RANGE SCAN MAXGAUGE.INDEX_TEST_IDX (ID) ("ID"=1) See some dramatic changes by the difference of parameters and statistics?
    Jonathan Lewis has written a great book on cost mechanism of Oracle optimizer.
    It will tell almost everything about your questions...
    http://www.amazon.com/Cost-Based-Oracle-Fundamentals-Jonathan-Lewis/dp/1590596366/ref=sr_1_1?ie=UTF8&s=books&qid=1195209336&sr=1-1

  • Entity Framework Generated SQL for paging or using Linq skip take causes full table scans.

    The slq genreated creates queries that cause a full table scan for pagination.  Is there any way to fix this?
    I am using
    ODP.NET ODTwithODAC1120320_32bit
    ASP.NET 4.5
    EF 5
    Oracle 11gR2
    This table has 2 million records. The further into the records you page the longer it takes.
    LINQ
    var cnt = (from errorLog in ctx.ERRORLOGANDSERVICELOG_VIEW
                        select errorLog).Count();
                    var query = (from errorLog in ctx.ERRORLOGANDSERVICELOG_VIEW
                                 orderby errorLog.ERR_LOG_ID
                                 select errorLog).Skip(cnt-10).Take(10).ToList();
    Here is the query & execution plans.
    SELECT *
    FROM   (SELECT "Extent1"."ERR_LOG_ID"  AS "ERR_LOG_ID",
                   "Extent1"."SRV_LOG_ID"  AS "SRV_LOG_ID",
                   "Extent1"."TS"          AS "TS",
                   "Extent1"."MSG"         AS "MSG",
                   "Extent1"."STACK_TRACE" AS "STACK_TRACE",
                   "Extent1"."MTD_NM"      AS "MTD_NM",
                   "Extent1"."PRM"         AS "PRM",
                   "Extent1"."INSN_ID"     AS "INSN_ID",
                   "Extent1"."TS_1"        AS "TS_1",
                   "Extent1"."LOG_ETRY"    AS "LOG_ETRY"
            FROM   (SELECT "Extent1"."ERR_LOG_ID"                                  AS "ERR_LOG_ID",
                           "Extent1"."SRV_LOG_ID"                                  AS "SRV_LOG_ID",
                           "Extent1"."TS"                                          AS "TS",
                           "Extent1"."MSG"                                         AS "MSG",
                           "Extent1"."STACK_TRACE"                                 AS "STACK_TRACE",
                           "Extent1"."MTD_NM"                                      AS "MTD_NM",
                           "Extent1"."PRM"                                         AS "PRM",
                           "Extent1"."INSN_ID"                                     AS "INSN_ID",
                           "Extent1"."TS_1"                                        AS "TS_1",
                           "Extent1"."LOG_ETRY"                                    AS "LOG_ETRY",
                           row_number() OVER (ORDER BY "Extent1"."ERR_LOG_ID" ASC) AS "row_number"
                    FROM   (SELECT "ERRORLOGANDSERVICELOG_VIEW"."ERR_LOG_ID"  AS "ERR_LOG_ID",
                                   "ERRORLOGANDSERVICELOG_VIEW"."SRV_LOG_ID"  AS "SRV_LOG_ID",
                                   "ERRORLOGANDSERVICELOG_VIEW"."TS"          AS "TS",
                                   "ERRORLOGANDSERVICELOG_VIEW"."MSG"         AS "MSG",
                                   "ERRORLOGANDSERVICELOG_VIEW"."STACK_TRACE" AS "STACK_TRACE",
                                   "ERRORLOGANDSERVICELOG_VIEW"."MTD_NM"      AS "MTD_NM",
                                   "ERRORLOGANDSERVICELOG_VIEW"."PRM"         AS "PRM",
                                   "ERRORLOGANDSERVICELOG_VIEW"."INSN_ID"     AS "INSN_ID",
                                   "ERRORLOGANDSERVICELOG_VIEW"."TS_1"        AS "TS_1",
                                   "ERRORLOGANDSERVICELOG_VIEW"."LOG_ETRY"    AS "LOG_ETRY"
                            FROM   "IDS_CORE"."ERRORLOGANDSERVICELOG_VIEW" "ERRORLOGANDSERVICELOG_VIEW") "Extent1") "Extent1"
            WHERE  ("Extent1"."row_number" > 1933849)
            ORDER  BY "Extent1"."ERR_LOG_ID" ASC)
    WHERE  (ROWNUM <= (10))
    | Id  | Operation              | Name                   | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |                        |    10 | 31750 |       |   821K  (1)| 02:44:15 |
    |*  1 |  COUNT STOPKEY         |                        |       |       |       |            |          |
    |   2 |   VIEW                 |                        |  1561K|  4728M|       |   821K  (1)| 02:44:15 |
    |*  3 |    VIEW                |                        |  1561K|  4748M|       |   821K  (1)| 02:44:15 |
    |   4 |     WINDOW SORT        |                        |  1561K|  3154M|  4066M|   821K  (1)| 02:44:15 |
    |*  5 |      HASH JOIN OUTER   |                        |  1561K|  3154M|       |   130K  (1)| 00:26:09 |
    |   6 |       TABLE ACCESS FULL| IDS_SERVICES_LOG       |  1047 | 52350 |       |     5   (0)| 00:00:01 |
    |   7 |       TABLE ACCESS FULL| IDS_SERVICES_ERROR_LOG |  1561K|  3080M|       |   130K  (1)| 00:26:08 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<=10)
       3 - filter("Extent1"."row_number">1933849)
       5 - access("T1"."SRV_LOG_ID"(+)="T2"."SRV_LOG_ID")

    I did try a sample from stack overflow that would apply it to all string types, but I didn't see any query results differences.  Please note, I am having the problem without any order with or where statements. Of course the skip take generates them.  Please advise how I would implement the EntityFunctions.AsNonUnicode method with this Linq query.
    LINQ
    var cnt = (from errorLog in ctx.ERRORLOGANDSERVICELOG_VIEW
                        select errorLog).Count();
                    var query = (from errorLog in ctx.ERRORLOGANDSERVICELOG_VIEW
                                 orderby errorLog.ERR_LOG_ID
                                 select errorLog).Skip(cnt-10).Take(10).ToList();
    This is what I inserted into my model to hopefully fix it.  FROM:c# - EF Code First - Globally set varchar mapping over nvarchar - Stack Overflow
    /// <summary>
    /// Change the "default" of all string properties for a given entity to varchar instead of nvarchar.
    /// </summary>
    /// <param name="modelBuilder"></param>
    /// <param name="entityType"></param>
    protected void SetAllStringPropertiesAsNonUnicode(
       DbModelBuilder modelBuilder,
       Type entityType)
       var stringProperties = entityType.GetProperties().Where(
      c => c.PropertyType == typeof(string)
       && c.PropertyType.IsPublic
       && c.

  • How to Reduce cost of full table scan or remove full table scan while execu

    Dear Experts
    need your help.
    I execute a query and create a explain plan in that plan i found cost of a table is very high (2777) and it was full table scan.
    Please guide me How to Reduce cost of full table scan or remove full table scan while execute the query.
    Thanks

    Need your help to tune this query..
    SELECT DISTINCT ool.org_id, ool.header_id, ooh.order_number, ool.line_id,
    ool.line_number, ool.shipment_number,
    NVL (ool.option_number, -99) option_number, xcl.GROUP_ID,
    xcl.attribute3, xcl.attribute4
    FROM oe_order_headers ooh,
    xxcn_comp_header xch,
    xxcn_comp_lines xcl,
    fnd_lookup_values_vl fvl,
    oe_order_lines ool
    WHERE 1 = 1
    AND ooh.org_id = 1524
    AND xch.src_ref_no = TO_CHAR (ooh.order_number)
    AND xch.src_ref_id = ooh.header_id
    AND xch.org_id = 1524
    AND xcl.header_id = xch.header_id
    AND ool.line_id = xcl.oe_line_id
    AND ool.flow_status_code IN
    ('WWD_SHIPPED',
    'FULFILLED',
    'SHIPPED',
    'CLOSED',
    'RETURNED'
    AND ool.org_id = 1524
    AND ool.header_id = ooh.header_id
    AND xch.org_id = 1524
    AND fvl.lookup_type = 'EMR OIC SOURCE FOR OU'
    AND fvl.tag = '1524'
    AND fvl.description = xch.SOURCE
    AND EXISTS (
    SELECT 1
    FROM oe_order_lines oe
    WHERE oe.header_id = ool.header_id
    AND oe.org_id = 1524
    AND oe.line_number = ool.line_number
    AND oe.ordered_item = ool.ordered_item
    AND oe.shipment_number > ool.shipment_number
    AND NVL (oe.option_number, -99) =
    NVL (ool.option_number,
    -99)
    AND NOT EXISTS (
    SELECT 1
    FROM xxcn_comp_lines xcl2
    WHERE xcl.GROUP_ID = xcl2.GROUP_ID
    AND oe.line_id = oe_line_id))
    call count cpu elapsed disk query current rows
    Parse 1 0.07 0.12 12 25 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 2 103.03 852.42 176206 4997766 0 12
    total 4 103.10 852.55 176218 4997791 0 12
    In this LIO is very high...can u please help in resolving this performance issue

  • URGENT HELP Required: Solution to avoid Full table scan for a PL/SQL query

    Hi Everyone,
    When I checked the EXPLAIN PLAN for the below SQL query, I saw that Full table scans is going on both the tables TABLE_A and TABLE_B
    UPDATE TABLE_A a
    SET a.current_commit_date =
    (SELECT MAX (b.loading_date)
    FROM TABLE_B b
    WHERE a.sales_order_id = b.sales_order_id
    AND a.sales_order_line_id = b.sales_order_line_id
    AND b.confirmed_qty > 0
    AND b.data_flag IS NULL
    OR b.schedule_line_delivery_date >= '23 NOV 2008')
    Though the TABLE_A is a small table having nearly 1 lakh records, the TABLE_B is a huge table, having nearly 2 and a half crore records.
    I created an Index on the TABLE_B having all its fields used in the WHERE clause. But, still the explain plan is showing FULL TABLE SCAN only.
    When I run the query, it is taking long long time to execute (more than 1 day) and each time I have to kill the session.
    Please please help me in optimizing this.
    Thanks,
    Sudhindra

    Check the instruction again, you're leaving out information we need in order to help you, like optimizer information.
    - Post your exact database version, that is: the result of select * from v$version;
    - Don't use TOAD's execution plan, but use
    SQL> explain plan for <your_query>;
    SQL> select * from table(dbms_xplan.display);(You can execute that in TOAD as well).
    Don't forget you need to use the {noformat}{noformat} tag in order to post formatted code/output/execution plans etc.
    It's also explained in the instruction.
    When was the last time statistics were gathered for table_a and table_b?
    You can find out by issuing the following query:select table_name
    , last_analyzed
    , num_rows
    from user_tables
    where table_name in ('TABLE_A', 'TABLE_B');
    Can you also post the results of these counts;select count(*)
    from table_b
    where confirmed_qty > 0;
    select count(*)
    from table_b
    where data_flag is null;
    select count(*)
    from table_b
    where schedule_line_delivery_date >= /* assuming you're using a date, and not a string*/ to_date('23 NOV 2008', 'dd mon yyyy');

  • How to find the count of tables going for fts(full table scan in oracle 10g

    HI
    how to find the count of tables going for fts(full table scan) in oracle 10g
    regards

    Hi,
    Why do you want to 'find' those tables?
    Do you want to 'avoid FTS' on those tables?
    You provide little information here. (Perhaps you just migrated from 9i and having problems with certain queries now?)
    FTS is sometimes the fastest way to retrieve data, and sometimes an index scan is.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9422487749968
    There's no 'FTS view' available, if you want to know what happens on your DB you need, like Anand already said, to trace sessions that 'worry you'.

  • Is it really another error about full table scans for small tables....?????

    Hi ,
    I have posted the following :
    Full Table Scans for small tables... in Oracle10g v.2
    and the first post of Mr. Chris Antognini was that :
    "I'm sorry to say that the documentation is wrong! In fact when a full table scan is executed, and the blocks are not cached, at least 2 I/O are performed. The first one to get the header block (where the extent map is stored) and the second to access the first and, for a very small table, only extent."
    Is it really wrong....????
    Thanks...
    Sim

    Fredrik,
    I do not say in any way that the documentation in this point is wrong.....
    In my first post , i have inserted a link to a thread made in another forum:
    Full Table Scans for small tables... in Oracle10g v.2
    Christian Antognini has written that the documentation is wrong....
    I'm sorry to say that the documentation is wrong!
    In fact when a full table scan is executed, and the
    blocks are not cached, at least 2 I/O are performed. The
    first one to get the header block (where the extent map
    is stored) and the second to access the first and, for a
    very small table, only extent.I'm just wondering if he has right......!!!!!!!
    Thanks..
    Sim

  • Selecting a column goes for a full table scan

    Hi,
    Oracle version 10.2
    I have the below query:
    SELECT   c.companyid,
             c.contactid,
             c.contactlname
        FROM contact c,company ic
       WHERE UPPER((c.contactlname)) LIKE CASE
               WHEN 'test' IS NULL THEN
                UPPER((c.contactlname))
               ELSE DECODE(1,
                       1,
                       '%' || 'TEST' || '%',
                       2,
                       'TEST' || '%',
                       3,
                       '%' || 'TEST',
                       4,
                       'TEST')
             END
         AND c.activeflag = DECODE('Y', 'N', 'Y', c.activeflag)
         AND ic.companyid=c.companyidthis is using the index on table company.
    Explain plan:
    SELECT STATEMENT, GOAL = ALL_ROWS               68     3523     176150     
    NESTED LOOPS               68     3523     176150     
      TABLE ACCESS FULL          CONTACT     65     3523     155012     
      INDEX UNIQUE SCAN          COMPANY_PK     0     1     6          Now if i include two more columns from the company table in the select statement the plan changes and it goes for a full table scan...
    Query:
    SELECT   ic.companyname,
             ic.companystatustypeid,
             c.companyid,
             c.contactid,
             c.contactlname
        FROM contact c,company ic
       WHERE UPPER((c.contactlname)) LIKE CASE
               WHEN 'test' IS NULL THEN
                UPPER((c.contactlname))
               ELSE DECODE(1,
                       1,
                       '%' || 'TEST' || '%',
                       2,
                       'TEST' || '%',
                       3,
                       '%' || 'TEST',
                       4,
                       'TEST')
             END
         AND c.activeflag = DECODE('Y', 'N', 'Y', c.activeflag)
         AND ic.companyid=c.companyidExplain Plan:
    SELECT STATEMENT, GOAL = ALL_ROWS               2126     4121     403858     
    HASH JOIN               2126     4121     403858     
      TABLE ACCESS FULL          CONTACT     108     4121     185445     
      PARTITION LIST ALL               1959     1031340     54661020     
       TABLE ACCESS FULL          COMPANY     1959     1031340     54661020     Any ideas why?

    dont think so.
    i tried removing the filters also:
    Query:
    SELECT  -- ic.companyname,
           --  ic.companystatustypeid,
    c.companyid,
             c.contactid,
             c.contactlname,
             c.contactfname,
             c.contactpositionid,
             c.contactroledesc,
             c.updateddate
        FROM contact c,company ic
       WHERE ic.companyid=c.companyidplan:
    SELECT STATEMENT, GOAL = ALL_ROWS               109     73346     3520608     
    NESTED LOOPS               109     73346     3520608     
      TABLE ACCESS FULL          CONTACT     51     73346     3080532     
      INDEX UNIQUE SCAN          COMPANY_PK     0     1     6     Query:
    SELECT   ic.companyname,
             ic.companystatustypeid,
    c.companyid,
             c.contactid,
             c.contactlname,
             c.contactfname,
             c.contactpositionid,
             c.contactroledesc,
             c.updateddate
        FROM contact c,company ic
       WHERE ic.companyid=c.companyid
         Plan:
    SELECT STATEMENT, GOAL = ALL_ROWS               2462     73346     6894524     
    HASH JOIN               2462     73346     6894524     
      TABLE ACCESS FULL          CONTACT     51     73346     3080532     
      PARTITION LIST ALL               1348     973674     50631048     
       TABLE ACCESS FULL          COMPANY     1348     973674     50631048     Does the columns selected have an impact on the plan?? I thought the plan is derived on basis of the join conditions...

  • VARRAY bind parameter in IN clause causes Full Table Scan

    Hi
    My problem is that Oracle elects to perform a full table scan when I want it to use an index.
    The situation is this: I have a single table SQL query with an IN clause such as:
    SELECT EMPNO, ENAME, JOB FROM EMP WHERE ENAME IN (...)
    Since this is running in an application, I want to allow the user to provide a list of ENAMES to search. Because IN clauses don't accept bind parameters I've been using the Tom Kyte workaround which relies on setting a bind variable to an array-valued scalar, and then casting this array to be a table of records that the database can handle in an IN clause:
    SELECT *
    FROM EMP
    WHERE ENAME IN (
    SELECT *
    FROM TABLE(CAST( ? AS TABLE_OF_VARCHAR)))
    This resulted in very slow performance due to a full table scan. To test, I ran the SQL in SQL*Plus and provided the IN clause values in the query itself. The explain plan showed it using my index...ok good. But once I changed the IN clause to the 'select * from table...' syntax Oracle went into Full Scan mode. I added an index hint but it didn't change the plan. Has anyone had success using this technique without a full scan?
    Thanks
    John
    p.s.
    Please let me know if you think this should be posted on a different forum. Even though my context is a Java app developed with JDev this seemed like a SQL question.

    Justin and 3360 - that was great advice and certainly nothing I would have come up with. However, as posted, the performance still wasn't good...but it gave me a term to Google on. I found this Ask Tom page http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:3779680732446#15740265481549, where he included a seemingly magical 'where rownum >=0' which, when applied with your suggestions, turned my query from minutes into seconds.
    My plans are as follows:
    1 - Query with standard IN clause
    SQL> explain plan for
    2 select accession_number, protein_name, sequence_id from protein_dim
    3 where accession_number in ('33460', '33458', '33451');
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 7 | 336 | 4 |
    | 1 | INLIST ITERATOR | | | | |
    | 2 | TABLE ACCESS BY INDEX ROWID| PROTEIN_DIM | 7 | 336 | 4 |
    | 3 | INDEX RANGE SCAN | IDX_PROTEIN_ACCNUM | 7 | | 3 |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    2 - Standard IN Clause with Index hint
    SQL> explain plan for
    2 select /*+ INDEX(protein_dim IDX_PROTEIN_ACCNUM) */
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source
    4 from pdssuser.protein_dim
    5 where accession_number in
    6 ('33460', '33458', '33451');
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 7 | 588 | 4 |
    | 1 | INLIST ITERATOR | | | | |
    | 2 | TABLE ACCESS BY INDEX ROWID| PROTEIN_DIM | 7 | 588 | 4 |
    | 3 | INDEX RANGE SCAN | IDX_PROTEIN_ACCNUM | 7 | | 3 |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    3 - Using custom TABLE_OF_VARCHAR type
    CREATE TYPE TABLE_OF_VARCHAR AS
    TABLE OF VARCHAR2(50);
    SQL> explain plan for
    2 select
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source
    4 from pdssuser.protein_dim
    5 where accession_number in
    6 (select * from table(cast(TABLE_OF_VARCHAR('33460', '33458', '33451') as TABLE_OF_VARCHAR)) t);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 168 | 57M|
    | 1 | NESTED LOOPS SEMI | | 2 | 168 | 57M|
    | 2 | TABLE ACCESS FULL | PROTEIN_DIM | 5235K| 419M| 13729 |
    | 3 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    4 - Using custom TABLE_OF_VARCHAR type w/ Index hint
    SQL> explain plan for
    2 select /*+ INDEX(protein_dim IDX_PROTEIN_ACCNUM) */
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source
    4 from pdssuser.protein_dim
    5 where accession_number in
    6 (select * from table(cast(TABLE_OF_VARCHAR('33460', '33458', '33451') as TABLE_OF_VARCHAR)) t);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 168 | 57M|
    | 1 | NESTED LOOPS SEMI | | 2 | 168 | 57M|
    | 2 | TABLE ACCESS BY INDEX ROWID | PROTEIN_DIM | 5235K| 419M| 252K|
    | 3 | INDEX FULL SCAN | IDX_PROTEIN_ACCNUM | 5235K| | 17255 |
    | 4 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    PLAN_TABLE_OUTPUT
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    12 rows selected.
    5 - Using custom TABLE_OF_VARCHAR type w/ cardinality hint
    SQL> explain plan for
    2 select
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source from protein_dim
    4 where accession_number in (select /*+ cardinality( t 10 ) */
    5 * from TABLE(CAST (TABLE_OF_VARCHAR('33460', '33458', '33451') AS TABLE_OF_VARCHAR)) t);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 168 | 57M|
    | 1 | NESTED LOOPS SEMI | | 2 | 168 | 57M|
    | 2 | TABLE ACCESS FULL | PROTEIN_DIM | 5235K| 419M| 13729 |
    | 3 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    6 - Using custom TABLE_OF_VARCHAR type w/ cardinality hint
    and rownum >= 0 constraint
    SQL> explain plan for
    2 select
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source from protein_dim
    4 where accession_number in (select /*+ cardinality( t 10 ) */
    5 * from TABLE(CAST (TABLE_OF_VARCHAR('33460', '33458', '33451') AS TABLE_OF_VARCHAR)) t
    6 where rownum >= 0);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 25 | 2775 | 43 |
    | 1 | TABLE ACCESS BY INDEX ROWID | PROTEIN_DIM | 2 | 168 | 3 |
    | 2 | NESTED LOOPS | | 25 | 2775 | 43 |
    | 3 | VIEW | VW_NSO_1 | 10 | 270 | 11 |
    | 4 | SORT UNIQUE | | 10 | | |
    | 5 | COUNT | | | | |
    | 6 | FILTER | | | | |
    PLAN_TABLE_OUTPUT
    | 7 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    | 8 | INDEX RANGE SCAN | IDX_PROTEIN_ACCNUM | 2 | | 2 |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    16 rows selected.
    I don't understand why performance improved so dramatically but happy that it did.
    Thanks a ton!
    John

  • Select statement in a function does Full Table Scan

    All,
    I have been coding a stored procedure that writes 38K rows in less than a minute. If I add another column which requires call to a package and 4 functions within that package, it runs for about 4 hours. I have confirmed that due to problems in one of the functions, the code does full table scans. The package and all of its functions were written by other contractors who have been long gone.
    Please note that case_number_in (VARCHAR2) and effective_date_in (DATE) are parameters sent to the problem function and I have verified through TOAD’s debugger that their values are correct.
    Table named ps2_benefit_register has over 40 million rows but case_number is an index for that table.
    Table named ps1_case_fs has more than 20 million rows but also uses case_number as an index.
    Select #1 – causes full table scan runs and writes 38K rows in a couple of hours.
    {case}
    SELECT max(a2.application_date)
    INTO l_app_date
    FROM dwfssd.ps2_benefit_register a1, dwfssd.ps2_case_fs a2
    WHERE a2.case_number = case_number_in and
    a1.case_number = a2.case_number and
    a2.application_date <= effective_date_in and
    a1.DOCUMENT_TYPE = 'F';
    {case}
    Select #2 – runs – hard coding values makes the code to write the same 38K rows in a few minutes.
    {case}
    SELECT max(a2.application_date)
    INTO l_app_date
    FROM dwfssd.ps2_benefit_register a1, dwfssd.ps2_case_fs a2
    WHERE a2.case_number = 'A006438' and
    a1.case_number = a2.case_number and
    a2.application_date <= '01-Apr-2009' and
    a1.DOCUMENT_TYPE = 'F';
    {case}
    Why using the values in the passed parameter in the first select statement causes full table scan?
    Thank you for your help,
    Seyed
    Edited by: user11117178 on Jul 30, 2009 6:22 AM
    Edited by: user11117178 on Jul 30, 2009 6:23 AM
    Edited by: user11117178 on Jul 30, 2009 6:24 AM

    Hello Dan,
    Thank you for your input. The function is not determinsitic, therefore, I am providing you with the explain plan. By version number, if you are refering to the Database version, we are running 10g.
    PLAN_TABLE_OUTPUT
    Plan hash value: 2132048964
    | Id  | Operation                     | Name                    | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT              |                         |   324K|    33M|  3138   (5)| 00:00:38 |       |       |
    |*  1 |  HASH JOIN                    |                         |   324K|    33M|  3138   (5)| 00:00:38 |       |       |
    |   2 |   BITMAP CONVERSION TO ROWIDS |                         |     3 |     9 |     1   (0)| 00:00:01 |       |       |
    |*  3 |    BITMAP INDEX FAST FULL SCAN| IDX_PS2_ACTION_TYPES    |       |       |            |          |       |       |
    |   4 |   PARTITION RANGE ITERATOR    |                         |   866K|    87M|  3121   (4)| 00:00:38 |   154 |   158 |
    |   5 |    TABLE ACCESS FULL          | PS2_FS_TRANSACTION_FACT |   866K|    87M|  3121   (4)| 00:00:38 |   154 |   158 |
    Predicate Information (identified by operation id):
       1 - access("AL1"."ACTION_TYPE_ID"="AL2"."ACTION_TYPE_ID")
       3 - filter("AL2"."ACTION_TYPE"='1' OR "AL2"."ACTION_TYPE"='2' OR "AL2"."ACTION_TYPE"='S')
    Thank you very much,
    Seyed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Taking more time in INDEX RANGE SCAN compare to the full table scan

    Hi all ,
    Below are the version og my database.
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for HPUX: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    I have gather the table statistics and plan change for sql statment.
    SELECT P1.COMPANY, P1.PAYGROUP, P1.PAY_END_DT, P1.PAYCHECK_OPTION,
    P1.OFF_CYCLE, P1.PAGE_NUM, P1.LINE_NUM, P1.SEPCHK  FROM  PS_PAY_CHECK P1
    WHERE P1.FORM_ID = :1 AND P1.PAYCHECK_NBR = :2 AND
    P1.CHECK_DT = :3 AND P1.PAYCHECK_OPTION <> 'R'
    Plan before the gather stats.
    Plan hash value: 3872726522
    | Id  | Operation         | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |              |       |       | *14306* (100)|          |
    |   1 |  *TABLE ACCESS FULL| PS_PAY_CHECK* |     1 |    51 | 14306   (4)| 00:02:52 |
    Plan after the gather stats:
    Operation     Object Name     Rows     Bytes     Cost
    SELECT STATEMENT Optimizer Mode=CHOOSE
              1           4
      *TABLE ACCESS BY INDEX ROWID     SYSADM.PS_PAY_CHECK*     1     51     *4*
        *INDEX RANGE SCAN     SYSADM.PS0PAY_CHECK*     1           3After gather stats paln look good . but when i am exeuting the query it take 5 hours. before the gather stats it finishing the within 2 hours. i do not want to restore my old statistics. below are the data for the tables.and when i am obserrving it lot of db files scatter rea
    NAME                                 TYPE        VALUE
    _optimizer_cost_based_transformation string      OFF
    filesystemio_options                 string      asynch
    object_cache_optimal_size            integer     102400
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.4
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      choose
    optimizer_secure_view_merging        boolean     TRUE
    plsql_optimize_level                 integer     2
    SQL> select count(*) from sysadm.ps_pay_check;
    select num_rows,blocks from dba_tables where table_name ='PS_PAY_CHECK';
      COUNT(*)
       1270052
    SQL> SQL> SQL>
      NUM_ROWS     BLOCKS
       1270047      63166
    Event                                 Waits    Time (s)   (ms)   Time Wait Class
    db file sequential read           1,584,677       6,375      4   36.6   User I/O
    db file scattered read            2,366,398       5,689      2   32.7   User I/Oplease let me know why it taking more time in INDEX RANGE SCAN compare to the full table scan?

    suresh.ratnaji wrote:
    NAME                                 TYPE        VALUE
    _optimizer_cost_based_transformation string      OFF
    filesystemio_options                 string      asynch
    object_cache_optimal_size            integer     102400
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.4
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      choose
    optimizer_secure_view_merging        boolean     TRUE
    plsql_optimize_level                 integer     2
    please let me know why it taking more time in INDEX RANGE SCAN compare to the full table scan?Suresh,
    Any particular reason why you have a non-default value for a hidden parameter, optimizercost_based_transformation ?
    On my 10.2.0.1 database, its default value is "linear". What happens when you reset the value of the hidden parameter to default?

Maybe you are looking for

  • How to restore a Db on another server

    Hello All, MaxDb 7.6.00.37. I need to copy my database from server A (Windows 2000) to Server B (Windows 2003). So i've installed the same version of MaxDb on server B, copy the last full backup from server A to server B, create the database instance

  • How can I add action listener to a cell or row in a table?

    hi there I need to be able to click on one cell or one row in a table, and perform some action, like openning a dialog or something. how can i add listener?

  • Scrollbar in a floater

    Hi everybody, I want to insert an area with a scrollbar in a floater panel, like dw's binding one. I tried frame, iframe, layer tags, div with overflow but nothing worked. Any ideas of how doing that ? Thx T0m_

  • Where is current version of my site??

    When I launch Muse, by default the Create New/Open a Recent Site window appears. I normally choose my site from Open a Recent Site. However, since a lot of recent sites were listed, including ones that really weren't recent and no longer used, last t

  • Disk Utility shows disk in SuperDrive when none is actually inserted.

    I am on Mac OS 10.5.1 and in Disk Utility Version 11.0 (252), in the left column, I see a disk icon while in fact no disk is inserted in disk-drive. Here is a screenshot of the Disk Utility window: http://img513.imageshack.us/my.php?image=picture1zb5