To_timestamp -vs- to_date and full table scans

Is it expected behavior for the to_timstamp function to negate the use of an index where the to_date does not?
Example:
The query:
SELECT hugea.intkey, hugea.stringkey, hugea.intnum, hugea.stringnum,
hugea.floatnum, hugea.longnum, hugea.doublenum, hugea.bytenum,
hugea.datevalue, hugea.timevalue, hugea.timestampvalue,
hugea.booleanvalue, hugea.charvalue, hugea.shortvalue,
hugea.bigintegervalue, hugea.bigdecimalvalue, hugea.objectvalue
FROM hugea
WHERE hugea.timestampvalue = {ts'2000-01-01 03:21:37[u].0'}
Submitted thru a java application generates the following trace IN ORACLE
=====================
PARSING IN CURSOR #4 len=452 dep=0 uid=65 oct=3 lid=65 tim=18446744071203520496 hv=3183903894 ad='6582cbe4'
SELECT hugea.intkey, hugea.stringkey, hugea.intnum, hugea.stringnum,
hugea.floatnum, hugea.longnum, hugea.doublenum, hugea.bytenum,
hugea.datevalue, hugea.timevalue, hugea.timestampvalue,
hugea.booleanvalue, hugea.charvalue, hugea.shortvalue,
hugea.bigintegervalue, hugea.bigdecimalvalue, hugea.objectvalue
FROM hugea
WHERE hugea.timestampvalue = to_timestamp('2000-01-01 03:21:37.0','YYYY-MM-DD HH24:MI:SS.FF')
END OF STMT
PARSE #4:c=359375,e=355026,p=0,cr=63,cu=3,mis=1,r=0,dep=0,og=4,tim=18446744071203520489
EXEC #4:c=0,e=1253028,p=0,cr=3,cu=0,mis=0,r=0,dep=0,og=4,tim=18446744071204773686
FETCH #4:c=0,e=2055128,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=18446744071206831146
STAT #4 id=1 cnt=0 pid=0 pos=1 obj=30620 op='TABLE ACCESS FULL HUGEA '*** 2004-07-30 16:06:28.000
=====================
The query:
SELECT hugea.intkey, hugea.stringkey, hugea.intnum, hugea.stringnum,
hugea.floatnum, hugea.longnum, hugea.doublenum, hugea.bytenum,
hugea.datevalue, hugea.timevalue, hugea.timestampvalue,
hugea.booleanvalue, hugea.charvalue, hugea.shortvalue,
hugea.bigintegervalue, hugea.bigdecimalvalue, hugea.objectvalue
FROM hugea
WHERE hugea.timestampvalue = {ts'2000-01-01 03:21:[u]37'}
Submitted thru a java application generates the following trace IN ORACLE
PARSING IN CURSOR #4 len=442 dep=0 uid=65 oct=3 lid=65 tim=18446744071260555440 hv=2315259180 ad='65343e30'
SELECT hugea.intkey, hugea.stringkey, hugea.intnum, hugea.stringnum,
hugea.floatnum, hugea.longnum, hugea.doublenum, hugea.bytenum,
hugea.datevalue, hugea.timevalue, hugea.timestampvalue,
hugea.booleanvalue, hugea.charvalue, hugea.shortvalue,
hugea.bigintegervalue, hugea.bigdecimalvalue, hugea.objectvalue
FROM hugea
WHERE hugea.timestampvalue = to_date('2000-01-01 03:21:37','YYYY-MM-DD HH24:MI:SS')
END OF STMT
PARSE #4:c=0,e=1058,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=18446744071260555431
EXEC #4:c=0,e=41,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=18446744071260555686
FETCH #4:c=0,e=58,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=4,tim=18446744071260557318
STAT #4 id=1 cnt=1 pid=0 pos=1 obj=30620 op='TABLE ACCESS BY INDEX ROWID HUGEA '
STAT #4 id=2 cnt=1 pid=1 pos=1 obj=31428 op='INDEX RANGE SCAN TIMESTAMPVALUE_IX '
Though the problem is related to JAVA/JDBC in this case. The underlying problem (to_date -vs- to_timestamp not acting the same insofar as INDEX utilization) is reproducible within SQL*Plus.
I also tried a function-based index and forced use with hints but had no success.
I'm hoping there is a patch of some kind and that this is simply due to the immaturity of the timestamp datatype.
please advise.

your test is then not relevant. if your table is to small, your statistics too old, your range too big, then oracle will not use an index.
SQL> insert into test_timestamp select timestamp '2000-01-01 00:00:00.00' + numtodsinterval(dbms_random.value,'DAY') from all_objects;
SQL> insert into test_timestamp select timestamp '2000-01-01 00:00:00.00' + numtodsinterval(dbms_random.value,'DAY') from all_objects;
SQL> select count(*) from test_timestamp;
  COUNT(*)
     74706
