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
Similar Messages
-
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 -
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,
DilipI 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
-
Hai all,
I have problem with order by clause,
My query is
"select number from table1 order by number asc "
and the output is displaying as
1
10
12
13
15
17
19
2
20
21
22
But if we give order by it should display as below only right ?
1
2
10
12
13
15
17
19
20
21
22 ........
Please help me why it is not displaying like it. and how to make the statement to display like the second case. Thanks in advance.
Regards,
UrajaThe column datatype that you are selecting is not of NUMBER datatype(might be char or varchar2) hence you are getting such result set.
And for this purpose, it is recommended to set datatype of a column appropriately.
For now you can add TO_NUMBER function to column in ORDER BY clause, only if it has data of number type.
Edited by: Ora on 19 Nov, 2012 3:10 AM -
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 -
Default where with order by clause
Hi all
How to use Default where with order by clause
for example i want to use Default_where clause with order by clause
Regards
Shahzaib ismailHi,
I have a similar query for where clause.
my query-find form is a multi record form like below:
Criteria - Condition - Value
Item/Category/Planner (List_Item) - Equals/Among (List_Item) - text_FIELD
Item - Equals - ITEM_1
Category - Among - ('CAT1', 'CAT2')
Planner - Equals - PL1
Find_BUTTON Clear_BUTTON
User can select any criteria and condition combination and then enter the value in "Value" text field.
My query is: how can I prepare a where clause based on user input since the user can enter any number of values/combinations? I guess I would have to use some looping to generate where clause.
Thanks
Imran -
ROWNUM can use with ORDER BY clause?
Hi
Following i have two quires in ROWNUM order for example..
1:query
select rownum,empno,ename,deptno from emp
where rownum <= 14;
result:
rownum empno ename deptno
1 7369 SMITH 20
2 7499 ALLEN 30
3 7521 WARD 30
4 7566 JONES 20
5 7654 MARTIN 30
6 7698 BLAKE 30
7 7782 CLARK 10
8 7788 SCOTT 20
9 7839 KING 10
10 7844 TURNER 30
11 7876 ADAMS 20
12 7900 JAMES 30
13 7902 FORD 20
14 7934 MILLER 10
2:Query , add ORDER BY clause it will change the sequence of ROWNUM.
select rownum,empno,ename,deptno from emp
where rownum <= 14
order by deptno;
result:
rownum empno ename deptno
7 7782 CLARK 10
9 7839 KING 10
14 7934 MILLER 10
1 7369 SMITH 20
11 7876 ADAMS 20
13 7902 FORD 20
8 7788 SCOTT 20
and so on......
but i want these records from 2 to 5...how i can query this through ROWNUM or any sequence because ORDER BY clause change the order of ROWNUM and i could get this result.
rownum empno ename deptno
9 7839 KING 10
14 7934 MILLER 10
1 7369 SMITH 20
11 7876 ADAMS 20
please send me general query which i can apply on any table.
advance thanks.My guess is that you are looking for a pagination solution. If so, here is a thread on Asktom:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:127412348064
So, essentially, you ORDER BY first and then write a wrapper to get your the rownum.
If you do it this way, You will also use the top-n optimization that Oracle uses.
Rahul. -
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
KHi,
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. -
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. -
IN clause with ORDER BY clause in sub-queries
Hello,
We generate dynamic queries with the following statement pattern (could be many union/intersect sub-queries):
select my_col
from my_table
where my_col IN
select table_2.my_col , x_col from table_2 where x_col > 10
UNION
select table_3.my_col , y_col from table_3 where y_col > 20
INTERSECT
select table_4.my_col , z_col from table_4 where z_col is between 30 and 50
I know that I can do just the sub-queries w/ an ORDER BY clause as follows (as long as the 2nd parameter in the select stmts are of the same type):
select table_2.my_col , x_col from table_2 where x_col > 10
UNION
select table_3.my_col , y_col from table_3 where y_col > 20
INTERSECT
select table_4.my_col , z_col from table_4 where z_col is between 30 and 50
order by 2 desc
But my questions are:
1. What is (if there is) the syntax that will ensure that the result set order will be that of the ordering of the sub-queries?
Or does my SQL stmt have to have syntactically (but not semantically) change to achieve this?
Thanks,
JimRandolf Geist wrote:
just a minor doubt - I think it is not officially supported to have separate ORDER BYs in a compound query with set operators (e.g. UNION / UNION ALL subsets). Of course one could use inline views with NO_MERGE + NO_ELIMINATE_OBY hints, but I think the only officially supported approach is to use a single, final ORDER BY (that needs to use positional notation as far as I remember).
Randolf,
You're right, of course, about the separate "order by" clauses.
Interestingly the following type of thing does work though (in 10.2.0.3, at least):
with v1 as (
select * from t1 where col1 = 'ABC' order by col2
v2 as (
select * from t1 where col1 = 'DEF' order by col2
select * from v1
union all
select * from v2
;A quick check the execution plan suggsts that Oracle appears to be convering this to the following - even though its technically not acceptable in normal circumstances:
select * from t1 where col1 = 'ABC' order by col2
union all
select * from t1 where col1 = 'DEF' order by col2
;Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
"Science is more than a body of knowledge; it is a way of thinking"
Carl Sagan -
Performance with order by clause
Dear all,
please find the below query .if i executed without order by it is going to execute with in 2 sec.if i add order by clause
it is taking more than 2 min.as per the business we need order by clause .plaese suggest me.it's very urgent.
SELECT "FACILITY_ID","VESSEL_NAME","CLASS_NUM","SURVEY_REPORT_NO","IMO_NUMBER","VESSEL_TYPE","VESSEL_TYPE_ID","PRIMARY_BUILDER","BUILDER_ID","REGISTER_OWNER","ABS_SURVEY_STATUS_ID","ABS_SURVEY_STATUS_DATE","NOT_ASSIGNED_SINCE","NO_OF_FINDINGS","CASE","SPM_ITM_CAT_NAME","LEAST_CONFIDENCE" FROM (SELECT
V. FACILITY_ID,
v.vessel_name,
v.class_num,
ASR.SURVEY_REPORT_NO,
V.IMO_NUMBER,
V.VESSEL_TYPE,
v.vessel_type_id,
V.PRIMARY_BUILDER,
V.BUILDER_ID,
V.REGISTER_OWNER,
ASR.ABS_SURVEY_STATUS_ID,
ASR.abs_survey_status_date,
ROUND(SYSDATE - ASR.abs_survey_status_date) AS NOT_ASSIGNED_SINCE,
(SELECT COUNT(1) FROM ABS_FINDINGS WHERE survey_report_no = asr.survey_report_no AND FIN_TAG_STAT_ID IN( 'TG')) AS no_of_findings,
CASE WHEN ( SELECT rnum FROM (SELECT survey_report_no,COUNT(rnum) rnum FROM (SELECT a.survey_report_no,COUNT(*) rnum FROM ABS_FINDINGS A,ABS_SURVEY_REPORTS b
WHERE a.survey_report_no=b.survey_report_no
GROUP BY a.survey_report_no,spm_item_category) GROUP BY survey_report_no ) WHERE survey_report_no=asr.survey_report_no )=1 THEN
( SELECT spm_item_cat_id FROM ABS_FINDINGS WHERE survey_report_no = asr.survey_report_no AND ROWNUM<2)
ELSE
5
END CASE,
(SELECT SPM_ITM_CAT_NAME FROM SPM_ITEM_CATEGORIES WHERE SPM_ITEM_CAT_ID =
(CASE WHEN ( SELECT rnum FROM (SELECT survey_report_no,COUNT(rnum) rnum FROM (SELECT a.survey_report_no,COUNT(*) rnum FROM ABS_FINDINGS A,ABS_SURVEY_REPORTS b
WHERE a.survey_report_no=b.survey_report_no
GROUP BY a.survey_report_no,spm_item_category) GROUP BY survey_report_no ) WHERE survey_report_no=asr.survey_report_no )=1 THEN
( SELECT spm_item_cat_id FROM ABS_FINDINGS WHERE survey_report_no = asr.survey_report_no AND ROWNUM<2)
ELSE
5
END )) AS SPM_ITM_CAT_NAME,
(SELECT MIN(tag_weight) FROM TAGGED_FINDINGS
WHERE finding_id IN (SELECT finding_id FROM ABS_FINDINGS WHERE survey_report_no IN (ASR.SURVEY_REPORT_NO))) AS least_confidence
FROM
ABS_SURVEY_REPORTS ASR,
ABS_VESSELS V
WHERE
ASR.FACILITY_ID = V.FACILITY_ID
AND abs_survey_Status_id = 1 ) WHERE no_of_findings>0
ORDER BY ABS_SURVEY_STATUS_DATE
Thanks
venkatPlease start reading these informative links first:
HOW TO: Post a SQL statement tuning request - template posting
When your query takes too long ...
and then rephrase your question by posting
- database version
- execution plans
- etc. (see the links above)
Put the tag before and after your examples, so it'll stay formatted.
See: http://forums.oracle.com/forums/help.jspa -
Not able to migrate a query with not exist clause
Hi all,
I'm using Toplink 10.1.3 and I am trying to rewrite the following query with Expression Framework:
select distinct r.e_ogg_oper_k_oggetto
FROM regola_accettazione_oper_banc r, oggetto_operazione_bancaria o
where not exists (
select 1
FROM limitaz_ogg_tipo_oper_banc l
where nvl(l.d_fine_validita,trunc(sysdate)+1)>trunc(sysdate)
and l.d_inizio_validita <= trunc(sysdate)
and l.e_tpodv_k_tipo_operazione=:appoggio.tipo_operaz
and l.e_ogg_oper_k_oggetto=r.e_ogg_oper_k_oggetto
and l.e_uni_oper_k_unita_oper_util= :appoggio.e_uni_oper_k_unita_oper_esegui )
and r.e_oper_ban_k_operaz_bancaria=:appoggio.form
and r.e_ogg_oper_k_oggetto=o.k_oggetto
and o.e_ogg_oper_k_oggetto is null
and o.k_oggetto != nvl(:appoggio.oggetto_autom,,'0')
and o.k_oggetto like substr(:appoggio.oggetto,1,2)||'%'
and r.d_inizio_validita <= :appoggio.d_contab
and to_date(nvl(to_char(r.d_fine_validita,DD/MM/YYYY'),31/12/3999'),'DD/MM/YYYY')> :appoggio.d_contab
and o.f_natura_oggetto in ('G','P') and r.f_oggetto_automatizzato!='S'
I'm not able to "attach" the not exist clause to the rest of query.
How can I do it?
Thank you very much.Not exists can be used in an expression through using a ReportQuery sub-query.
i.e.
ExpressionBuilder outerBuilder = new ExpressionBuilder();
ReadAllQuery outerQuery = new ReadAllQuery(Employee.class, outerBuilder);
ExpressionBuilder subBuilder = new ExpressionBuilder();
ReportQuery subQuery = new ReportQuery(Address.class, subBuilder);
subQuery.addAttribute("id");
subQuery.setSelectionCriteria(
subBuilder.get("city").equal(outerBuilder.get("address").get("city")
.and(subBuilder.notEqual(outerBuilder.get("address")))));
outerQuery.setSelectionCriteria(
outerBuilder.notExists(subQuery));
List results = (List) session.executeQuery(outerQuery);
Refer to the documentation section on sub-queries for more information.
I would suggest simlpifying the where clause until you get the sub-query working to start.
You can also always use a custom SQL query in TopLink. -
Select statement takes very long to run with order by clause.
Hi all,
I have a select statement which when I run without the order by clause takes arround 2 minutes to run. But with the order by clause it goes on for ever. I am trying to access the database server through a network which is not too fast.
The select statement is based on 9 views which are again based on some views. It also has inline views and outer joins. These views and inline views can not be done away with.
When selected without the order by clause it gives 3215 records.
Anything like 2 to 3 minutes will be Ok.
Thanks.
--MalayThe select statement is as follows :-
SELECT f.system_name,
a.signal_type,
f.sys_signal_name,
a.bus_desc,
b.vl_ident,
b.vl_name,
b.src_mac,
b.src_mac_addr,
b.dest_mac,
b.dest_mac_addr,
b.network,
bb.bufr_size_in_bytes,
bb.bag_in_ms,
bb.is_rma_used,
bb.is_ic_used,
bb.sub_vl_cnt,
bb.skew_max_in_ns,
cc.msg_name,
c.src_ip,
c.src_ip_addr,
c.src_port,
c.dest_ip,
c.dest_ip_addr,
c.dest_port,
cc.rate_in_ms,
cc.tx_mode,
cc.protocol,
cc.port_type,
cc.msg_length_in_bytes,
d.mnemonic,
d.start_addr32,
d.lsb,
d.end_addr32,
d.msb,
d.format,
d.init_value,
d.fs_mnemonic,
d.fs_afdx_data_id,
d.digital_data_id,
DECODE(
d.digital_datatype,
NULL, '',
'UNUSED', '',
api$util.concat_column_data(
'api_'
|| d.digital_datatype,
'digital_data_id',
d.digital_data_id,
bool.FALSE
) AS data_details,
f.connection_id
|| '_'
|| a.digital_bus_id
|| '_'
|| b.afdx_vl_id
|| '_'
|| bb.afdx_output_id
|| '_'
|| c.afdx_frame_id
|| '_'
|| cc.afdx_msg_id
|| '_'
|| d.afdx_data_id AS KEY
FROM api_afdx a,
api_afdx_vl b,
api_afdx_output bb,
api_afdx_frame c,
api_afdx_msg cc,
api_afdx_data d,
vf_signal e,
(SELECT DISTINCT aa.signal_id,
cc.system_name,
bb.connection_id,
bb.sys_signal_name
FROM vf_nodes aa,
vf_connections bb,
vf_system cc
WHERE aa.connection_id = bb.connection_id
AND bb.system_id = cc.system_id) f
WHERE e.signal_id = f.signal_id(+)
AND e.digital_bus_id = a.digital_bus_id
AND a.digital_bus_id = bb.digital_bus_id(+)
AND bb.afdx_output_id = b.afdx_output_id(+)
AND b.afdx_vl_id = c.afdx_vl_id(+)
AND bb.afdx_output_id = cc.afdx_output_id(+)
AND cc.afdx_msg_id = d.afdx_msg_id(+)
ORDER BY f.system_name,
a.signal_type,
f.sys_signal_name,
b.vl_name,
cc.msg_name,
d.start_addr32,
d.lsb;
Where api_afdx ,
api_afdx_vl ,
api_afdx_output ,
api_afdx_frame ,
api_afdx_msg ,
api_afdx_data ,
vf_signal ,
vf_nodes ,
vf_connections ,
vf_system
are all views. -
Popup lov with order by clause
I created a form manually using the document from the url:
http://otn.oracle.com/products/database/htmldb/howtos/tabular_form.html#MANUAL
I used the following query from that document.
select htmldb_item.hidden(1,empno) empno,
ename,
htmldb_item.select_list_from_query(3,job,'select distinct job, job from emp') job,
htmldb_item.popupkey_from_query(4,mgr,'select ename, empno from emp',10) mgr,
wwv_flow_item.date_popup(6,null,hiredate) hiredate,
htmldb_item.text(7,sal,10) sal,
htmldb_item.text(8,comm,10) comm,
htmldb_item.select_list_from_query(9,deptno,'select dname, deptno from dept') deptno
from emp
This works fine.
But if I add an order by clause to the query the popup key for mgr column doesn't work.
select htmldb_item.hidden(1,empno) empno,
ename,
htmldb_item.select_list_from_query(3,job,'select distinct job, job from emp') job,
htmldb_item.popupkey_from_query(4,mgr,'select ename, empno from emp',10) mgr,
wwv_flow_item.date_popup(6,null,hiredate) hiredate,
htmldb_item.text(7,sal,10) sal,
htmldb_item.text(8,comm,10) comm,
htmldb_item.select_list_from_query(9,deptno,'select dname, deptno from dept') deptno
from emp
order by ename
Thanks
Chandra.Duplicate post, see:
popup lov in a report is not working if I have an order by caluse
Sergio
Maybe you are looking for
-
Is There A Way To Make The "Check Out CNN On Twitter" Pop-Up Stop?
I had an old DVR that I had to get rid of and before that I got this annoying pop-up to stop appearing but it's been weeks with my new DVR and no matter what I do it keeps popping up on the screen. Sure, you just hit 'exit' on the remote and it goes
-
HP Officejet Pro L7590 networking problem
Hi! I have the following problem: I have an Officejet Pro L7590 All-in-one printer. It is connected to my wlan router (ASUS WL-500G Premium) through its ethernet port. I have two desktop PCs, i've installed, and using this printer on them without pro
-
SSPU issue: Cache directory does not exist, and couldn't create a new downl
I have installed SSPU and created an offer over there. When I run my offer it gives the error: Cache directory does not exist, and couldn't create a new download cache directory. Can anyone tell me the root cause and workaround for this issue?
-
Absolute links on hml page in local directory not working
All the absolute links on my html pages (which are on my hardrive) are being treated as local links and are therefore not working - i.e. Firefox is adding the local file path before the url. For example, the original link is: http://www.insidehousing
-
Document written in Word:Mac 2008 shows up as yellow font for Windows Word?
When I write a document on Word for Mac and send it to someone using a PC when they open it in Word the font is all yellow. Any Advice on a fix?