Using indexes when using group by clause

How can I make use of indexes when there is a group by clause in the sql/ pl/sql. Heard that when ever there is a group by clause , sql bypasses use of indexes. Is it true?
Thanks in advance

Hi,
Depending on the query containing the group by, indexes will still be used.
For example, create a big table based on the all_objects table. Then create an index on the object_type column. Then run this query:
select count(*), object_type from big_table where object_type != 'PACKAGE' group by object_type
The execution plan for this query will show the index to be used, the group by does not prevent the optimizer from using an index. Then run this query:
select count(*), object_type from big_table group by object_type
The execution plan for this query will show the index not to be used because the whole table - no restrictions - needs to be read to get the result.
Hope this helps!
Regards,
Marco Stuijvenberg
=
www.marcostuijvenberg.nl

Similar Messages

  • ORA-00907: missing right parenthesis when using group by clause with xmlagg

    I have the following query and I am getting ORA 00907 Error when I am using group by clause with the xmlagg function.
    select xmlelement("Mitigation",
                    xmlelement("m_szMethodName",tm.DisplayName),
                    xmlelement("SubstanceInterferenceProtocolList",
                                (select xmlagg(xmlelement("MitigationProtocol",
                                        xmlelement("m_szMethodName",tm.DisplayName),
                                        xmlelement("m_szInterferenceProtocolName",tmp.protocol_name),
                                        xmlelement("m_szInterferenceSubstance",tmp.intf_mtrl_prod_code),
                                        xmlelement("m_ProtocolParameters",
                                            xmlelement("m_szProtocolName",tmp.protocol_name),
                                                xmlelement("m_Consumables",
                                                    xmlelement("Consumable",
                                                        xmlelement("m_szConsumId", xrl.rgnt_pack_name),
                                                        xmlelement("m_szProductCode",xrl.pack_prod_code),
                                                        xmlelement("m_nVolume",tmp.fluid_vol),
                                                        xmlelement("m_szProtocolStep",xps.protocol_step_name))),
                                                    xmlelement("m_ProtParamList",
                                                        xmlagg(
                                                        xmlelement("ParameterValues",
                                                            xmlelement("m_szProtocolName",tmp.protocol_name),
                                                            xmlelement("m_Time",xpsd.parameter_ntime_value))
                                                        group by tmp.ccd_test_id,tmp.intf_mtrl_prod_code)
                    order by tmp.ccd_test_id, tmp.intf_mtrl_prod_code, xps.protocol_step_intprotocolstep )
                    from XPR_tdef_mitigation_protocol tmp, xp_reagentlist xrl,
                    xpr_protocol_settings xps, xpr_protocol_settings_default xpsd
                    where tmp.ccd_test_id = tm.ccd_test_id
                    and tmp.ccd_test_id = xrl.ccd_test_id
                    and tmp.pack_prod_code = xrl.pack_prod_code
                    and tmp.intf_type = 1
                    and xps.protocol_name = xpsd.protocol_name
                    and xps.protocol_step_name = xpsd.protocol_step_name
                    and xps.ps_action_parameterlist = xpsd.ps_action_parameterlist
                    and xps.protocol_name =  tmp.PROTOCOL_NAME
    from XPtoXPRTdef_defn_mapping tm
    where tm.DisplayName = 'SYPH'If I remove the xmlagg clause along with the group by clause, the query runs fine and give me the output.
    But in that XML format of the output is incorrect for my application.
    Could someone help here?

    Hi,
    userAtoZ wrote:
    I have the following query and I am getting ORA 00907 Error when I am using group by clause with the xmlagg function.
    ... xmlagg(
    xmlelement("ParameterValues",
    xmlelement("m_szProtocolName",tmp.protocol_name),
    xmlelement("m_Time",xpsd.parameter_ntime_value))
    group by tmp.ccd_test_id,tmp.intf_mtrl_prod_code)Please don't post unformatted code. When posting any formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If the code above were formatted well, so that you could match each '(' with its closing ')', it would look something like this:... xmlagg ( xmlelement ( "ParameterValues"
                        , xmlelement ( "m_szProtocolName"
                                       , tmp.protocol_name
                        , xmlelement ( "m_Time"
                                       , xpsd.parameter_ntime_value
    group by tmp.ccd_test_id
                        ,     tmp.intf_mtrl_prod_code
    This is exactly what you posted, only the whitespace has been changed.
    This makes it clear that the GROUP BY is inside the parentheses with the argument to XMLAGG.  You can have an ORDER BY clause there, but not a GROUP BY clause.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • Can we use Group by Clause here?

    All,
    Can we use group by clause in the date column?
    If yes, will it work for these kind of values '11/12/2009 12:30:45 PM' and '11/12/2009 4:30:45 PM'......

    Hi,
    frontier007 wrote:
    All,
    Can we use group by clause in the date column?
    If yes, will it work for these kind of values '11/12/2009 12:30:45 PM' and '11/12/2009 4:30:45 PM'......Yes, GROUP BY works with DATEs.
    Remember that DATEs always include hours, minutes and seconds, so '11/12/2009 12:30:45 PM' and '11/12/2009 4:30:45 PM', though they are in the same calendar day, are different DATE values. If you want them to be in the same group, then use TRUNC.
    For example:
    SELECT    TRUNC (entry_date)      AS entry_dt
    ,         SUM (amount)            AS daily_amount
    FROM      orders
    GROUP BY  TRUNC (entry_date)
    ;Edited by: Frank Kulash on Oct 30, 2009 4:55 AM

  • Output not sorted when using group by clause

    Recently we migrated our application from Forms5 to Forms10g and database from 7.3.2 to 10gR2.
    More than 400 applications using sql stmt with "group by" clause and without "order by".
    In Earlier version of oracle 7.3.2 "group by" clause in SQL stmt sorts the output by order of the column in the "group by"
    stmt, where new version of oracle 10g (10.2.0.1.0 - 64bit Production) doesnt behave like older version.
    eg select div_cd,dept_cd,count(*) from class group by div_cd,dept_cd
    Output of the above query in Oracle7
    DIV_CD DEPT_CD COUNT(*)
    0 1     120
    0 9 131
    1 4 938
    1 6 1
    4 1 1490
    5 2 59
    6 6 848
    6 9 295
    8 1 45
    9 5 19
    Output of same query in Oracle10g
    DIV_CD DEPT_CD COUNT(*)
    0 6 120
    0 9 131
    4 1 1490
    6 9 295
    8 1 45
    9 5 19
    1 4 938
    1 6 1
    5 2 59
    6 6 848
    My question is
    a) Does the oracle behave in that manner?.
    b) if so, Any patch set available for this?
    c) if no patch set how to resolve this issue.
    if i use "order by" clause
    along with group by then i can get the output how i want.
    BUt problem is more than 400 applications (forms) using above method.
    Identify Forms/Reports and rectifing is a tedious job.
    Anyone can give me a good solution to solve the above issue

    Group By does not, and never has guaranteed order. Just because it happened that way on the past does not mean it will continue to do so.
    In the past, the algorithm used for Group By invoked a sort. It was convenient for the system to simply dump the output in that resulting order. These days, Group By could also be accomplished using a hash algorithm. Walking through the hash can easily result in a completely different ordering, as you have seen.
    Your problem is that the assumptions made previously are now invalid. Oracle is still working correctly. No patch, but you might be able to work around it by crippling your database and using the COMPATIBLE parameter (although the official lower limit is 9.2.0)

  • How to use Group by clause in Infoset

    Hi,
    I have a infoset where I  am using two DSO .Now want to use the group by clause on basis of day, month, quarter .And also I want to use the left outer join .SO how will I do that ?
              Can somebody help me to to get these solved ?
    Regards
    Sunit

    Hi,
    for me it seems like Multiprovider is the one which we use in case when we want to go for group by option. This infoset is more kind of intersection operation.
    go through this link for more detailed info on Infoset
    http://help.sap.com/saphelp_nw2004s/helpdata/en/67/7e4b3eaf72561ee10000000a114084/content.htm
    Regards,
    rik

  • Can u write the following query without using group by clause

    select sp.sid, p.pid, p.name from product p, supp_prod sp
    where sp.pid= p.pid and
    sp.sid = ( select sid from supp_prod group by sid
    having count(*) =(select count(*) from product));
    thru this, we retrieving all the products delivered by the supplier.
    Can you write the following query without using the group by clause

      select sp.sid, p.pid, p.name
        from product p, supp_prod sp
       where sp.pid= p.pid the above query will still retrieve all the products supplied by the supplier. sub-query is not necessary.
    maybe if you can post some sample data and output will help us understand what you want to achieve.

  • While using group by clause facing this problem

    1.----- Orders Closed
    SELECT count(distinct h.order_number ) no_of_orders
    from
    oe_order_headers_all h,oe_order_lines_all l
    where h.header_id = l.header_id
    and l.flow_status_code = 'CLOSED'
    and l.open_flag = 'N'
    Output:
    NO_OF_ORDERS
    47905
    2.Orders Closed with respect to org_id :
    SELECT h.org_id,count(distinct h.order_number ) no_of_orders, l.flow_status_code
    from
    oe_order_headers_all h,oe_order_lines_all l
    where h.header_id = l.header_id
    and l.flow_status_code = 'CLOSED'
    and l.open_flag = 'N'
    group by l.flow_status_code,h.org_id
    Output:
    ORG_ID NO_OF_ORDERS
    600 24
    204 10864
    626 6551
    887 7170
    888 6962
    889 6431
    911 7678
    916 6
    917 6
    996 2969
    1017 1765
    1018 1794
    1668 5
    1733 16
    1759 1
    1885 1
    2541 10
    2869 1
    3537 1
    The total count of h.order_number is 52255.
    The total count of h.number_order is varying while grouping with respect to org_id.
    So anyone help me to solve this issue.

    Hi,
    We do not have any data etc. But if your question is why is the sum of the distinct count more then the total distinct count, that is very well posible.
    See sample data below.
    org_id     order_number
    1          1
    1          2
    2          1
    2          3distinct count of order_number = 3
    and the sum of the distinct counts grouped by org_id = 2 + 2 = 4
    I do not see any problem
    Regards,
    Peter

  • Oracle 10g group by clause

    I have one SQL query using a GROUP BY clause and no ORDER BY clause is used. When executed in Oracle 8i, the query results are returned ordered by first column mentioned in the GROUP BY clause. When the same query is executed in Oracle 10g, the query results are returned withour ordering the data by the first column in the GROUP BY clause. It works only when I explicitly mention the ORDER BY clause. Can you please explain this? In Orcale 8i, is it that, by default, the data is ordered by the first column mentioned in the GROUP BY clause when ORDER BY clause is not mentioned?
    In which order does oracle 10g sorts when I use group by clause in oracle 10g

    [email protected] wrote:
    the use of group by is to group based on some column value, in this case why does the the output differs in rows. why does the output, when you use group by is not the following formatSorry, but this is a totally fruitless topic. Why are you bothering with something that is totally internal to the DBMS? If you want the data ordered, use ORDER BY, it's that simple.
    Check out this link, if you want some discussion on it:
    [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:74320098178823]

  • Group By clause in oracle 10g help needed

    Hi
    we have a requirement that get the AR aging details at customer level.I have written the following query to fetch the correct rows at invoice level.But now i need to sum the amounts and i should show at invoice level and customer level.Could you please help me how can i group by customer level.
    Here is the query i used
    select ps.org_id
    , sob.SET_OF_BOOKS_ID
    , sob.CHART_OF_ACCOUNTS_ID
    , gcc.SEGMENT1 Company
    , gcc.SEGMENT2 Location
    , gcc.SEGMENT3 Department
    , gcc.SEGMENT4 Account
    , gcc.SEGMENT5 Future_1
    , gcc.SEGMENT6 Future_2
    , gcc.SEGMENT7 Future_3
    , gcc.CONCATENATED_SEGMENTS gl_cc_concat_kff
    , ps.trx_number
    , ps.trx_date
    , ps.due_date
    , ps.invoice_currency_code
    , sob.currency_code SOB_Currency_Code
    , ps.class
    , ps.amount_due_original
    , ps.amount_due_original * nvl(ps.exchange_rate, 1) acctd_amount_due_original
    , ps.amount_due_remaining
    , ps.acctd_amount_due_remaining
    , ps.status
    , ps.cust_trx_type_id
    , ps.customer_site_use_id
    , ps.customer_trx_id
    , ps.cash_receipt_id
    , ps.gl_date
    , rctlda.CODE_COMBINATION_ID
    , ps.customer_id
    , nvl(rcta.ATTRIBUTE5,ps.CUSTOMER_ID) End_Customer_Id
    , rc.customer_number
    , rc2.CUSTOMER_NUMBER Brand_Cust_no
    , round((sysdate-ps.due_date))
    from gl_sets_of_books sob
    , hr_operating_units ou
    , ar_payment_schedules_all ps
    , ra_customers rc
    , ra_cust_trx_line_gl_dist_all rctlda
    , gl_code_combinations_kfv gcc
    , ra_customer_trx_all rcta
    , ra_customers rc2
    where sob.set_of_books_id = ou.set_of_books_id
    and ou.organization_id = ps.org_id
    and ps.status = 'OP'
    and ps.org_id is not null
    and ps.CUSTOMER_ID=rc.CUSTOMER_ID
    and ps.CUSTOMER_TRX_ID=rctlda.CUSTOMER_TRX_ID
    and rctlda.ACCOUNT_CLASS='REC'
    and rctlda.latest_rec_flag = 'Y'
    and rctlda.CODE_COMBINATION_ID=gcc.CODE_COMBINATION_ID
    and ps.CUSTOMER_TRX_ID=rcta.CUSTOMER_TRX_ID
    and gcc.CODE_COMBINATION_ID=39446
    -and ps.trx_number = '1-15O0A8O'
    --and    rc.CUSTOMER_NUMBER='1-10PA5KX'
    and nvl(rcta.ATTRIBUTE5,ps.CUSTOMER_ID)=rc2.CUSTOMER_ID
    Could any one help me how to get the same columns with sum( ps.amount_due_original ) for each customer.I tried to use group by clause but it is again giving invoice level.
    But my req is for each customer invoice amount should be summed and it should give the total
    Thanks
    Y

    if you need to have the sum of invoice related to each customer then may also need to check for the
    CUBE
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#sthref9448
    and example here
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#i2066443
    and ROLLUP
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#sthref9445
    I couldn't follow with all your SQL statement, or I could rewrite it for you again
    Thanks
    Edited by: user9532576 on Jul 21, 2009 9:24 AM

  • How to display column specified in group by clause only once?

    I've a result coming out of a sql query that uses group by clause as follows:
    2008-07-25 19" LCD Screen 5
    2008-07-25 HP Printer     4
    2008-08-01 Hanging Files 11
    2008-08-01 Stapler     3
    2008-08-15 19" LCD Screen 5
    2008-08-15 Hanging Files 14
    What should I do in the query to display the result set as follows:
    2008-07-25 19" LCD Screen 5
         HP Printer     4
    2008-08-01 Hanging Files 11
         Stapler     3
    2008-08-15 19" LCD Screen 5
    Hanging Files 14

    Hi,
    That's a display issue, and display issues are best handled by the front end.
    What is your frone end?
    If it's SQL*Plus, you can use the BREAK command.
    For example:
    BREAK ON  deptno     NODUPLICATES
    SELECT       deptno
    ,       ename
    FROM       scott.emp
    ORDER BY  deptno
    ,            ename
    ;Output:
    `   DEPTNO ENAME
            10 CLARK
               KING
               MILLER
            20 ADAMS
               FORD
               JONES
               SCOTT
               SMITH
            30 ALLEN
               BLAKE
               JAMES
               MARTIN
               TURNER
               WARDNote that deptno is never NULL: KING and MILLER have deptno=10; but it doesn't show in the display, because it's the same as the deptno on the previous row.
    NODUPLICATES is actually the default, so you could just say
    BREAK ON deptnoThe BREAK command remains in force until you end the session (or un-do it, e.g. with "CLEAR BREAKS")
    Remember to issue the BREAK command at least once in the session before running the query.
    To get the same results in SQL, use the analytic ROW_NUMBER function.

  • HOW TO ADD GROUP BY CLAUSE WHEN USING Jbo:Datatable

    Would like to know if there are any provisions for adding a Group by clause so the data shown using DataTable Component cn be grouped.
    eg:
    Currently using DataTable component shows data as shown below.
    Dept Name
    10 ABC
    10 DEF
    10 PQR
    20 XYZ
    20 QQQ
    Can this be done as shown bewlow
    Dept Name
    10 ABC
    DEF
    PQR
    20 XYZ
    QQQ
    Thanks

    Hi Sashi,
    For a bc4j view object, the shape of the result set needs to be consistent. So, there can not be a groupby directly in the result set.
    However, that does not prevent you from inserting a calculated column that performs a similar calculation.
    Another mechanism might be to consider a master detail arrangement of the views where the master contains an aggregation of data from its children. You are then free to access and display this data as you choose.
    Hope this helps,
    Pete

  • How to use order by within Group by clause

    Hi All,
    I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
    Select RaceNo,Venue,FP,BP from Race group by RaceNo
    Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
    Can anybody suggest me how to use order by clause that would apply to each group of data.
    Thanks .

    order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
    i hope this eg.l gives u some clarification....
    e.g
    select deptno,count(empno)
    from dept
    group by deptno
    having count(empno) > 10
    order by deptno

  • Use of expressions or field aliases in GROUP BY clauses

    I've seen numerous references, even BNF syntax
    diagrams, that suggest that Oracle's parser will accept an expression in a
    GROUP BY clause; however, I've had no success whatsoever in getting this to
    work. Here's an example of something I had hoped would work, but does not:
    SELECT
    account_id,
    CASE
    WHEN txn_date BETWEEN DATE '2006-06-01' AND DATE '2006-06-07' THEN 1
    WHEN txn_date BETWEEN DATE '2006-06-08' AND DATE '2006-06-14' THEN 2
    ELSE 3
    END AS week_id,
    COUNT(*) AS week_cnt
    FROM myschema.my_random_table_name
    GROUP BY account_id, week_id;
    The interpreter gags on the use of "week_id" in the GROUP BY statement.
    Evidently Oracle syntax doesn't support the use of positional designations
    in aggregating statements either - I tried using the clause
    GROUP BY 1, 2;
    as the last line, and it didn't like this either.
    Any assistance or suggestions you can offer would be greatly appreciated.
    I prefer to let the DBMS engine do my aggregating for me as much as
    possible, but without being able to aggregate relative to programmer-defined
    fields, I am somewhat hamstrung.

    try this :
    SQL> select case when hire_date between '01-JAN-00' and '31-DEC-05' then 1 else 0 end col1, count(*)
    2 from employees
    3 group by col1;
    group by col1
    ERROR at line 3:
    ORA-00904: "COL1": invalid identifier
    SQL>
    SQL>
    SQL>
    1 select case when hire_date between '01-JAN-00' and '31-DEC-05' then 1 else 0 end col1, count(*)
    2 from employees
    3* group by case when hire_date between '01-JAN-00' and '31-DEC-05' then 1 else 0 end
    SQL> /
    COL1 COUNT(*)
    1 11
    0 96

  • Partition Pruning on Interval Range Partitioned Table not happening when SYSDATE used in Where Clause

    We have tables that are interval range partitioned on a DATE column, with a partition for each day - all very standard and straight out of Oracle doc.
    A 3rd party application queries the tables to find number of rows based on date range that is on the column used for the partition key.
    This application uses date range specified relative to current date - i.e. for last two days would be "..startdate > SYSDATE -2 " - but partition pruning does not take place and the explain plan shows that every partition is included.
    By presenting the query using the date in a variable partition pruning does table place, and query obviously performs much better.
    DB is 11.2.0.3 on RHEL6, and default parameters set - i.e. nothing changed that would influence optimizer behavior to something unusual.
    I can't work out why this would be so. It very easy to reproduce with simple test case below.
    I'd be very interested to hear any thoughts on why it is this way and whether anything can be done to permit the partition pruning to work with a query including SYSDATE as it would be difficult to get the application code changed.
    Furthermore to make a case to change the code I would need an explanation of why querying using SYSDATE is not good practice, and I don't know of any such information.
    1) Create simple partitioned table
    CREATETABLE part_test
       (id                      NUMBER NOT NULL,
        starttime               DATE NOT NULL,
        CONSTRAINT pk_part_test PRIMARY KEY (id))
    PARTITION BY RANGE (starttime) INTERVAL (NUMTODSINTERVAL(1,'day')) (PARTITION p0 VALUES LESS THAN (TO_DATE('01-01-2013','DD-MM-YYYY')));
    2) Populate table 1million rows spread between 10 partitions
    BEGIN
        FOR i IN 1..1000000
        LOOP
            INSERT INTO part_test (id, starttime) VALUES (i, SYSDATE - DBMS_RANDOM.value(low => 1, high => 10));
        END LOOP;
    END;
    EXEC dbms_stats.gather_table_stats('SUPER_CONF','PART_TEST');
    3) Query the Table for data from last 2 days using SYSDATE in clause
    EXPLAIN PLAN FOR
    SELECT  count(*)
    FROM    part_test
    WHERE   starttime >= SYSDATE - 2;
    | Id  | Operation                 | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |           |     1 |     8 |  7895  (1)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE           |           |     1 |     8 |            |          |       |       |
    |   2 |   PARTITION RANGE ITERATOR|           |   111K|   867K|  7895   (1)| 00:00:01 |   KEY |1048575|
    |*  3 |    TABLE ACCESS FULL      | PART_TEST |   111K|   867K|  7895   (1)| 00:00:01 |   KEY |1048575|
    Predicate Information (identified by operation id):
       3 - filter("STARTTIME">=SYSDATE@!-2)
    4) Now do the same query but with SYSDATE - 2 presented as a literal value.
    This query returns the same answer but very different cost.
    EXPLAIN PLAN FOR
    SELECT count(*)
    FROM part_test
    WHERE starttime >= (to_date('23122013:0950','DDMMYYYY:HH24MI'))-2;
    | Id  | Operation                 | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |           |     1 |     8 |   131  (0)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE           |           |     1 |     8 |            |          |       |       |
    |   2 |   PARTITION RANGE ITERATOR|           |   111K|   867K|   131   (0)| 00:00:01 |   356 |1048575|
    |*  3 |    TABLE ACCESS FULL      | PART_TEST |   111K|   867K|   131   (0)| 00:00:01 |   356 |1048575|
    Predicate Information (identified by operation id):
       3 - filter("STARTTIME">=TO_DATE(' 2013-12-21 09:50:00', 'syyyy-mm-dd hh24:mi:ss'))
    thanks in anticipation
    Jim

    As Jonathan has already pointed out there are situations where the CBO knows that partition pruning will occur but is unable to identify those partitions at parse time. The CBO will then use a dynamic pruning which means determine the partitions to eliminate dynamically at run time. This is why you see the KEY information instead of a known partition number. This is to occur mainly when you compare a function to your partition key i.e. where partition_key = function. And SYSDATE is a function. For the other bizarre PSTOP number (1048575) see this blog
    http://hourim.wordpress.com/2013/11/08/interval-partitioning-and-pstop-in-execution-plan/
    Best regards
    Mohamed Houri

Maybe you are looking for