SQL> analyze table test_timestamp compute statistics;
Table analyzed.
SQL> create index test_timestamp_ix on test_timestamp(ts) compute statistics;
Index created.
SQL> set autot trace exp
SQL> select * from test_timestamp where ts between to_timestamp('2000-01-01','YYYY-MM-DD')  and to_timestamp('2000-01-01 00:00:05.00','YYYY-MM-DD HH24:MI:SS.FF');
Execution Plan
   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=187 Bytes=2
          057)
   1    0   FILTER
   2    1     INDEX (RANGE SCAN) OF 'TEST_TIMESTAMP_IX' (INDEX) (Cost=
          2 Card=187 Bytes=2057)

Similar Messages

  • Slow queries and full table scans in spite of context index

    I have defined a USER_DATASTORE, which uses a PL/SQL procedure to compile data from several tables. The master table has 1.3 million rows, and one of the fields being joined is a CLOB field.
    The resulting token table has 65,000 rows, which seems about right.
    If I query the token table for a word, such as "ORACLE" in the token_text field, I see that the token_count is 139. This query returns instantly.
    The query against the master table is very slow, taking about 15 minutes to return the 139 rows.
    Example query:
    select hnd from master_table where contains(myindex,'ORACLE',1) > 0;
    I've run a sql_trace on this query, and it shows full table scans on both the master table and the DR$MYINDEX$I table. Why is it doing this, and how can I fix it?

    After looking at the tuning FAQ, I can see that this is doing a functional lookup instead of an indexed lookup. But why, when the rows are not constrained by any structural query, and how can I get it to instead to an indexed lookup?
    Thanks in advance,
    Annie

  • Slow query due to large table and full table scan

    Hi,
    We have a large Oracle database, v 10g. Two of the tables in the database have over one million rows.
    We have a few queries which take a lot of time to execute. Not always though, it that seems when load is high the queries tend
    to take much longer. Average time may be 1 or 2 seconds, but maxtime can be up to 2 minutes.
    We have now used Oracle Grid to help us examine the queries. We have found that some of the queries require two or three full table scans.
    Two of the full table scans are of the two large tables mentioned above.
    This is an example query:
    SELECT table1.column, table2.column, table3.column
    FROM table1
    JOIN table2 on table1.table2Id = table2.id
    LEFT JOIN table3 on table2.table3id = table3.id
    WHERE table1.id IN(
    SELECT id
    FROM (
    (SELECT a.*, rownum rnum FROM(
    SELECT table1.id
    FROM table1,
    table2,
    table3
    WHERE
    table1.table2id = table2.id
    AND
    table2.table3id IS NULL OR table2.table3id = :table3IdParameter
    ) a
    WHERE rownum <= :end))
    WHERE rnum >= :start
    Table1 and table2 are the large tables in this example. This query starts two full table scans on those tables.
    Can we avoid this? We have, what we think are, the correct indexes.
    /best regards, Håkan

    >
    Hi Håkan - welcome to the forum.
    We have a large Oracle database, v 10g. Two of the tables in the database have over one million rows.
    We have a few queries which take a lot of time to execute. Not always though, it that seems when load is high the queries tend
    to take much longer. Average time may be 1 or 2 seconds, but maxtime can be up to 2 minutes.
    We have now used Oracle Grid to help us examine the queries. We have found that some of the queries require two or three full table scans.
    Two of the full table scans are of the two large tables mentioned above.
    This is an example query:Firstly, please read the forum FAQ - top right of page.
    Please format your SQL using tags [code /code].
    In order to help us to help you.
    Please post table structures - relevant (i.e. joined, FK, PK fields only) in the form - note use of code tags - we can just run table create script.
    CREATE TABLE table1
      Field1  Type1,
      Field2  Type2,
    FieldN  TypeN
    );Then give us some table data - not 100's of records - just enough in the form
    INSERT INTO Table1 VALUES(Field1, Field2.... FieldN);
    ..Please post EXPLAIN PLAN - again with tags.
    HTH,
    Paul...
    /best regards, Håkan

  • Nested Tables and Full Table Scans

    Hello,
    I am hoping someone help can help me as I am truly scratching my head.
    I have recently been introduced to nested tables due to the fact that we have a poor running query in production. What I have discovered is that when a table is created with a column that is a nested table a unique index is automatically created on that column.
    When I do an explain plan on this table A it states that a full scan is being doine on Table A and on the nested table B. I can add an index to the offending columns to remove the full scan on Table A but the explain plan still identifies that a full scan is being done on the nested table B. Bare in mind that the column with the nested table has a cardinality of 27.
    What can I do? As I stated, there is an index on this nested table column but clearly it is being ignored.The query bombed out after 4 hours and when I ran a query to see what the record count was it was only 2046.
    Any suggestions would be greatly appreciated.
    Edited by: user11887286 on Sep 10, 2009 1:05 PM

    Hi and welcome to the forum.
    Since your question is in fact a tuning request, you need to provide us some more insights.
    See:
    [How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    and also
    [When your query takes too long|http://forums.oracle.com/forums/thread.jspa?threadID=501834]
    In short:
    - database version
    - the actual queries you're executing
    - the execution plans (explain plans)
    - trace/tkprof output if available, or ask your DBA for it
    - utopiamode a small but concisive testcase would be ideal (create table + insert statements). +/utopiamode+

  • Full table scans and EUL

    Hi All,
    I am using Discoverer Version 10.1.2.1.
    I have few reports in which tables used in queries (used in Custom folders) go into full table scans inspite of all efforts in tuning.
    I came to know that full table scans also come from the way EUL is built and maintained.
    Can anyone please throw some light on how does EUL and full table scan relate.
    Also one more thing here, which is better to use, Database View on which we can base our folder or writing the complete complex query in the folder.
    Any help in this case will be appreciated.
    Regards,
    Ankur

    Hi,
    Can anyone please throw some light on how does EUL and full table scan relateThe database cost base optimiser processes the SQL that has been generated by Discoverer and creates an execution plan for the SQL. Now the execution plan will contain full table scans if the CBO calculates that FTS will give the best results. The CBO mainly uses the statistics held against the tables and the conditions in the SQL to calculate whether FTS would be better than using an index. The table join conditions are usually defined in the EUL but other conditions are usually in the workbook.
    So there are many factors which control whether the database uses an FTS and only a few of them are affected by how the EUL is built.
    Database View on which we can base our folder or writing the complete complex query in the folderIn general, it is always better to create a database view if that option is available to you. You can control and monitor the SQL in a database view much more easily than using a query in a custom folder.
    Rod West

  • Update doing full table scan and taking long time

    Hi All,
    I am running an update statement which is doing a full table scan.
    UPDATE Database.TABLE AS T
    SET COMMENTS = CAST(CAST(COALESCE(T.COMMENTS,0) AS INTEGER) + 1 AS
    CHARACTER)
    WHERE T.TRACKINGPOINT = 'NDEL'
    AND T.REFERENCENUMBER =
    SUBSTRING(Root.XML.EE_EAI_MESSAGE.ReferenceNumber || '
    ' FROM 1 FOR 32);
    Any advice.
    Regards,
    Umair

    Mustafa,
    No Developer is writing it in his program.
    Regards,
    Umair

  • Full table scan and how to avoid it

    Hello,
    I have two tables, one with 425,000 records, and the other with 5,200,000 records in it. The smaller table has an index on its unique primary key, and the bigger table has an index on the foreign key of the smaller table.
    When joining these two tables, I keep getting full table scans on both of these tables, and I would like to understand the philosophy behind it as well as ways to avoid this.
    Thanks

    Are you manipulating the join columns in any fashion? Such as applying a function to them like in
    to_char(column_a) = to_char(column_b)Because any manipulation like that will obviate your index (assuming you don't have function based indexes).
    Really though, without your tables, indexes and query, we're left with voodoo, which is cool, but not really that effective.
    *note to any and all practicing witch doctors, i really do think voodoo is cool and effective, please don't persecute me for my speakings.
    Message was edited by:
    Tubby

  • Question about Full Table Scans and Tablespaces

    Good evening (or morning),
    I'm reading the Oracle Concepts (I'm new to Oracle) and it seems that, based on the way that Oracle allocates and manages storage the following premise would be true:
    Premise: A table that is often accessed using a full table scan (for whatever reasons) would best reside in its own dedicated tablespace.
    The main reason I came to this conclusion is that when doing a full table scan, Oracle does multiblock I/O, likely reading one extent at a time. If the Tablespace's datafile(s) only contain data for a single table then a serial read will not have to skip over segments that contain data for other tables (as would be the case if the tablespace is shared with other tables). The performance improvement is probably small but, it would seem that there is one nonetheless.
    I'd like to have the thoughts of experienced DBAs regarding the above premise.
    Thank you for your contribution,
    John.

    Good morning :) Aman,
    >
    A little correction! A segment(be it a table,index, cluster, temporary) , would stay always in its own tablespace. Segments can't span tablespaces!
    >
    Fortunately, I understood that from the beginning :)
    You mentioned fragmentation, I understand that too. As rows get deleted small holes start existing in the segment and those holes are not easily reusable because of their limited size.
    What I am referring to is different though.
    Let's consider a tablespace that is the home of 2 or more tables, the tablespace in turn is represented by one or more OS datafiles, in that case the situation will be as shown in the following diagram (not a very good diagram but... best I can do here ;) ):
    Tablespace TablespaceWithManyTables
      (segment 1 contents)
        TableA Extent 1
          TableA Block 1
          TableA Block 2
          Fragmentation may happen in these blocks or
          even across blocks because Oracle allows rows
          to span blocks
          TableA Block n
        End of TableA Extent 1
        more extents here all for TableA
      (end of segment 1 contents)
      (segment 2 contents)
        TableZ Extent 5
          blocks here
        End of TableZ Extent 5
        more extents here, all for tableZ
      (end of segment 2 contents)
        and so on
      (more segments belonging to various tables)
    end of Tablespace TablespaceWithManyTablesOn the other hand, if the tablespace hosts only one table, the layout will be:
    Tablespace TablespaceExclusiveForTableA
      (segment 1 contents)
        TableA Extent 1
          TableA Block 1
          TableA Block 2
          Fragmentation may happen in these blocks or
          even across blocks because Oracle allows rows
          to span blocks
          TableA Block n
        End of TableA Extent 1
        another extent for TableA
      (end of segment 1 contents)
      (segment 2 contents)
        TableA Extent 5
          blocks here
        End of TableA Extent 5
        more extents for TableA
      (end of segment 2 contents)
      and so on
      (more segments belonging to TableA)
    end of Tablespace TablespaceExclusiveForTableAThe fragmentation you mentioned takes place in both cases. In the first case, regardless of fragmentation, some segments don't belong to the table that is being serially scanned, therefore they have to be skipped over at the OS level. In the second case, since all the extents belong to the same table, they can be read serially at the OS level. I realize that in that case the segments may not be read in the "right" sequence but they don't have to because they can be served to the client app in sequence.
    It is because of this that, I thought that if a particular table is mostly read serially, there might be a performance benefit (and also less work for Oracle) to dedicate a tablespace to it.
    I can't wait to see what you think of this :)
    John.

  • Full Table Scans and LRU

    Hello,
    In a full table scan I understand that the memory block used for a newly read table block is placed at the end of the LRU.
    When the second table block is read, is the same memory block replaced?
    What I am asking basically is whether for a full table scan only one block in the data buffer is ever used, with the same single block being recycled for the entire content of the table.
    Kind regards,
    Peter Strauss

    Hi Fidel,
    > In oracle 10g it changes a little the behavior. It is
    > recommended not to set MULTIBLOCK_READ_COUNT. You
    > calculate system statistics and Oracle "decides" the
    > <i>best </i>value.
    Take care... oracle 10gR2 uses the system statistic values to calculate the costs (= execution plan) including the i/o statistics but for the multiple i/o it uses the parameter DB_FILE_MULTIBLOCK_READ_COUNT.
    So the result is: For calculating it uses the system statistic and for the work itself it uses DB_FILE_MULTIBLOCK_READ_COUNT (if set).
    http://jonathanlewis.wordpress.com/2007/05/20/system-stats-strategy/
    For the LRU thing ... oracle has a nice explanation:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/memory.htm
    Regards
    Stefan

  • "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

  • 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');

  • Trunc causing Full Table Scans

    I have a situtaion here where my query is as follows.
    SQL> select count(1) from HBSM_SM_ACCOUNT_INFO where OPTIONAL_PARM5='MH' and CUST_STATUS in ('UP','UUP') and trunc(FIRST_ACTVN_DATE) = trunc(sysdate);
    COUNT(1)
    6
    PLAN_TABLE_OUTPUT
    Plan hash value: 3951750498
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1 | 10 | 13904 (1)| 00:02:47 | | |
    | 1 | SORT AGGREGATE | | 1 | 10 | | | | |
    | 2 | PARTITION LIST SINGLE| | 1 | 10 | 13904 (1)| 00:02:47 | 12 | 12 |
    |* 3 | TABLE ACCESS FULL | HBSM_SM_ACCOUNT_INFO | 1 | 10 | 13904 (1)| 00:02:47 | 12 | 12 |
    Predicate Information (identified by operation id):
    3 - filter(("CUST_STATUS"='UP' OR "CUST_STATUS"='UUP') AND
    TO_DATE(INTERNAL_FUNCTION("FIRST_ACTVN_DATE"))=TO_DATE(TO_CHAR(SYSDATE@!)))
    16 rows selected.
    If I remove the trunc clause from the query the performance definitely improves the the results are wrong.
    SQL> select count(1) from HBSM_SM_ACCOUNT_INFO where OPTIONAL_PARM5='MH' and CUST_STATUS in ('UP','UUP') and FIRST_ACTVN_DATE = trunc(sysdate);
    COUNT(1)
    0
    PLAN_TABLE_OUTPUT
    Plan hash value: 454529511
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1 | 40 | 47 (0)| 00:00:01 | | |
    |* 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| HBSM_SM_ACCOUNT_INFO | 1 | 40 | 47 (0)| 00:00:01 | 12 | 12 |
    |* 2 | INDEX RANGE SCAN | IND_FIRST_ACTVN_DATE | 51 | | 4 (0)| 00:00:01 | | |
    Can someone please help me whereby I can get the right data and I can also prevent these full table scans.

    Unless you are using a functional index, applying any function to an indexed column prevents the use of the index.
    The way round it in your case is to realise that
    select count(1) from HBSM_SM_ACCOUNT_INFO where OPTIONAL_PARM5='MH' and CUST_STATUS in ('UP','UUP') and trunc(FIRST_ACTVN_DATE) = trunc(sysdate)Is really asking that FIRST_ACTVN_DATE should be sometime today. You could therefore rewrite it as
    select count(1) from HBSM_SM_ACCOUNT_INFO where OPTIONAL_PARM5='MH' and CUST_STATUS in ('UP','UUP')
    and FIRST_ACTVN_DATE >= trunc(sysdate)
    and FIRST_ACTVN_DATE < trunc(sysdate) + 1Note, this still might not use the index depending on how many rows are within today's date versus how many are outside today's date.
    Also, when posting, remember to put your code between tags and to post create table scripts and sample data inserts.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem of full table scan on a partitioned table

    hi all
    There is a table called "si_sync_operation" that have 171040 number of rows.
    I partitioned that table into a new table called "si_sync_operation_par" with 7 partitoins.
    I issued the following statements
    SELECT * FROM si_sync_operation_par.
    SELECT * FROM si_sync_operation.
    The explain plan show that the cost of the first statement is 1626 and that of the second statments is 1810.
    The "cost" of full table scan on partitioned table is lower than the that of non-partitioned table.That's fine.
    But the "Bytes" of full table scan on partitioned table is 5761288680 and that of the non-partitioned table is 263743680.
    Why full table scan on partitioned table access more bytes than non-partitioned table?
    And how could a statment that access more bytes results a lower cost?
    Thank u very much

    As Hemant metioned bytes reported are approximate number of bytes. As far as Cost is concerned, according to Tom its just a number and we should not compare queries by their cost. (search asktom.oracle.com for more information)
    SQL> drop table non_part purge;
    Table dropped.
    SQL> drop table part purge;
    Table dropped.
    SQL>
    SQL> CREATE TABLE non_part
      2        (id  NUMBER(5),
      3         dt    DATE);
    Table created.
    SQL>
    SQL> CREATE TABLE part
      2        (id  NUMBER(5),
      3         dt    DATE)
      4         PARTITION BY RANGE(dt)
      5         (
      6         PARTITION part1_jan2008 VALUES LESS THAN(TO_DATE('01/02/2008','DD/MM/YYYY')),
      7         PARTITION part2_feb2008 VALUES LESS THAN(TO_DATE('01/03/2008','DD/MM/YYYY')),
      8         PARTITION part3_mar2008 VALUES LESS THAN(TO_DATE('01/04/2008','DD/MM/YYYY')),
      9         PARTITION part4_apr2008 VALUES LESS THAN(TO_DATE('01/05/2008','DD/MM/YYYY')),
    10         PARTITION part5_may2008 VALUES LESS THAN(TO_DATE('01/06/2008','DD/MM/YYYY'))
    11       );
    Table created.
    SQL>
    SQL>
    SQL> insert into non_part select rownum, trunc(sysdate) - rownum from dual connect by level <= 140;
    140 rows created.
    Execution Plan
    Plan hash value: 1731520519
    | Id  | Operation                     | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT              |      |     1 |     2   (0)| 00:00:01 |
    |   1 |  COUNT                        |      |       |            |          |
    |*  2 |   CONNECT BY WITHOUT FILTERING|      |       |            |          |
    |   3 |    FAST DUAL                  |      |     1 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter(LEVEL<=140)
    SQL>
    SQL> insert into part select * from non_part;
    140 rows created.
    Execution Plan
    Plan hash value: 1654070669
    | Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT  |          |   140 |  3080 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| NON_PART |   140 |  3080 |     3   (0)| 00:00:01 |
    Note
       - dynamic sampling used for this statement
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> set line 10000
    SQL> set autotrace traceonly exp
    SQL> select * from non_part;
    Execution Plan
    Plan hash value: 1654070669
    | Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |          |   140 |  3080 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| NON_PART |   140 |  3080 |     3   (0)| 00:00:01 |
    Note
       - dynamic sampling used for this statement
    SQL> select * from part;
    Execution Plan
    Plan hash value: 3392317243
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT    |      |   140 |  3080 |     9   (0)| 00:00:01 |       |       |
    |   1 |  PARTITION RANGE ALL|      |   140 |  3080 |     9   (0)| 00:00:01 |     1 |     5 |
    |   2 |   TABLE ACCESS FULL | PART |   140 |  3080 |     9   (0)| 00:00:01 |     1 |     5 |
    Note
       - dynamic sampling used for this statement
    SQL>
    SQL> exec dbms_stats.gather_table_stats(user, 'non_part');
    PL/SQL procedure successfully completed.
    SQL> exec dbms_stats.gather_table_stats(user, 'part');
    PL/SQL procedure successfully completed.
    SQL>
    SQL>
    SQL> select * from non_part;
    Execution Plan
    Plan hash value: 1654070669
    | Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |          |   140 |  1540 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| NON_PART |   140 |  1540 |     3   (0)| 00:00:01 |
    SQL> select * from part;
    Execution Plan
    Plan hash value: 3392317243
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT    |      |   140 |  1540 |     9   (0)| 00:00:01 |       |       |
    |   1 |  PARTITION RANGE ALL|      |   140 |  1540 |     9   (0)| 00:00:01 |     1 |     5 |
    |   2 |   TABLE ACCESS FULL | PART |   140 |  1540 |     9   (0)| 00:00:01 |     1 |     5 |
    SQL>After analyzing the tables, notice that the Bytes column has changed value

  • Avoid Full table scan

    Hi,
    My Query generation needs to be fine tuned. There are several queries generated that force full table scans of large tables. My question over here is whether functions and decodes need to be removed so that the queries take full advantage of the indexes on the table? I have used decode, Sum, case functions. So does it forces a full table scan of item price table (> 200 million records) as many times I have used these functions?
    How can I optimized it in more better way?

    How to see execution plan? Is it like explain plan you are saying? Can you please brief me on same.
    My query is
    Select S_ACCT_INFO.CUST_ACCT_NAM as CUST_ACCT_NAM,
           S_SLS_CRMEM_ITEM.CUST_ACCT_ID as CUST_ACCT_ID,
           S_SLS_CRMEM_ITEM.CUST_CNTRC_ID as CUST_CNTRC_ID,
           S_MCK_ITEM.GNRC_ID as GNRC_ID,
           S_MCK_ITEM.GNRC_NAM as GNRC_NAM,
           S_MCK_ITEM.SELL_DSCR_TXT as SELL_DSCR_TXT,
           S_MCK_ITEM.ITEM_STAT_CD_DSPSTN as ITEM_STAT_CD_DSPSTN,
           S_MCK_ITEM.RETL_LBL_CNT as RETL_LBL_CNT,
           S_MCK_ITEM.LBL_NAM as LBL_NAM,
           S_MCK_ITEM.MFG_SIZ_QTY as MFG_SIZ_QTY,
           S_SLS_CRMEM_ITEM.EM_ITEM_NUM as EM_ITEM_NUM,
           S_MCK_ITEM.NDC_NUM as NDC_NUM,
           S_MCK_ITEM.SPLR_ITEM_SEQ_NUM as SPLR_ITEM_SEQ_NUM,
           S_MCK_ITEM.SPLR_ACCT_NAM as SPLR_ACCT_NAM,
           S_MCK_ITEM.SPLR_ACCT_ID as SPLR_ACCT_ID,
           S_MCK_ITEM.UPC_NUM as UPC_NUM,
           S_IW_CNTRC_LEAD.CNTRC_LEAD_NAM as CNTRC_LEAD_NAM,
           DECODE(S_SLS_CRMEM_ITEM.CNTRC_LEAD_TP_ID, NULL, 'N', 'Y') CNTRC_IND_HIST,
           S_SLS_CRMEM_ITEM.CNTRC_LEAD_TP_ID as CNTRC_LEAD_TP_ID,
           S_SLS_CRMEM_ITEM.SLS_DOC_NUM as SLS_DOC_NUM,
           SUM(S_SLS_CRMEM_ITEM.SLS_AMT) INV_EXT_PRC_3,
           S_SLS_CRMEM_ITEM.SLS_PROC_WRK_DT as SLS_PROC_WRK_DT,
           CASE
             WHEN S_SLS_CRMEM_ITEM.GRS_SLS_QTY <> 0 THEN
              ROUND(S_SLS_CRMEM_ITEM.GRS_SLS_AMT / S_SLS_CRMEM_ITEM.GRS_SLS_QTY,
                    2)
             ELSE
              0
           END INV_PRC_PKG_2,
           SUM(S_SLS_CRMEM_ITEM.SLS_QTY) NET_QTY_3,
           S_SLS_CRMEM_ITEM.CUST_PO_NUM as CUST_PO_NUM,
           CASE
             WHEN S_SLS_CRMEM_ITEM.CUST_OMIT_IND IN
                  ('L', 'U', 'R', 'F', 'A', 'X') THEN
              SUM(S_SLS_CRMEM_ITEM.ORDR_QTY - S_SLS_CRMEM_ITEM.GRS_SLS_QTY)
             ELSE
              0
           END QTY_OMTD_MUS_1,
           S_ACCT_INFO.NATL_SUB_GRP_CD as NATL_SUB_GRP_CD,
           S_ACCT_INFO.CUST_STOR_NUM as CUST_STOR_NUM,
           S_MCK_ITEM.PKG_SIZ as PKG_SIZ,
           SUM(S_SLS_CRMEM_ITEM.GRS_SLS_QTY) INV_QTY_1,
           SUM(S_SLS_CRMEM_ITEM.ORDR_QTY) ORDR_QTY_2,
           SUM(S_SLS_CRMEM_ITEM.ORDR_QTY - S_SLS_CRMEM_ITEM.GRS_SLS_QTY) QTY_OMTD_1,
           SUM(S_SLS_CRMEM_ITEM.GRS_RTN_QTY) RTRN_QTY_1
      from S_SLS_CRMEM_ITEM
      LEFT OUTER JOIN S_MCK_ACCT_ITEM_PRC ON (S_SLS_CRMEM_ITEM.CUST_ACCT_ID =
                                             S_MCK_ACCT_ITEM_PRC.CUST_ACCT_ID AND
                                             S_SLS_CRMEM_ITEM.EM_ITEM_NUM =
                                             S_MCK_ACCT_ITEM_PRC.ITEM_NUM)
      LEFT OUTER JOIN S_ACCT_CNTRC_LEAD_TYP ON (S_MCK_ACCT_ITEM_PRC.CUST_ACCT_ID =
                                               S_ACCT_CNTRC_LEAD_TYP.CUST_ACCT_ID AND
                                               S_MCK_ACCT_ITEM_PRC.CNTRC_LEAD_ID =
                                               S_ACCT_CNTRC_LEAD_TYP.CNTRC_LEAD_ID)
      LEFT OUTER JOIN S_IW_CNTRC_LEAD ON (S_MCK_ACCT_ITEM_PRC.CNTRC_LEAD_ID =
                                         S_IW_CNTRC_LEAD.CNTRC_LEAD_ID)
    INNER JOIN S_ACCT_INFO ON (S_SLS_CRMEM_ITEM.CUST_ACCT_ID =
                               S_ACCT_INFO.CUST_ACCT_ID)
      LEFT OUTER JOIN S_VA_CUST_CNTRC ON (S_SLS_CRMEM_ITEM.CUST_ACCT_ID =
                                         S_VA_CUST_CNTRC.CUST_ACCT_ID AND
                                         S_SLS_CRMEM_ITEM.EM_ITEM_NUM =
                                         S_VA_CUST_CNTRC.ITEM_NUM)
    INNER JOIN S_MCK_ITEM ON (S_SLS_CRMEM_ITEM.EM_ITEM_NUM =
                              S_MCK_ITEM.EM_ITEM_NUM)
    where ((((((((S_SLS_CRMEM_ITEM.CUST_ACCT_ID in ('110718') or
           (S_ACCT_INFO.NATL_GRP_CD = '0227' and
           S_ACCT_INFO.NATL_SUB_GRP_CD = '000001')) or
           (S_ACCT_INFO.NATL_GRP_CD = '0227' and
           S_ACCT_INFO.NATL_SUB_GRP_CD = '000002')) or
           (S_ACCT_INFO.NATL_GRP_CD = '0227' and
           S_ACCT_INFO.NATL_SUB_GRP_CD = '000003')) or
           (S_ACCT_INFO.NATL_GRP_CD = '0227' and
           S_ACCT_INFO.NATL_SUB_GRP_CD = '000005')) or
           (S_ACCT_INFO.CUST_CHN_ID = '227' and
           S_ACCT_INFO.CUST_RGN_NUM = '000001')) or
           (S_ACCT_INFO.CUST_CHN_ID = '227' and
           S_ACCT_INFO.CUST_RGN_NUM = '000002')) or
           (S_ACCT_INFO.CUST_CHN_ID = '227' and
           S_ACCT_INFO.CUST_RGN_NUM = '000003')) or
           (S_ACCT_INFO.CUST_CHN_ID = '227' and
           S_ACCT_INFO.CUST_RGN_NUM = '000005'))
       and S_MCK_ITEM.SPLR_ACCT_ID IN
           ('34227', '34232', '34233', '34228', '34229', '34230', '34231',
            '34235', '34236', '78063', '84230', '90014', '98014')
       and (S_SLS_CRMEM_ITEM.SLS_PROC_WRK_DT between
           to_date('04/01/2007', 'MM/DD/YYYY') and
           to_date('06/30/2007', 'MM/DD/YYYY'))
    GROUP BY S_ACCT_INFO.CUST_ACCT_NAM,
              S_SLS_CRMEM_ITEM.CUST_ACCT_ID,
              S_SLS_CRMEM_ITEM.CUST_CNTRC_ID,
              S_MCK_ITEM.GNRC_ID,
              S_MCK_ITEM.GNRC_NAM,
              S_MCK_ITEM.SELL_DSCR_TXT,
              S_MCK_ITEM.ITEM_STAT_CD_DSPSTN,
              S_MCK_ITEM.RETL_LBL_CNT,
              S_MCK_ITEM.LBL_NAM,
              S_MCK_ITEM.MFG_SIZ_QTY,
              S_SLS_CRMEM_ITEM.EM_ITEM_NUM,
              S_MCK_ITEM.NDC_NUM,
              S_MCK_ITEM.SPLR_ITEM_SEQ_NUM,
              S_MCK_ITEM.SPLR_ACCT_NAM,
              S_MCK_ITEM.SPLR_ACCT_ID,
              S_MCK_ITEM.UPC_NUM,
              S_IW_CNTRC_LEAD.CNTRC_LEAD_NAM,
              DECODE(S_SLS_CRMEM_ITEM.CNTRC_LEAD_TP_ID, NULL, 'N', 'Y'),
              S_SLS_CRMEM_ITEM.CNTRC_LEAD_TP_ID,
              S_SLS_CRMEM_ITEM.SLS_DOC_NUM,
              S_SLS_CRMEM_ITEM.SLS_PROC_WRK_DT,
              CASE
                WHEN S_SLS_CRMEM_ITEM.GRS_SLS_QTY <> 0 THEN
                 ROUND(S_SLS_CRMEM_ITEM.GRS_SLS_AMT /
                       S_SLS_CRMEM_ITEM.GRS_SLS_QTY,
                       2)
                ELSE
                 0
              END,
              S_SLS_CRMEM_ITEM.CUST_PO_NUM,
              S_SLS_CRMEM_ITEM.CUST_OMIT_IND,
              S_ACCT_INFO.NATL_SUB_GRP_CD,
              S_ACCT_INFO.CUST_STOR_NUM,
              S_MCK_ITEM.PKG_SIZ
    order by S_MCK_ITEM.NDC_NUM               asc,
              S_SLS_CRMEM_ITEM.SLS_PROC_WRK_DT asc,
              S_SLS_CRMEM_ITEM.SLS_PROC_WRK_DT asc

  • Query doing full table scan

    Hai all,
    10.2.0.4 on solaris 10
    SELECT sum(RechargeForPrepaid/10000), to_date(substr (TIMESTAMP, 1,8),'YYYY/MM/DD')
    FROM medt.crm_t  WHERE to_date(substr (TIMESTAMP, 1,8),'YYYY/MM/DD') >= trunc(sysdate)-1 and tradetype != '0' group by to_date(substr (TIMESTAMP, 1,8),'YYYY/MM/DD');The explain shows that it performs a full table scan on crm_t . I created indexes on the column
    timestamp and tradetype too . collected stats too. but still it is doing a full table scan.
    Please guide
    Thanks
    Kai

    sybrand_b wrote:
    The column is wrongly named --> timestamp is a reserved word.True:
    SQL> select * from v$reserved_words where keyword = 'TIMESTAMP'
      2  /
    KEYWORD                                                              LENGTH
    TIMESTAMP                                                                 9
    1 row selected.
    It is also of the wrong type--> dates shouldn't be stored as varchar2.All we know, is that the column is treated as if it is a VARCHAR2. It doesn't have to be a varchar2, because he might be relying on some implicit datatype conversion.
    The design of this table is a complete mess.
    Drop it and redesign.You'd better tell that to Oracle as well then :-) :
    SQL> desc user_objects
    Name                                                                      Null?    Type
    OBJECT_NAME                                                                        VARCHAR2(128)
    SUBOBJECT_NAME                                                                     VARCHAR2(30)
    OBJECT_ID                                                                          NUMBER
    DATA_OBJECT_ID                                                                     NUMBER
    OBJECT_TYPE                                                                        VARCHAR2(18)
    CREATED                                                                            DATE
    LAST_DDL_TIME                                                                      DATE
    TIMESTAMP                                                                          VARCHAR2(19)
    STATUS                                                                             VARCHAR2(7)
    TEMPORARY                                                                          VARCHAR2(1)
    GENERATED                                                                          VARCHAR2(1)
    SECONDARY                                                                          VARCHAR2(1)My point is that the TIMESTAMP datatype was introduced in version 9, and versions prior to that were free to use the name "TIMESTAMP". And all those older applications still function. A redesign would be ideal, but maybe not economically feasible. Oracle certainly didn't choose a redesign.
    If you are going to build a new application, then I agree that you'd better not use that reserved word anymore.
    Regards,
    Rob.

Maybe you are looking for

  • LoadMovie- loading an external swf into movieclip in AS3

    Im extremely frustrated.........im trying to do something that was once very simple, which has now become over complicated unecessecarily.....i want to do a simple loadMovie type action and load an external clip into a movieclip called ph. my AS2 cod

  • Solaris 10 network installation for X2100

    I would like to ask that how can I install Solaris 10 over network for Sun Fire X2100 because I did not found the X2100 Server Operating System Installation Guide but I found the Sun Fire X2100 M2 Server Operating System Installation Guide instead.

  • User cannot view Blanket Purchase Agreements

    is there a way to allow users to view Blanket Purchase Agreements in the View Purchase Order Summary without making them a buyer? I tried using securing attributes to give them access to the buyers req/pos and they can see standard POs....just not Bl

  • Green line along caption

    I have an imported Illustrator file I am using as a backdrop for a kind of logo behind a caption (like the artwork along the bottom of a news channel). I keep getting a thin green line extending along the top of the illustrator art. It doesn't seem t

  • Configure messaging server and MTA on different machine

    Is there anyways to install / configure messaging server and MTA on different machine? I am using Sun One Messaging server 6.0 Thanks Haris