Query with order by taking 1 hr

Hi,
Query with order by taking 1 hr, without order by taking 9 seconds,
pls tell me ,wat will be the reason and how to tune.
Query:
SELECT
T17.CONFLICT_ID,
T17.LAST_UPD,
T17.CREATED,
T17.LAST_UPD_BY,
T17.CREATED_BY,
T17.MODIFICATION_NUM,
T17.ROW_ID,
T1.ACCNT_TYPE_CD,
T36.X_BRIDGESTATION,
T36.X_CTI_PIN,
T36.X_FLOOR,
T36.X_SEGMENT2,
T36.X_SEGMENT3,
T36.X_CONTACT_STATUS,
T36.X_DEALING_CODE,
T36.X_DELETE,
T36.X_DEPARTMENT,
T36.X_DIRECT_MKT,
T36.X_FASS_LAST_CONTACT_DATE,
T36.X_SEGMENT1,
T36.X_LAST_TRAINED_DATE,
T36.X_LEGAL_CONSENT,
T36.X_LOCAL_FST_NAME,
T36.X_LOCAL_LAST_NAME,
T36.X_PREF_LANG,
T36.X_PROD_BLEND,
T36.X_SALUTATION,
T36.X_BSC_SIDE,
T36.X_END_USR_ACT,
T36.X_PRIM_ASSET_CLASS,
T36.X_SEC_ASSET_CLASS,
T36.X_STATUS,
T36.X_LANGUAGE,
T36.X_SUPPRESS_SMS_FLG,
T36.X_TRAINING_ADDRESS,
T36.X_UPD_TYPE,
T36.X_XTRA_UPD,
T36.X_XTRA_ID,
T36.X_ESERVICE_USER,
T36.X_SALES_COMMENTS,
T36.PR_DEPT_OU_ID,
T1.INTEGRATION_ID,
T1.PRTNR_FLG,
T36.BIRTH_DT,
T36.CELL_PH_NUM,
T9.ATTRIB_07,
T5.LAST_UPD,
T36.EMAIL_ADDR,
T36.EMP_FLG,
T36.FAX_PH_NUM,
T36.FST_NAME,
T36.HOME_PH_NUM,
T36.JOB_TITLE,
T36.LAST_NAME,
T36.SEX_MF,
T36.PER_TITLE,
T36.MID_NAME,
T36.OWNER_PER_ID,
T17.NAME,
T36.PERSON_UID,
T36.PRIV_FLG,
T1.NAME,
T29.PR_ADDR_ID,
T36.PR_REP_DNRM_FLG,
T36.PR_REP_MANL_FLG,
T36.PR_REP_SYS_FLG,
T36.PR_MKT_SEG_ID,
T36.PR_GRP_OU_ID,
T36.PR_OPTY_ID,
T36.PR_PER_ADDR_ID,
T36.PR_PER_PAY_PRFL_ID,
T36.PR_POSTN_ID,
T36.PR_RESP_ID,
T19.OWN_INST_ID,
T19.INTEGRATION_ID,
T36.SOC_SECURITY_NUM,
T29.STATUS,
T36.SUPPRESS_CALL_FLG,
T36.SUPPRESS_MAIL_FLG,
T36.WORK_PH_NUM,
T36.BU_ID,
T36.PR_ALT_PH_NUM_ID,
T36.PR_EMAIL_ADDR_ID,
T36.PR_SYNC_USER_ID,
T18.SHARE_HOME_PH_FLG,
T36.PR_REGION_ID,
T36.NATIONALITY,
T36.CITIZENSHIP_CD,
T36.AGENT_FLG,
T36.MEMBER_FLG,
T13.PR_EMP_ID,
T36.PR_OU_ADDR_ID,
T33.PR_EMP_ID,
T13.PR_EMP_ID,
T21.LOGIN,
T26.LOGIN,
T25.PR_FAX_NUM_ID,
T36.PR_INDUST_ID,
T36.PR_NOTE_ID,
T1.PR_POSTN_ID,
T36.PR_PROD_LN_ID,
T25.PR_SMS_NUM_ID,
T36.PR_SECURITY_ID,
T6.NAME,
T36.MED_SPEC_ID,
T36.PR_STATE_LIC_ID,
T36.PR_TERR_ID,
T36.PROVIDER_FLG,
T36.CUST_SINCE_DT,
T34.ADDR,
T34.CITY,
T34.COUNTRY,
T34.ZIPCODE,
T34.STATE,
T4.NAME,
T36.CURR_PRI_LST_ID,
T27.ROW_STATUS,
T22.LOGIN,
T2.CITY,
T2.COUNTRY,
T2.ZIPCODE,
T2.COUNTY,
T2.ADDR,
T20.X_ACC_CLASS,
T20.X_FS_INLIMITS,
T20.X_PRIORITY,
T20.X_DC_LOC,
T20.X_SERV_PROV_ID,
T20.X_FS_LOC,
T20.X_LOCAL_ACCOUNT_NAME,
T20.NAME,
T20.LOC,
T20.PR_BL_ADDR_ID,
T20.PR_BL_PER_ID,
T20.PR_SHIP_ADDR_ID,
T20.PR_SHIP_PER_ID,
T20.OU_NUM,
T16.ROW_ID,
T20.PR_SRV_AGREE_ID,
T16.ROW_ID,
T15.PRIM_MARKET_CD,
T16.ROW_ID,
T14.CITY,
T14.COUNTRY,
T14.ZIPCODE,
T14.STATE,
T14.ADDR,
T35.NAME,
T32.NAME,
T8.CHRCTR_ID,
T32.PRIV_FLG,
T3.LOGIN,
T31.LOGIN,
T36.ROW_ID,
T36.MODIFICATION_NUM,
T36.CREATED_BY,
T36.LAST_UPD_BY,
T36.CREATED,
T36.LAST_UPD,
T36.CONFLICT_ID,
T36.PAR_ROW_ID,
T25.ROW_ID,
T25.MODIFICATION_NUM,
T25.CREATED_BY,
T25.LAST_UPD_BY,
T25.CREATED,
T25.LAST_UPD,
T25.CONFLICT_ID,
T25.PAR_ROW_ID,
T18.ROW_ID,
T18.MODIFICATION_NUM,
T18.CREATED_BY,
T18.LAST_UPD_BY,
T18.CREATED,
T18.LAST_UPD,
T18.CONFLICT_ID,
T18.PAR_ROW_ID,
T9.ROW_ID,
T9.MODIFICATION_NUM,
T9.CREATED_BY,
T9.LAST_UPD_BY,
T9.CREATED,
T9.LAST_UPD,
T9.CONFLICT_ID,
T9.PAR_ROW_ID,
T19.ROW_ID,
T19.MODIFICATION_NUM,
T19.CREATED_BY,
T19.LAST_UPD_BY,
T19.CREATED,
T19.LAST_UPD,
T19.CONFLICT_ID,
T19.PAR_ROW_ID,
T27.ROW_ID,
T24.ROW_ID,
T23.ROW_ID,
T2.ROW_ID,
T28.ROW_ID,
T16.ROW_ID,
T11.ROW_ID,
T14.ROW_ID,
T35.ROW_ID,
T8.ROW_ID,
T30.ROW_ID,
T7.ROW_ID
FROM
SIEBEL.S_ORG_EXT T1,
SIEBEL.S_ADDR_PER T2,
SIEBEL.S_USER T3,
SIEBEL.S_PRI_LST T4,
SIEBEL.S_PER_DEDUP_KEY T5,
SIEBEL.S_MED_SPEC T6,
SIEBEL.S_PARTY T7,
SIEBEL.S_CON_CHRCTR T8,
SIEBEL.S_CONTACT_X T9,
SIEBEL.S_POSTN T10,
SIEBEL.S_CON_ADDR T11,
SIEBEL.S_POSTN T12,
SIEBEL.S_POSTN T13,
SIEBEL.S_ADDR_PER T14,
SIEBEL.S_ORG_EXT_FNX T15,
SIEBEL.S_PARTY T16,
SIEBEL.S_PARTY T17,
SIEBEL.S_EMP_PER T18,
SIEBEL.S_CONTACT_SS T19,
SIEBEL.S_ORG_EXT T20,
SIEBEL.S_USER T21,
SIEBEL.S_USER T22,
SIEBEL.S_CON_ADDR T23,
SIEBEL.S_PARTY T24,
SIEBEL.S_CONTACT_LOYX T25,
SIEBEL.S_USER T26,
SIEBEL.S_POSTN_CON T27,
SIEBEL.S_PARTY_PER T28,
SIEBEL.S_POSTN_CON T29,
SIEBEL.S_PARTY T30,
SIEBEL.S_USER T31,
SIEBEL.S_CHRCTR T32,
SIEBEL.S_POSTN T33,
SIEBEL.S_ADDR_PER T34,
SIEBEL.S_CONTACT_XM T35,
SIEBEL.S_CONTACT T36
WHERE
T36.PR_DEPT_OU_ID = T1.PAR_ROW_ID (+) AND
T1.PR_POSTN_ID = T33.PAR_ROW_ID (+) AND
T36.PR_POSTN_ID = T13.PAR_ROW_ID (+) AND
T17.ROW_ID = T29.CON_ID (+) AND T29.POSTN_ID (+) = '1-ERPTObjMgrSqlLog' AND
T33.PR_EMP_ID = T21.PAR_ROW_ID (+) AND
T13.PR_EMP_ID = T26.PAR_ROW_ID (+) AND
T36.PR_PER_ADDR_ID = T34.ROW_ID (+) AND
T36.MED_SPEC_ID = T6.ROW_ID (+) AND
T36.CURR_PRI_LST_ID = T4.ROW_ID (+) AND
T17.ROW_ID = T5.PERSON_ID (+) AND
T17.ROW_ID = T36.PAR_ROW_ID AND
T17.ROW_ID = T25.PAR_ROW_ID (+) AND
T17.ROW_ID = T18.PAR_ROW_ID (+) AND
T17.ROW_ID = T9.PAR_ROW_ID AND
T17.ROW_ID = T19.PAR_ROW_ID (+) AND
T36.PR_POSTN_ID = T27.POSTN_ID AND T36.ROW_ID = T27.CON_ID AND
T27.POSTN_ID = T24.ROW_ID AND
T27.POSTN_ID = T12.PAR_ROW_ID (+) AND
T12.PR_EMP_ID = T22.PAR_ROW_ID (+) AND
T36.PR_OU_ADDR_ID = T23.ADDR_PER_ID (+) AND T36.PR_DEPT_OU_ID = T23.ACCNT_ID (+) AND
T36.PR_OU_ADDR_ID = T2.ROW_ID (+) AND
T36.PR_DEPT_OU_ID = T28.PARTY_ID (+) AND T36.ROW_ID = T28.PERSON_ID (+) AND
T36.PR_DEPT_OU_ID = T16.ROW_ID (+) AND
T36.PR_DEPT_OU_ID = T20.PAR_ROW_ID (+) AND
T36.PR_DEPT_OU_ID = T15.PAR_ROW_ID (+) AND
T29.PR_ADDR_ID = T11.ADDR_PER_ID (+) AND T29.CON_ID = T11.CONTACT_ID (+) AND
T29.PR_ADDR_ID = T14.ROW_ID (+) AND
T36.X_SEGMENT1 = T35.ROW_ID (+) AND
T36.PR_MKT_SEG_ID = T8.ROW_ID (+) AND
T8.CHRCTR_ID = T32.ROW_ID (+) AND
T1.PR_POSTN_ID = T30.ROW_ID (+) AND
T1.PR_POSTN_ID = T10.PAR_ROW_ID (+) AND
T10.PR_EMP_ID = T3.PAR_ROW_ID (+) AND
T36.PR_SYNC_USER_ID = T7.ROW_ID (+) AND
T36.PR_SYNC_USER_ID = T31.PAR_ROW_ID (+) AND
((T36.X_DELETE = 'N') AND
(T36.PRIV_FLG = 'N' AND T17.PARTY_TYPE_CD != 'Suspect')) AND
(T9.ATTRIB_10 = 'NObjMgrSqlLog')
ORDER BY
T36.LAST_NAME, T36.FST_NAME

@afalty, the story you are telling about the order of the tables being important, from smallest to largest, et cetera, is only partially true and only when dealing with the rule based optimizer. Nowadays, almost everybody is using the cost based optimizer, so these remarks can very likely be ignored.
@original poster:
I think you are "measuring" the elapsed time by using TOAD, am I right? And you are probably writing 9 seconds, because it took TOAD 9 seconds before it could display the first records. If you would scroll down to the last record, it is likely taking much more time. A sort operation costs resources and time, but very unlikely this much.
When you want your rows sorted, all rows must have been visited before you know for sure which one is the smallest. That's why it takes longer to display the first row. Without an order by, the query can begin popping out rows much faster.
Regards,
Rob.

Similar Messages

  • Query with order by clause

    Hi,
    I found a query with order by clause in procedure which is taking long time.
    Stats are upto date.
    Total Rows :650000.
    It is ordered by primary key column.
    select * from table_name order by col1;
    col1 is a primary key.No of cpu's used is 4.
    can anyone suggest me a better solution to improve the performance of a query.
    Is it better to use parallel hint for above scenario.
    Any help really apprecaited.
    Thanks in advance.

    Hi,
    Thanks for ur immediate reply.
    It doesn't have where clause.
    below is the plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 619071987
    | Id  | Operation                   | Name                 | Rows  | Bytes | Cos
    |   0 | SELECT STATEMENT            |                      |   671K|   255M| 125
    |   1 |  TABLE ACCESS BY INDEX ROWID| FULL_ITEM_FACILITIES |   671K|   255M| 125
    |   2 |   INDEX FULL SCAN           | FIF_PK               |   671K|       |
    9 rows selected
    Executed in 0.094 secondsThanks in advance
    Edited by: unique on Jun 22, 2009 8:26 AM

  • Sub query with order by

    Hi ,
    I have created a sub query with order by on a column.( i have cutomized the IKM control append to put order by).I can see the order by condition.If i use this subquery(yellow interface) in main query(is also yellow interface) i can't see the order by condition
    Subquery(Q-yellow interface):
    select
    PID,
         START_TIME,
         ACTION_TYPE_CODE
    FROM
    select      DISTINCT
         SERVICE_TRACKING_S.PID PID,
         TO_TIMESTAMP(TO_CHAR(SERVICE_TRACKING_S.ACTION_TIME,'DD-MON-YY HH24:MI:SS'),'DD-MON-YY HH24:MI:SS') START_TIME,
         SERVICE_TRACKING_S.ACTION_TYPE_CODE ACTION_TYPE_CODE
    from     KSTGDB.SERVICE_TRACKING_S SERVICE_TRACKING_S
    where          (1=1)     
    ORDER BY-----------------------------------------------
    PID
    ,START_TIME ASC
    ODI_GET_FROM
    Main query(Q1--yellow interface):
    select
    PID,
         START_TIME,
         ACTION_TYPE_CODE,
         RN,
         RN_MAX
    FROM (     
    select      
         Q.PID PID,
         Q.START_TIME START_TIME,
         CASE WHEN Q.START_TIME-LAG(Q.START_TIME,1,Q.START_TIME) OVER (PARTITION BY Q. PID ORDER BY Q.START_TIME)> numtodsinterval(75,'minute')
    or Q.PID!=LAG(Q.PID,1,0) OVER (PARTITION BY Q.PID ORDER BY Q.START_TIME) THEN 1 ELSE Q.ACTION_TYPE_CODE END ACTION_TYPE_CODE,
         ROW_NUMBER() OVER(PARTITION BY Q.PID ORDER BY Q.START_TIME) RN,
         count(*) over (PARTITION BY Q.PID ORDER BY Q.START_TIME ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING )
    RN_MAX
    from     (
    select      DISTINCT
         SERVICE_TRACKING_S.PID PID,     TO_TIMESTAMP(TO_CHAR(SERVICE_TRACKING_S.ACTION_TIME,'DD-MON-YY HH24:MI:SS'),'DD-MON-YY HH24:MI:SS') START_TIME,     SERVICE_TRACKING_S.ACTION_TYPE_CODE ACTION_TYPE_CODE
    from     KSTGDB.SERVICE_TRACKING_S SERVICE_TRACKING_S
    where     (1=1)
    ----------------- i don't see order by here--------------------------------
    ) Q
    where          (1=1)     
    ) ODI_GET_FROM
    thanks in advance
    K

    Hi,
    Add a new KM step with the SQL you want to use for the sub query and select the +"Use Current Command for Derived-Table sub-select statement"+ checkbox. This new step can be the last one of your IKM.
    Basically, you can copy the select statement of the "Insert new rows" step.
    Regards,
    JeromeFr

  • Improve performance of query with order by

    Hello,
    I have a query with a necessary "order by" which lasts 24 seconds. The same query without the "order by" lasts 1 second.
    How can I improve the performance of the query with "order by"?
    Thank you very much.
    The query is:
    select distinct CC.acceso,CC.ext_acceso,TIT.TITULO_SALIDA
    from (((Ocurrencias CT01 inner join
         palabras p0 on (CT01.cod_palabra = p0.cod_palabra and p0.palabra like 'VENEZUELA%' AND p0.campo = 'AUTOR')) INNER JOIN
         CENTRAL CC ON (CT01.ACCESO = CC.ACCESO AND CT01.EXT_ACCESO = CC.EXT_ACCESO))) inner join
         codtit ctt on (CC.acceso = ctt.acceso and CC.ext_acceso = ctt.ext_acceso) inner join
         titulos tit on (ctt.cod_titulo = tit.cod_titulo and ctt.portada = '1')
    where CC.nivel_reg <> 's'
    ORDER BY 3 ASC;

    My guess is SQL Scratchpad is a GUI and is not returning all the rows but just the first screenful. Without any order by or distinct the database can start returning rows as soon as it finds the first one. With an order or distinct it needs to sort the rows so the first row can only be returned after the last row is retrieved.
    Open a command line prompt and run
    sqlplus
    SQL> set timing on
    SQL>And then run your queries.
    If you still have a large discrepancy do this
    SQL> set autotrace traceonly
    SQL>And then run the queries and post the output.

  • Oracle query tuning : query with Order-by clause

    Hi
    I am having a query in my database :
    SELECT * FROM SAPR3.HRP1001 WHERE "MANDT" = 990
    ORDER BY
    "MANDT" , "OTYPE" , "OBJID" , "PLVAR" , "RSIGN" , "RELAT" , "ISTAT" , "PRIOX" , "BEGDA" , "ENDDA" ,"VARYF" , "SEQNR" ;
    Autotrace output is :
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4649 Card=171895 Byt
    es=22862035)
    1 0 SORT (ORDER BY) (Cost=4649 Card=171895 Bytes=22862035)
    2 1 TABLE ACCESS (FULL) OF 'HRP1001' (Cost=1170 Card=171895
    Bytes=22862035)
    Statistics
    0 recursive calls
    5 db block gets
    12157 consistent gets
    11543 physical reads
    0 redo size
    38253080 bytes sent via SQL*Net to client
    376841 bytes received via SQL*Net from client
    34201 SQL*Net roundtrips to/from client
    0 sorts (memory)
    1 sorts (disk)
    512992 rows processed
    Since it is a issue with order by , it seems a PGA memory issue. there is 12GB PGA available but only 3GB gets allocated. pga_aggregate target is set in the DB. There is a index created for al the columns on order by, but it is not getting used.
    pleas suggest me as I am running into major problems, i can post the output of any query u require from my side. Any help wil be highly apprciated.
    Rishi

    > The query was alwasy spilling over to the One-Parse execution . It can be seen thru ST04N ->resource consumption-> sql work area trace.
    >
    > An undocumented oracle parameter smmmax_size was set which allowed for more usage of physical memory by single process and there was no spillover to the TEMP tablespaces.
    >
    > Also the File read time was analysed from Unix level ( From SAP thru ST04 ->filesystem wait s-> Avg rd (ms) and Ang writes (ms) which showed that reading from the File was not happening well. )
    Hi Rishi,
    the provided execution statistics prove the opposite:
    >Statistics
    >...
    >0 sorts (memory)
    > 1 sorts (disk)
    >512992 rows processed
    This indeed was a single-pass sort, which means it had to use the temp tablespace for one pass of the sorting/grouping.
    Remember that Oracle distinguishes three kinds of sorts: 1. "in memory", 2. "single-pass" and 3. "multi-pass".
    Only the first one won't need to spill out data to the disks. The others do this by definition.
    BTW: the file read times in ST04 are aquired through Oracle V$ views and not directly from the OS - that can make a big difference sometimes.
    regards,
    Lars

  • Query with order by & View/procedure

    1)I have a query its getting joined with few tables and the base table contains 12 billion rows . my issue is when I execute the query with necessary parameter am getting the result in few seconds . but when I add an order by for any column am not getting the result even after 15 minuts.
    The sort column is an indexed column and I have even tried with the primary column of the base table but no change .. is there any way to make it faster with order by ??
    2)I have got a view which also getting joined with few high volume tables . when I call the view with required parameter am not getting the result even after 15 minutes.. but when I took out the query of the view and hardcode the value am getting the result in 3 seconds . so I just made it to a procedure that returns a cursor . now its working fine .. could you please explain me the reason for this ….??
    Please help …

    select * from
    (select Rownum RowNO,Qr.* from
    (select T1.c1,T2.C2,T3.c3 from TI,T2,T3
    where < all required joins>
    order by Ti.c)Qr
    where RowNum <20 )
    where RowNO >10 ;As said before:
    Your view very likely prevented predicate pushing and by manually adding the predicate inside the query, you changed the semantics of the query.
    Your view contains a rownum column. This prevents predicate pushing because the semantics of the query changes. An example to clarify:
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7             from emp
      8         )
      9   where empno = 7839
    10  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 4024650034
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |     1 |    14 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    14 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("EMPNO"=7839)
    14 rijen zijn geselecteerd.
    SQL> exec dbms_lock.sleep(1)
    PL/SQL-procedure is geslaagd.
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7             from emp
      8            where empno = 7839
      9         )
    10  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 4024650034
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |     1 |    14 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    14 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("EMPNO"=7839)
    14 rijen zijn geselecteerd.The previous two queries show that in this case the predicate "empno = 7839" can be pushed inside the view. Both queries are semantically the same.
    However, when you add a rownum to your view definition, like you did, the predicates cannot be pushed inside the view:
    SQL> exec dbms_lock.sleep(1)
    PL/SQL-procedure is geslaagd.
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7                , rownum rowno
      8             from emp
      9         )
    10   where empno = 7839
    11  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 2077119879
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |    14 |   644 |     3   (0)| 00:00:01 |
    |*  1 |  VIEW               |      |    14 |   644 |     3   (0)| 00:00:01 |
    |   2 |   COUNT             |      |       |       |            |          |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   196 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("EMPNO"=7839)
    15 rijen zijn geselecteerd.
    SQL> exec dbms_lock.sleep(1)
    PL/SQL-procedure is geslaagd.
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7                , rownum rowno
      8             from emp
      9            where empno = 7839
    10         )
    11  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 1054641936
    | Id  | Operation                     | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |        |     1 |    46 |     1   (0)| 00:00:01 |
    |   1 |  VIEW                         |        |     1 |    46 |     1   (0)| 00:00:01 |
    |   2 |   COUNT                       |        |       |       |            |          |
    |   3 |    TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    14 |     1   (0)| 00:00:01 |
    |*  4 |     INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("EMPNO"=7839)
    16 rijen zijn geselecteerd.Now the two queries are not the same anymore. If you wonder why, please look carefully at the query results of both:
    SQL> select *
      2    from ( select empno
      3                , ename
      4                , sal
      5                , rownum rowno
      6             from emp
      7         )
      8   where empno = 7839
      9  /
         EMPNO ENAME             SAL      ROWNO
          7839 KING             5000          9
    1 rij is geselecteerd.
    SQL> select *
      2    from ( select empno
      3                , ename
      4                , sal
      5                , rownum rowno
      6             from emp
      7            where empno = 7839
      8         )
      9  /
         EMPNO ENAME             SAL      ROWNO
          7839 KING             5000          1
    1 rij is geselecteerd.Regards,
    Rob.

  • JDBC Driver 11.2.0.1.0 freeze after execute query with order by

    Hi,
    I have two tables : A and B
    The table B has as foreign key the ID from table A.
    I'm executing statment select id, foreing_id, name from table b order by foreing_id;
    After executing query I see on database that query remains inactive and I don't receive any response on my client.
    I've activate the oracle driver logs and I notice that driver stop working after these lines
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.OracleSql getSqlBytes
    TRACE_30: return: [B@126f827
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.OracleSql getSqlBytes
    TRACE_30: Exit
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.DBConversion getServerCharSetId
    TRACE_16: Enter:
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.DBConversion getServerCharSetId
    TRACE_16: return: 178
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.DBConversion getServerCharSetId
    TRACE_16: Exit
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.DBConversion getNCharSetId
    TRACE_16: Enter:
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.DBConversion getNCharSetId
    TRACE_16: return: 2000
    Dec 26, 2012 7:05:22 PM oracle.jdbc.driver.DBConversion getNCharSetId
    TRACE_16: Exit
    I'm using linux machine to execute this query, and I tried execute this same application in another linux machine and the query works.
    It's very strange, for instance, this only happens if I have two records on table B using the id from table A, and also happens if only one record from table A.
    Could someone help me what's going on with oracle driver?

    LOG ORACLE DRIVER_
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql initialize
    TRACE_30: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSqlKind
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql computeBasicInfo
    TRACE_16: Enter: "SELECT ID, TABLE_A_ID, NAME, URL, ISACTIVE FROM TABLE_B ORDER BY TABLE_A_ID"
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql computeBasicInfo
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSqlKind
    TRACE_30: return: 0
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSqlKind
    TRACE_30: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement prepareForNewResults
    TRACE_16: Enter: true, true
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement clearWarnings
    TRACE_16: Public Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement clearWarnings
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement prepareForNewResults
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement doExecuteWithTimeout
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement doExecuteWithTimeout
    TRACE_20: Debug: needToPrepareDefineBuffer = true
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement doExecuteWithTimeout
    CONFIG: SQL: SELECT ID, TABLE_A_ID, NAME, URL, ISACTIVE FROM TABLE_B ORDER BY TABLE_A_ID
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanOldTempLobs
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempClobs
    TRACE_16: Enter: null
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempClobs
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempBlobs
    TRACE_16: Enter: null
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempBlobs
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanOldTempLobs
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.PhysicalConnection registerHeartbeat
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.PhysicalConnection registerHeartbeat
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.PhysicalConnection needLine
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.PhysicalConnection needLineUnchecked
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.PhysicalConnection needLineUnchecked
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.PhysicalConnection needLine
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection open
    TRACE_16: Enter: oracle.jdbc.driver.T4CStatement@af72d8
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection assertLoggedOn
    TRACE_16: Enter: "T4CConnection.open"
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection assertLoggedOn
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement setCursorId
    TRACE_16: Enter: 0
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement setCursorId
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection open
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement executeMaybeDescribe
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement executeMaybeDescribe
    TRACE_20: Debug: rowPrefetchChanged = false, needToParse = true, needToPrepareDefineBuffer = true, columnsDefinedByUser = false
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CStatement executeForDescribe
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection assertLoggedOn
    TRACE_16: Enter: "oracle.jdbc.driver.T4CStatement.execute_for_describe"
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection assertLoggedOn
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanOldTempLobs
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempClobs
    TRACE_16: Enter: null
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempClobs
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempBlobs
    TRACE_16: Enter: null
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanTempBlobs
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleStatement cleanOldTempLobs
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection assertLoggedOn
    TRACE_16: Enter: "oracle.jdbc.driver.T4CStatement.doOall8"
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection assertLoggedOn
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection sendPiggyBackedMessages
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection sendPiggyBackedClose
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection sendPiggyBackedClose
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.T4CConnection sendPiggyBackedMessages
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSqlBytes
    TRACE_16: Enter: true, false
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSql
    TRACE_16: Enter: true, false
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql parse
    TRACE_16: Enter: "SELECT ID, TABLE_A_ID, NAME, URL, ISACTIVE FROM TABLE_B ORDER BY TABLE_A_ID"
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql skipSpace
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql skipSpace
    TRACE_30: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql handleODBC
    TRACE_16: Enter: NORMAL
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql handleODBC
    TRACE_30: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql parse
    TRACE_16: return: SELECT ID, TABLE_A_ID, NAME, URL, ISACTIVE FROM TABLE_B ORDER BY TABLE_A_ID
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql parse
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSql
    TRACE_30: return: SELECT ID, TABLE_A_ID, NAME, URL, ISACTIVE FROM TABLE_B ORDER BY TABLE_A_ID
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSql
    TRACE_30: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion StringToCharBytes
    TRACE_16: Enter: "SELECT ID, TABLE_A_ID, NAME, URL, ISACTIVE FROM TABLE_B ORDER BY TABLE_A_ID"
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion StringToCharBytes
    TRACE_16: return: [B@289d2e
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion StringToCharBytes
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSqlBytes
    TRACE_30: return: [B@289d2e
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.OracleSql getSqlBytes
    TRACE_30: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getServerCharSetId
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getServerCharSetId
    TRACE_16: return: 178
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getServerCharSetId
    TRACE_16: Exit
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getNCharSetId
    TRACE_16: Enter:
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getNCharSetId
    TRACE_16: return: 2000
    Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getNCharSetId
    TRACE_16: Exit
    DDL TABLE A*
    CREATE TABLE "TABLE_A"
    (     "ID" NUMBER NOT NULL ENABLE,
         "NAME" VARCHAR2(50 BYTE) NOT NULL ENABLE,
         "TYPE" NUMBER NOT NULL ENABLE,
         "VERSION" VARCHAR2(30 BYTE) NOT NULL ENABLE,
         "ISIMPLIED" NUMBER(1,0),
         CONSTRAINT "TABLE_A_PK" PRIMARY KEY ("ID")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ENABLE
    ) SEGMENT CREATION IMMEDIATE
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ;
    CREATE UNIQUE INDEX "TABLE_A_NAME_UNIQ" ON "TABLE_A" ("NAME")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ;
    CREATE UNIQUE INDEX "TABLE_A_PK" ON "TABLE_A" ("ID")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ;
    DDL Table B:_
    CREATE TABLE "TABLE_B"
    (     "ID" NUMBER NOT NULL ENABLE,
         "TABLE_A_ID" NUMBER NOT NULL ENABLE,
         "NAME" VARCHAR2(50 BYTE) NOT NULL ENABLE,
         "URL" VARCHAR2(2000 BYTE) NOT NULL ENABLE,
         "ISACTIVE" NUMBER(1,0) NOT NULL ENABLE,
         CONSTRAINT "TABLE_B_PK" PRIMARY KEY ("ID")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ENABLE,
         CONSTRAINT "TABLE_A_FK" FOREIGN KEY ("TABLE_A_ID")
         REFERENCES "TABLE_A" ("ID") ON DELETE CASCADE ENABLE
    ) SEGMENT CREATION IMMEDIATE
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ;
    CREATE UNIQUE INDEX "TABLE_B_NAME_UNIQ" ON "TABLE_B" ("NAME")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ;
    CREATE UNIQUE INDEX "TABLE_B_PK" ON "TABLE_B" ("ID")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "APPDATA" ;
    Comments*_
    After line: Dec 27, 2012 11:33:38 AM oracle.jdbc.driver.DBConversion getNCharSetId TRACE_16: Exit the driver freeze.
    I can see on DB that query keep INACTIVE and oracle driver doesn't throws any exception.
    My Oracle version is 11.2.0.1.0 and as well as oracle driver, I also tried use the version 11.2.0.3.0 but the problem persists.
    More facts:
    If I remove or replace by another field the clause order by TABLE_A_ID from query the query works.
    In this case, I have two recods on TABLE_B with TABLE_A_ID equals 2, if I remove one of these records the query works.
    The bug happens only one specific machine where the number of routers is bigger than another machine that works with all possible scenarios.
    Edited by: 978737 on Dec 27, 2012 12:11 PM

  • EJB finder query with ORDER BY clause

    Hi,
    How to query the data in ordered list using Order By clause in the entity Bean.
    Here is the part of My code in which i am interrested.
    /* @ejbgen:finder
    * signature = "Collection findAllData()"
    * ejb-ql = "SELECT OBJECT(z) FROM DataProfileBean AS z"
    abstract public class DataProfileBean extends EntityAdapter {
    * @ejbgen:cmp-field column = DATA_PREFIX
    * @ejbgen:primkey-field
    * @ejbgen:local-method transaction-attribute = Required
    public abstract Integer getDataPrefix();
    public abstract void setDataPrefix(Integer DataPrefix);
    Now what modification needs to be done in the ejb-ql query to find the DataPrefix in the sorted list.
    Regards,
    Dilip

    I don't think the current spec for EJBs support ORDER BY. But Weblogic has an extension that you can use (that is, if you're using it). Here's the info: http://e-docs.bea.com/wls/docs61/ejb/cmp.html#1076421

  • Query builder 'order by'

    Hi all,
    I'm using query builder to retrieve result. Generated query statement is:
         /jcr:root/content/dam/myFolder//element(*, dam:Asset) order by jcr:content/metadata/general/@views descending
    The attribute 'views' is of xtype numberfield, but of course numberfield is a textfield with only numbers allowed inside and stored as String.
    Ordering by this attribute returns hits ordered in descending alphabetical order.
    My question is if it's possible to execute query with ordering by number value of it's attribute, not string value.
    Thanks a lot for help

    The xpath search cannot do this. So the best option (also in terms of performance) is to make that property a LONG.
    Alternatively you can write a custom querybuilder predicate evaluator that can provide a custom comparator. In the query, you would then address that predicate in the orderby to use the comparator:
    stringasnumber=jcr:content/metadata/general/views
    orderby=stringasnumber
    It could inherit from the standard JcrPropertyPredicateEvaluator or even from RangePropertyPredicateEvaluator (to support range queries as well, using filtering). Note that such a comparator will be slow if there are many results to order (since it does not make use of any search index).

  • Problem with performance of a query having order by, distinct clause

    Hi,
    I have a problem with queries having order by, distinct clause.
    While its executing its taking lot of time. With DBMS_PROFILER identified the queries taking long time.
    The table is having approximately 70 million rows.
    Problem -1
    select * from table_name order by col1;
    select distinct col1,col2 from table_name;
    Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.
    Solution1:
    Max parallel servers is 8.
    select /* + parallel(table_name,8) */ * from table_name order by col1;
    select /* + parallel(table_name,8) */ distinct col1, col2 from table_name ;
    Solution-2:
    select /* + first_rows */ * from table_name order by col1;
    select /* + first_rows */ distinct col1, col2 from table_name ;
    Problem-2
    I am having a query with where condition on columns.
    Select * from table_name where col1='value1' and col2!='value2';
    Index created on col1 and col2.
    As we no that not equal won't use index as it is a composite index it should use the lead column. but its not using the index.
    Should i forcibly use index with hint or suggest me better solution.
    Any help really appreciated.
    Thanks in advance

    unique wrote:
    The table is having approximately 70 million rows.
    select * from table_name order by col1;Do you really want 70,000,000 rows from your table without any restrictions ? And furthermore ordered output ? I honestly understand the slowness of that query.
    Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.Who knows if you choosed the right solution. I would suggest to reconsider your query and the need of 70,000,000 returned rows.
    Problem-2
    I am having a query with where condition on columns.
    Select * from table_name where col1='value1' and col2!='value2';Please, provide the explain plan, eventually the tkprof output could also help. And tables descirption AND indexes description.
    And OS and Oracle version.
    Nicolas.

  • Optimizing order by query with multiple time dimensions

    Hello all,
    I have two time dimensions, one a standard date dimension (Year,Qtr, Month, Week, Day) the other a user defined Time dimension (All, Hour, Minute, Second).
    I am joining my cube with my time dimension using only the 'All' level, so that I can get a single record for the Day level in my Date dimension. Under these circumanstances there aren't many records in my sample data. Less than 100 dates, although at the lowest level(seconds) there are approx 2 million records.
    In order to get my results back in order I am ordering by the date dimension day_end_date. The query is taking longer than I would expect given that there aren't many records at the Day Level. How can I ensure that my query is ordering based only on the values in the current day_level and not all day_end_dates values in the underlying cube.

    Changed order, speed improved significantly.

  • Is that important column order in a query with row_number function

    Hi folks,
    I am using Oracle 11g R2 on HP-UX machine.
    I have 2 types of query with row_number and I think they are same but output of each of them are different. I changed only column order in query2.
    Query 1 :
    (SELECT
    "LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
    "LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
    FROM (
    SELECT row_number ()
    OVER (
    PARTITION BY "R_CON_SUBS_SIMCARD_LK".
    "CONTRACT_SK"
    ORDER BY
    "R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
    "R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
    "SIRA",
    "R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
    "R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK"
    FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
    "LOOKUP_INPUT_SUBQUERY"
    WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
    Output of this like that :
    CONTRACT_SK SIMCARD_SK
    1     1
    1     3
    1     4
    1     5
    1     6
    1     11
    1     12
    1     14
    1     15
    1     16
    Query 2 :
    (SELECT
    "LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
    "LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
    FROM (
    SELECT
    "R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
    "R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK",
    row_number ()
    OVER (
    PARTITION BY "R_CON_SUBS_SIMCARD_LK".
    "CONTRACT_SK"
    ORDER BY
    "R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
    "R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
    "SIRA"
    FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
    "LOOKUP_INPUT_SUBQUERY"
    WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
    Output of this like that:
    2     874812
    7     70097256
    8     18734091
    9     158024
    10     815397739
    13     22657919
    19     83177779
    20     82579529
    22     5829949
    23     35348926
    25     3865978
    I expected the second output, because there are lots of contract sk but there is one contract_sk in first query result. i did not get the point. What is the problem ?

    user8649469 wrote:
    I changed only column order in query2.So what else do you expect? If you order, for example, by last name, fist name don't you think rows will be returned in a different order (and therefore same row will have different row number) than ordering by first name, last name?
    SY.

  • Need help in optimizing the query with joins and group by clause

    I am having problem in executing the query below.. it is taking lot of time. To simplify, I have added the two tables FILE_STATUS = stores the file load details and COMM table that is actual business commission table showing records successfully processed and which records were transmitted to other system. Records with status = T is trasnmitted to other system and traansactions with P is pending.
    CREATE TABLE FILE_STATUS
    (FILE_ID VARCHAR2(14),
    FILE_NAME VARCHAR2(20),
    CARR_CD VARCHAR2(5),
    TOT_REC NUMBER,
    TOT_SUCC NUMBER);
    CREATE TABLE COMM
    (SRC_FILE_ID VARCHAR2(14),
    REC_ID NUMBER,
    STATUS CHAR(1));
    INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
    INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
    INSERT INTO COMM VALUES ('12345678', 1, 'T');
    INSERT INTO COMM VALUES ('12345678', 3, 'T');
    INSERT INTO COMM VALUES ('12345678', 4, 'P');
    INSERT INTO COMM VALUES ('12345678', 5, 'P');
    COMMIT;Here is the query that I wrote to give me the details of the file that has been loaded into the system. It reads the file status and commission table to show file name, total records loaded, total records successfully loaded to the commission table and number of records that has been finally transmitted (status=T) to other systems.
    SELECT
        FS.CARR_CD
        ,FS.FILE_NAME
        ,FS.FILE_ID
        ,FS.TOT_REC
        ,FS.TOT_SUCC
        ,NVL(C.TOT_TRANS, 0) TOT_TRANS
    FROM FILE_STATUS FS
    LEFT JOIN
        SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
        FROM COMM
        WHERE STATUS = 'T'
        GROUP BY SRC_FILE_ID
    ) C ON C.SRC_FILE_ID = FS.FILE_ID
    WHERE FILE_ID = '12345678';In production this query has more joins and is taking lot of time to process.. the main culprit for me is the join on COMM table to get the count of number of transactions transmitted. Please can you give me tips to optimize this query to get results faster? Do I need to remove group and use partition or something else. Please help!

    I get 2 rows if I use my query with your new criteria. Did you commit the record if you are using a second connection to query? Did you remove the criteria for file_id?
    select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
      from (select fs.carr_cd,
                   fs.file_name,
                   fs.file_id,
                   fs.tot_rec,
                   fs.tot_succ,
                   count(case
                            when c.status = 'T' then
                             1
                            else
                             null
                          end) over(partition by c.src_file_id) tot_trans,
                   row_number() over(partition by c.src_file_id order by null) rn
              from file_status fs
              left join comm c
                on c.src_file_id = fs.file_id
             where carr_cd = 'LIBM')
    where rn = 1;
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS
    LIBM    CM_LIBM.TXT          12345678                5          4          2
    LIBM    CM_LIBM.TXT          12345677               10          0          0Using RANK can potentially produce multiple rows to be returned though your data may prevent this. ROW_NUMBER will always prevent duplicates. The ordering of the analytical function is irrelevant in your query if you use ROW_NUMBER. You can remove the outermost query and inspect the data returned by the inner query;
    select fs.carr_cd,
           fs.file_name,
           fs.file_id,
           fs.tot_rec,
           fs.tot_succ,
           count(case
                    when c.status = 'T' then
                     1
                    else
                     null
                  end) over(partition by c.src_file_id) tot_trans,
           row_number() over(partition by c.src_file_id order by null) rn
    from file_status fs
    left join comm c
    on c.src_file_id = fs.file_id
    where carr_cd = 'LIBM';
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS         RN
    LIBM    CM_LIBM.TXT          12345678                5          4          2          1
    LIBM    CM_LIBM.TXT          12345678                5          4          2          2
    LIBM    CM_LIBM.TXT          12345678                5          4          2          3
    LIBM    CM_LIBM.TXT          12345678                5          4          2          4
    LIBM    CM_LIBM.TXT          12345677               10          0          0          1

  • Long run time with ORDER by clause

    Hi,
    I am having a query which is executing fine(in 2 mins) but when i am using order by clause in it, its taking around 13 mins.
    Can anyone suggest what could be th reason and how to execute the same query are get the ordered record?
    thanks.

    Sorry for not providing complet details.
    Database version id 10g.
    Below is the execution plan when using with order by clause.
    Execution Plan
    | Id  | Operation                              | Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT                       |                   |     1 |   118 |  1538 |
    |   1 |  FILTER                                |                   |       |       |       |
    |   2 |   HASH JOIN                            |                   | 16657 |  1089K|    56 |
    |   3 |    TABLE ACCESS FULL                   | FILETYP           |     6 |    60 |     3 |
    |   4 |    TABLE ACCESS FULL                   | FILETYPSOURCEID   | 16657 |   927K|    52 |
    |   5 |   NESTED LOOPS                         |                   |     1 |    35 |     3 |
    |   6 |    TABLE ACCESS BY INDEX ROWID         | FILEWAREHOUSE     |     1 |    25 |     2 |
    |   7 |     INDEX RANGE SCAN                   | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |   8 |    TABLE ACCESS BY INDEX ROWID         | EXTFILE           |     1 |    10 |     1 |
    |   9 |     INDEX UNIQUE SCAN                  | PK_EXTFILE        |     1 |       |     1 |
    |  10 |  SORT ORDER BY                         |                   |     1 |   118 |  1538 |
    |  11 |   NESTED LOOPS                         |                   |     1 |   118 |  1534 |
    |  12 |    NESTED LOOPS OUTER                  |                   |     1 |   100 |  1533 |
    |  13 |     NESTED LOOPS OUTER                 |                   |     1 |    96 |  1532 |
    |  14 |      NESTED LOOPS                      |                   |     1 |    88 |  1531 |
    |  15 |       HASH JOIN                        |                   |     5 |   360 |  1524 |
    |  16 |        TABLE ACCESS BY INDEX ROWID     | RTXN              |     1 |    22 |     1 |
    |  17 |         NESTED LOOPS                   |                   |   117 |  5148 |  1518 |
    |  18 |          VIEW                          | VW_SQ_1           | 20869 |   448K|  1441 |
    |  19 |           HASH GROUP BY                |                   | 20869 |   427K|  1441 |
    |  20 |            FILTER                      |                   |       |       |       |
    |  21 |             TABLE ACCESS BY INDEX ROWID| RTXNSTATHIST      | 20869 |   427K|  1304 |
    |  22 |              INDEX RANGE SCAN          | RTXNSTATHIST_DX2  | 20869 |       |    29 |
    |  23 |          INDEX RANGE SCAN              | PK_RTXN           |     1 |       |     1 |
    |  24 |           NESTED LOOPS                 |                   |     1 |    24 |     3 |
    |  25 |            TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE     |     1 |    14 |     2 |
    |  26 |             INDEX RANGE SCAN           | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |  27 |            TABLE ACCESS BY INDEX ROWID | EXTFILE           |     1 |    10 |     1 |
    |  28 |             INDEX UNIQUE SCAN          | PK_EXTFILE        |     1 |       |     1 |
    |  29 |        TABLE ACCESS FULL               | RTXNTYP           |     1 |    28 |     5 |
    |  30 |       TABLE ACCESS BY INDEX ROWID      | RTXNSTATHIST      |     1 |    16 |     2 |
    |  31 |        INDEX RANGE SCAN                | PK_RTXNSTATHIST   |     1 |       |     1 |
    |  32 |      TABLE ACCESS BY INDEX ROWID       | NTWKNODE          |     1 |     8 |     1 |
    |  33 |       INDEX UNIQUE SCAN                | PK_NTWKNODE       |     1 |       |     1 |
    |  34 |     INDEX UNIQUE SCAN                  | PK_ORG            |     1 |     4 |     1 |
    |  35 |    TABLE ACCESS BY INDEX ROWID         | ACCT              |     1 |    18 |     1 |
    |  36 |     INDEX UNIQUE SCAN                  | PK_ACCT           |     1 |       |     1 |
    Below is the execution plan when running without ORDER BY clause...
    Execution Plan
    | Id  | Operation                             | Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT                      |                   |     1 |   135 |  1537 |
    |   1 |  FILTER                               |                   |       |       |       |
    |   2 |   HASH JOIN                           |                   | 16657 |  1089K|    56 |
    |   3 |    TABLE ACCESS FULL                  | FILETYP           |     6 |    60 |     3 |
    |   4 |    TABLE ACCESS FULL                  | FILETYPSOURCEID   | 16657 |   927K|    52 |
    |   5 |   NESTED LOOPS                        |                   |     1 |    35 |     3 |
    |   6 |    TABLE ACCESS BY INDEX ROWID        | FILEWAREHOUSE     |     1 |    25 |     2 |
    |   7 |     INDEX RANGE SCAN                  | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |   8 |    TABLE ACCESS BY INDEX ROWID        | EXTFILE           |     1 |    10 |     1 |
    |   9 |     INDEX UNIQUE SCAN                 | PK_EXTFILE        |     1 |       |     1 |
    |  10 |  NESTED LOOPS                         |                   |     1 |   135 |  1534 |
    |  11 |   NESTED LOOPS OUTER                  |                   |     1 |   117 |  1533 |
    |  12 |    NESTED LOOPS OUTER                 |                   |     1 |   113 |  1532 |
    |  13 |     NESTED LOOPS                      |                   |     1 |   105 |  1531 |
    |  14 |      HASH JOIN                        |                   |     5 |   445 |  1524 |
    |  15 |       TABLE ACCESS FULL               | RTXNTYP           |     1 |    28 |     5 |
    |  16 |       TABLE ACCESS BY INDEX ROWID     | RTXN              |     1 |    22 |     1 |
    |  17 |        NESTED LOOPS                   |                   |   117 |  7137 |  1518 |
    |  18 |         VIEW                          | VW_SQ_1           | 20869 |   794K|  1441 |
    |  19 |          HASH GROUP BY                |                   | 20869 |   427K|  1441 |
    |  20 |           FILTER                      |                   |       |       |       |
    |  21 |            TABLE ACCESS BY INDEX ROWID| RTXNSTATHIST      | 20869 |   427K|  1304 |
    |  22 |             INDEX RANGE SCAN          | RTXNSTATHIST_DX2  | 20869 |       |    29 |
    |  23 |         INDEX RANGE SCAN              | PK_RTXN           |     1 |       |     1 |
    |  24 |          NESTED LOOPS                 |                   |     1 |    24 |     3 |
    |  25 |           TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE     |     1 |    14 |     2 |
    |  26 |            INDEX RANGE SCAN           | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |  27 |           TABLE ACCESS BY INDEX ROWID | EXTFILE           |     1 |    10 |     1 |
    |  28 |            INDEX UNIQUE SCAN          | PK_EXTFILE        |     1 |       |     1 |
    |  29 |      TABLE ACCESS BY INDEX ROWID      | RTXNSTATHIST      |     1 |    16 |     2 |
    |  30 |       INDEX RANGE SCAN                | PK_RTXNSTATHIST   |     1 |       |     1 |
    |  31 |     TABLE ACCESS BY INDEX ROWID       | NTWKNODE          |     1 |     8 |     1 |
    |  32 |      INDEX UNIQUE SCAN                | PK_NTWKNODE       |     1 |       |     1 |
    |  33 |    INDEX UNIQUE SCAN                  | PK_ORG            |     1 |     4 |     1 |
    |  34 |   TABLE ACCESS BY INDEX ROWID         | ACCT              |     1 |    18 |     1 |
    |  35 |    INDEX UNIQUE SCAN                  | PK_ACCT           |     1 |       |     1 |
    -------------------------------------------------------------------------------------------Edited by: user10754555 on Feb 5, 2010 6:02 PM

  • Query with union

    Hi,
    I have three table:
    Candidates: (candidate_id primary key)
    Purhcase_orders: (Po_number primary key)
    Bids: (bid_number primary key)
    Just wanted to retrieve candidate information like candidate_id, first_name etc, along with count of purchase orders issued against this candidate and count of bid_number.
    For that I have written below query:
    query - 1:
    SELECT CANDIDATE_ID,
    INITCAP (first_name) FIRST_NAME,
    +(SELECT COUNT (DISTINCT bid_number)+
    FROM bids
    WHERE BIDS.CANDIDATE_ID = cand.candidate_id)
    BID_COUNT,
    +(SELECT COUNT (DISTINCT po_number)+
    FROM purchase_orders po
    WHERE PO.CONTRACTEE_ID = cand.candidate_id)
    PO_COUNT,
    +'Y' match_flag,+
    DECODE ( (SELECT candidate_id
    FROM v_ineligible_candidates vic
    WHERE VIC.CANDIDATE_ID = cand.candidate_id),
    NULL, 'N',
    +'Y')+
    INELIGIBLE_FLAG
    FROM candidates cand
    Based on business requirement, need to create another set of query (query -2) same like above. In that we have some decode statements to calculate match_flag, then need to perform UNION operation between query -1 and query -2.
    have around 130563 number of rows in candidates table.
    Individually both queries are taking 500 msec.
    But when I have used union, it didnt give result for atleast 60 sec. Then I cancelled execution.
    Execution plan for the final query with UNION: (final cost)
    Cost: 2,873  Bytes: 9,130,170  Cardinality: 260,862                
    Please help me in this issue.
    Why its taking that much time in union.
    Please correct my mistake and suggest me in this query.
    UNION ALL is running but not UNION.
    Thanks in advance

    Please post complete Explain Plans.
    To get detailed information of Explain Plan use
    explain plan for
    your_query;
    select *
      from table(dbms_xplan.display(null, null, 'ALL'));Post it alongwith below details between {noformat}{noformat} (exactly as specified) tags to preserve formatting and ease of understanding.
    On your requirement,
    Using UNIONALL you will get two set of rows, with UNION you might get a single row if your MATCH_FLAG are same for both queries. Use of either, has to meet your requirements than to meet your performance. If it is Business Acceptable, then look for performance and tuning.
    If you could do the folllowing, it might be helpful for you.
    1. Post the Sample table structure (Table information of Candidates should suffice) in a Create Table/With Sub-Query clause.
    2. Sample Data in Insert Into/With Sub-Query format.
    3. Expected Outcome based on Sample data
    4. The Explain Plan of your Queries as requested above.
    Reason of asking these details are, there might be a way to avoid Hitting the table Twice and avoid use of UNION/UNIONALL clauses.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • I have an iMac 21.5 late 2009, the hard drive has failed.

    Instead of spending £200 replacing the internal hard drive, is it possible to run Lion off an external firewire 800 hard drive. If so, what are the negatives. The employee at western computers told me that it will run slower than it would with an int

  • INDesgin image links broken after saving file across systems

    Hi We have a scenario involving 3 components: 1. Linux file server running both SMB and AFP (sharing the same directory thru both protocols) 2. MacOS 10.5 (Leopard) with INDesign CS3 connecting to the Linux server thru AFP 3. Windows 2003 server runn

  • How do i transfer files from my ipod to itunes?

    my computer crashed recently, but before it did i was able to save a number of uncorrupted media files on my ipod (some of my favorite albums in fact...). i installed a new hard drive and reinstalled itunes...but now i can't seem to get the music fro

  • ADF Faces - Panel Accordion rendering issue

    Hi, I am trying to follow this tutorial about adf faces: http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_55/jdtut_11r2_55_2.html but when I click on the detail items in the accordion component, the objects inside desappears and I could see a

  • Hi all. My imac disk is full

    I installed Leopard on an external drive connected by firewire. I can boot fine from their. Is their an easy way to transfer my files to the external drive so it will work just like my current setup is configured?