Query Tuning-Help Needed
Hi ,
11.2.0.1
AIX 6.1
I have following query which is executed from Application,the query comes back within 2 secs for not so common last_name combined with gender but it is taking longer time for common last_names like 'BROWN' or 'JONES' or 'SMITH' with gender_id .
select customerin0_.ROW_NUMBER as ROW1_22596_, customerin0_.ADDRESS_ID as
ADDRESS2_22596_, customerin0_.addressTypeId as addressT3_22596_,
customerin0_.city as city22596_, customerin0_.CONTACT_DETAILS_CODE_ID as
CONTACT5_22596_, customerin0_.county as county22596_, customerin0_.countyID
as countyID22596_, customerin0_.dob as dob22596_, customerin0_.eyecolor as
eyecolor22596_, customerin0_.eyecolorid as eyecolorid22596_,
customerin0_.FIRST_NAME as FIRST11_22596_, customerin0_.gender as
gender22596_, customerin0_.genderid as genderid22596_,
customerin0_.ID_NUMBER as ID14_22596_, customerin0_.JURISDICTION_CODE as
JURISDI15_22596_, customerin0_.LAST_NAME as LAST16_22596_,
customerin0_.LEGAL_ENTITY_ID as LEGAL17_22596_,
customerin0_.LEGAL_ENTITY_NUMBER as LEGAL18_22596_,
customerin0_.LEGAL_ENTITY_TYPE as LEGAL19_22596_, customerin0_.MIDDLE_NAME
as MIDDLE20_22596_, customerin0_.STREET_ADDRESS_1 as STREET21_22596_,
customerin0_.suffix_value as suffix22_22596_, customerin0_.ZIP_CODE as
ZIP23_22596_, customerin0_.ZIP_PLUS_4 as ZIP24_22596_
from
CUSTOMER_IND_SEARCH_VIEW customerin0_ where (customerin0_.LAST_NAME like :1)
and customerin0_.genderid=:2 and rownum<=200
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 18 1.88 123.53 8245 12403 0 179
total 18 1.88 123.53 8245 12403 0 179
Misses in library cache during parse: 0
Parsing user id: 135 (???)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
ges message buffer allocation 259 0.00 0.00
gc cr grant 2-way 259 0.00 0.08
db file sequential read 10126 1.40 148.07
SQL*Net message from client 19 0.02 0.10
SQL*Net message to client 18 0.00 0.00
********************************************************************************Was not able to generate plan out of tkrprof ,captured it from OEM.
10 | NESTED LOOPS | | 805 | 73255 | 3477 (1)| 00:00:42 |
| 11 | NESTED LOOPS | | 805 | 51520 | 1866 (1)| 00:00:23 |
| 12 | NESTED LOOPS | | 805 | 33005 | 254 (0)| 00:00:04 |
|* 13 | TABLE ACCESS BY INDEX ROWID| REF_CONTACT_DETAILS | 1 | 10 | 1 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | XAK1_REF_CD_VALUE | 1 | | 0 (0)| |
| 15 | TABLE ACCESS BY INDEX ROWID| PERSON_PROFILE_NAMES | 805 | 24955 | 253 (0)| 00:00:04 |
|* 16 | INDEX RANGE SCAN | IDX$$_D7D50001 | 805 | | 4 (0)| 00:00:01 |
|* 17 | TABLE ACCESS BY INDEX ROWID | PERSON_PROFILE | 1 | 23 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | XPK_PERSON_PROFILE | 1 | | 1 (0)| 00:00:01 |
|* 19 | TABLE ACCESS BY INDEX ROWID | LEGAL_ENTITY | 1 | 27 | 2 (0)| 00:00:01 |
|* 20 | INDEX UNIQUE SCAN | XPK_LEGAL_ENTITY | 1 | | 1 (0)| 00:00:01 |
|* 21 | TABLE ACCESS BY INDEX ROWID | LEGAL_ENTITY_ADDRESSES | 1 | 81 | 3 (0)| 00:00:01 |
|* 22 | INDEX RANGE SCAN | LENUM_CODE_ID | 1 | | 2 (0)| 00:00:01 |
|* 23 | TABLE ACCESS BY INDEX ROWID | LEGAL_ENTITY_IDENTIFICATIONS | 1 | 36 | 3 (0)| 00:00:01 |
|* 24 | INDEX RANGE SCAN | XIF1_LEGAL_ENTITY_ID | 1 | | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("REFCOUNTIES"."ID"=:B1)
4 - access("REFEYECOLORS"."ID"=:B1)
6 - access("REFGENDER"."ID"=:B1)
7 - filter(ROWNUM<=200)
13 - filter("REFCONTACTDETAILS"."MODE_TYPE"=4)
14 - access("REFCONTACTDETAILS"."VALUE"='PRA')
16 - access("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0)
filter(("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0))
17 - filter("SYS_ALIAS_2"."GENDER_ID"=:2)
18 - access("SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER"="PERSONPROFILENAMES"."PP_LEGALENTITY_NUMBER")
19 - filter(("LEGALENTITY"."IS_DELETED"=0 OR "LEGALENTITY"."IS_DELETED"=NULL))
20 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER")
21 - filter("LEGALENTITYADDRESSES"."IS_DELETED"=0)
22 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="LEGALENTITYADDRESSES"."LEGAL_ENTITY_NUMBER" AND
"REFCONTACTDETAILS"."ID"="LEGALENTITYADDRESSES"."CONTACT_DETAILS_CODE_ID")
23 - filter(("LEGAL_ENTITY_ID"."END_DATE">=SYSDATE@! AND "LEGAL_ENTITY_ID"."EFFECTIVE_DATE"<=SYSDATE@!))
24 - access("LEGAL_ENTITY_ID"."LEGAL_ENTITY_NUMBER"="LEGALENTITY"."LEGAL_ENTITY_NUMBER")
Please advice ....
Thanks
Edited by: Monto on Aug 22, 2012 4:22 AM
Explain Plan with common name.
SELECT customerin0_.ROW_NUMBER AS ROW1_22596_,
customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
customerin0_.addressTypeId AS addressT3_22596_,
customerin0_.city AS city22596_,
customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
customerin0_.county AS county22596_,
customerin0_.countyID AS countyID22596_,
customerin0_.dob AS dob22596_,
customerin0_.eyecolor AS eyecolor22596_,
customerin0_.eyecolorid AS eyecolorid22596_,
customerin0_.FIRST_NAME AS FIRST11_22596_,
customerin0_.gender AS gender22596_,
customerin0_.genderid AS genderid22596_,
customerin0_.ID_NUMBER AS ID14_22596_,
customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
customerin0_.LAST_NAME AS LAST16_22596_,
customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
customerin0_.suffix_value AS suffix22_22596_,
customerin0_.ZIP_CODE AS ZIP23_22596_,
customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
FROM xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
WHERE (customerin0_.LAST_NAME LIKE 'SMITH%')
AND customerin0_.genderid = 2
AND ROWNUM <= 200
call count cpu elapsed disk query current rows
Parse 1 0.04 0.05 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 15 5.05 167.51 14050 20246 0 200
total 17 5.09 167.56 14050 20246 0 200
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Rows Row Source Operation
41 TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=58 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
41 INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=17 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
7 TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=11 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
7 INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
1 TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
1 INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
200 COUNT STOPKEY (cr=20175 pr=14050 pw=0 time=2540633 us)
200 NESTED LOOPS OUTER (cr=20175 pr=14050 pw=0 time=2540633 us cost=103 size=1248 card=6)
200 NESTED LOOPS (cr=19756 pr=13775 pw=0 time=17003952 us cost=80 size=1032 card=6)
200 NESTED LOOPS (cr=19304 pr=13586 pw=0 time=14271285 us cost=55 size=1092 card=12)
200 NESTED LOOPS (cr=19017 pr=13453 pw=0 time=13593988 us cost=31 size=768 card=12)
4923 NESTED LOOPS (cr=4640 pr=4614 pw=0 time=63281900 us cost=7 size=492 card=12)
1 TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
1 INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
4923 TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=4638 pr=4614 pw=0 time=63269280 us cost=6 size=372 card=12)
4923 INDEX RANGE SCAN IDX$$_D7D50001 (cr=30 pr=16 pw=0 time=60326 us cost=2 size=0 card=12)(object id 311149)
200 TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=14377 pr=8839 pw=0 time=0 us cost=2 size=23 card=1)
4923 INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=9454 pr=4288 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
200 TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=287 pr=133 pw=0 time=0 us cost=2 size=27 card=1)
200 INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=225 pr=80 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
200 TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=452 pr=189 pw=0 time=0 us cost=3 size=81 card=1)
200 INDEX RANGE SCAN LENUM_CODE_ID (cr=281 pr=94 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
200 TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=419 pr=275 pw=0 time=0 us cost=4 size=36 card=1)
200 INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=219 pr=77 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
ges message buffer allocation 8576 0.00 0.02
library cache lock 7 0.00 0.00
library cache pin 7 0.00 0.00
SQL*Net message to client 15 0.00 0.00
Disk file operations I/O 19 0.01 0.03
gc cr grant 2-way 8554 0.01 3.09
db file sequential read 14050 0.91 158.32
SQL*Net message from client 15 32.28 35.97
gc cr grant congested 8 0.00 0.01
********************************************************************************Plan with rare names.
SELECT customerin0_.ROW_NUMBER AS ROW1_22596_,
customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
customerin0_.addressTypeId AS addressT3_22596_,
customerin0_.city AS city22596_,
customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
customerin0_.county AS county22596_,
customerin0_.countyID AS countyID22596_,
customerin0_.dob AS dob22596_,
customerin0_.eyecolor AS eyecolor22596_,
customerin0_.eyecolorid AS eyecolorid22596_,
customerin0_.FIRST_NAME AS FIRST11_22596_,
customerin0_.gender AS gender22596_,
customerin0_.genderid AS genderid22596_,
customerin0_.ID_NUMBER AS ID14_22596_,
customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
customerin0_.LAST_NAME AS LAST16_22596_,
customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
customerin0_.suffix_value AS suffix22_22596_,
customerin0_.ZIP_CODE AS ZIP23_22596_,
customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
FROM xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
WHERE (customerin0_.LAST_NAME LIKE 'KUMAR%')
AND customerin0_.genderid = '2'
AND ROWNUM <= 200
call count cpu elapsed disk query current rows
Parse 1 0.05 0.07 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 15 0.02 0.03 0 1829 0 200
total 17 0.07 0.10 0 1829 0 200
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Rows Row Source Operation
23 TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=37 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
23 INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=14 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
5 TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=9 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
5 INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
1 TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
1 INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
200 COUNT STOPKEY (cr=1781 pr=0 pw=0 time=15124 us)
200 NESTED LOOPS OUTER (cr=1781 pr=0 pw=0 time=14726 us cost=103 size=1248 card=6)
200 NESTED LOOPS (cr=1383 pr=0 pw=0 time=35422 us cost=80 size=1032 card=6)
200 NESTED LOOPS (cr=980 pr=0 pw=0 time=20198 us cost=55 size=1092 card=12)
200 NESTED LOOPS (cr=741 pr=0 pw=0 time=15422 us cost=31 size=768 card=12)
289 NESTED LOOPS (cr=129 pr=0 pw=0 time=3648 us cost=7 size=492 card=12)
1 TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
1 INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
289 TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=127 pr=0 pw=0 time=3360 us cost=6 size=372 card=12)
289 INDEX RANGE SCAN IDX$$_D7D50001 (cr=18 pr=0 pw=0 time=672 us cost=2 size=0 card=12)(object id 311149)
200 TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=612 pr=0 pw=0 time=0 us cost=2 size=23 card=1)
289 INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=323 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
200 TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=239 pr=0 pw=0 time=0 us cost=2 size=27 card=1)
200 INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=194 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
200 TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=403 pr=0 pw=0 time=0 us cost=3 size=81 card=1)
200 INDEX RANGE SCAN LENUM_CODE_ID (cr=230 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
200 TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=398 pr=0 pw=0 time=0 us cost=4 size=36 card=1)
200 INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=198 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
ges message buffer allocation 14 0.00 0.00
library cache lock 7 0.00 0.00
library cache pin 7 0.00 0.00
KJC: Wait for msg sends to complete 2 0.00 0.00
SQL*Net message to client 15 0.00 0.00
SQL*Net message from client 15 18.88 21.81
********************************************************************************PERSONPROFILENAMES-16 Milion rows
LEGALENTITYADDRESSES-34 Milion rows
PERSONPROFILE-16 Milion rows
LEGALENTITY 17 Milion rows
refcontactdetails 45 rows
Thanks
Similar Messages
-
Query Tuning! - Need your help
Hi Guys,
I have got a problem in Query Tuning.
I have a query, in which I am accesing tables from different users. Example:
2 tables are from my own schema, 3 tables from other users and 3 tables from yet another user.
I am using DISTINCT on this select statement. The 1st two columns in teh select list are concatenated with each other.
There is yet another select in the from clause to get few other records from other tables.
Thee query returns 163 records and takes around 14 seconds.
I referred PLAN_TABLE, its showing NESTED LOOPS and CARTESIAN JOIN in the SORT OPERATION.
Can anyone of you please suggest areas where I can concentrate?
Thanks in advance
Himanshu DabirDISTINCT always do an inherent sort.
SQL> EXPLAIN PLAN FOR
2 SELECT DISTINCT principal_due,outstand_balance
3 FROM outstanding_ledger
4 WHERE dnum=1030003931
5 /
Explained.
SQL> SET LINE 200
SQL> SELECT * FROM TABLE(dbms_xplan.display)
2 /
PLAN_TABLE_OUTPUT
Plan hash value: 1765098853
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 17 | 272 | 1 (100)| 00:00:01 |
| 1 | SORT UNIQUE | | 17 | 272 | 1 (100)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| OUTSTANDING_LEDGER | 17 | 272 | | |
|* 3 | INDEX SKIP SCAN | DLINE_COM_DDATE_DNUM_PK | 17 | | | |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - access("DNUM"=1030003931)
filter("DNUM"=1030003931)
16 rows selected.
SQL> DELETE plan_table
2 /
4 rows deleted.
SQL> commit
2 /
Commit complete.
SQL> EXPLAIN PLAN FOR
2 SELECT principal_due,outstand_balance
3 FROM outstanding_ledger
4 WHERE dnum=1030003931
5 /
Explained.
SQL> SELECT * FROM TABLE(dbms_xplan.display)
2 /
PLAN_TABLE_OUTPUT
Plan hash value: 3157896501
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 17 | 272 | 0 (0)|
| 1 | TABLE ACCESS BY INDEX ROWID| OUTSTANDING_LEDGER | 17 | 272 | |
|* 2 | INDEX SKIP SCAN | DLINE_COM_DDATE_DNUM_PK | 17 | | |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
2 - access("DNUM"=1030003931)
filter("DNUM"=1030003931)
15 rows selected.
SQL>
Can anyone of you please suggest areas where I can concentrate?Paste yours plan with updated stats.
Khurram -
Performance issue on query. Help needed.
This is mainly a performance issue. I hope someone can help me on this.
Basically I have four tables Master (150000 records), Child1 (100000+ records), Child2 (50 million records !), Child 3 (10000+ records)
(please pardon the aliases).
Now every record in master has more than one corresponding record in each of the child tables (one to many).
Also there may not be any record in any or all of the tables for a particular master record.
Now, I need to fetch the max of last_updated_date for every master record in each of the 3 child tables and then find the maximum of
the three last_active_dates obtained from the 3 tables.
eg: for Master ID 100, I need to query Child1 for all the records of Master ID 100 and get the max last_updated_date.
Same for the other 2 tables and then get the maximum of these three values.
(I also need to take care of cases where no record may be found in a child table for a Master ID)
Writing a procedure that uses cursors that fetches the value from each of the child table hits performance
badly. And thing is I need to find out the last_updated_date for every Master record (all 150000 of them). It'll probably take days to do this.
SELECT MAX (C1.LAST_UPDATED_DATE)
,MAX (C2.LAST_UPDATED_DATE)
,MAX (C3.LAST_UPDATED_DATE)
FROM CHILD1 C1
,CHILD2 C2
,CHILD3 C3
WHERE C1.MASTER_ID = 100
OR C2.MASTER_ID = 100
OR C3.MASTER_ID = 100
I tried the above but I got a temp tablespace error. I don't think the query is good enough at all.
(The OR clause is to take care of no records in any child table. If there's an AND, then the join and hence select will
fail even if there is no record in one child table but valid values in the other 2 tables).
Thanks a lot.
Edited by: user773489 on Dec 16, 2008 11:49 AMNot sure I understand the problem. The max you are getting from the above is already the greatest out of the three - that's why we do the UNION ALL.
Here's sample code without output, maybe this will clear it up:
with a as (
select 10 MASTER_ID, to_date('12/15/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 20 MASTER_ID, to_date('12/01/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 30 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual
b as (
select 10 MASTER_ID, to_date('12/14/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 20 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 40 MASTER_ID, to_date('11/15/2008', 'MM/DD/YYYY') LAST_DTE from dual
c as (
select 10 MASTER_ID, to_date('12/07/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 30 MASTER_ID, to_date('11/29/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 40 MASTER_ID, to_date('12/13/2008', 'MM/DD/YYYY') LAST_DTE from dual
select MASTER_ID, MAX(LAST_DTE)
FROM
(select MASTER_ID, LAST_DTE from a UNION ALL
select MASTER_ID, LAST_DTE from b UNION ALL
select MASTER_ID, LAST_DTE from c)
group by MASTER_ID;
MASTER_ID MAX(LAST_DTE)
30 02-DEC-08
40 13-DEC-08
20 02-DEC-08
10 15-DEC-08
4 rows selectedEdited by: tk-7381344 on Dec 16, 2008 12:38 PM -
I ran the below query two times . first this query run within 4 minutes now it is running withing 20 minutes only . and how can I reduce the running time of this query.
my first table TABLE1 has partitioned day wise.
Total 14 partition in TABLE1 so if it runs for total 14 partitions it will take 14*20= 280 minutes.
Index created for TABLE1 and TABLE2
CREATE INDEX TABLE1_COL_A_INX ON TABLE1(COL_A);
CREATE INDEX TABLE1_COL_B_INX ON TABLE1(COL_B);
CREATE INDEX TABLE2_BNO_TYP_INX ON TABLE2(COL_B,RECORD_TYP);TABLE1 contain 3 billion records
TABLE2 contain 87 thousand records
INSERT INTO TARGET_TABLE
SELECT t1.col_A,
t1.col_b,
t1.record_typ,
TO_date('14/06/2012','DD/MM/YYYY') ,
MIN( start_dt) AS First_Seen,
MAX( start_dt) AS Last_Seen
FROM TABLE1 t1,
TABLE2 t2
WHERE t1.start_dt = TO_date('14/06/2012','DD/MM/YYYY') - 12
AND t1.col_b = t2.col_b
AND t1.record_typ = t2.record_typ
GROUP BY t1.col_a,t1.col_b,t1.record_typ,TO_date('14/06/2012','DD/MM/YYYY') ;Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Explain plan with statistics
SQL>
117794 rows selected.
Execution Plan
Plan hash value: 1844245574
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 147K| 7362K| | 615K (1)| 02:03:05 | | |
| 1 | HASH GROUP BY | | 147K| 7362K| 9320K| 615K (1)| 02:03:05 | | |
| 2 | NESTED LOOPS | | | | | | | | |
| 3 | NESTED LOOPS | | 147K| 7362K| | 613K (1)| 02:02:43 | | |
| 4 | TABLE ACCESS FULL | TABEL2 | 87586 | 1282K| | 137 (1)| 00:00:02 | | |
| 5 | PARTITION RANGE SINGLE | | 3 | | | 3 (0)| 00:00:01 | 4 | 4 |
|* 6 | INDEX RANGE SCAN | TABLE1_COL_B_INX | 3 | | | 3 (0)| 00:00:01 | 4 | 4 |
|* 7 | TABLE ACCESS BY LOCAL INDEX ROWID| TABLE1 | 2 | 72 | | 7 (0)| 00:00:01 | 4 | 4 |
Predicate Information (identified by operation id):
6 - access("T1"."COL_B"="T2"."COL_B")
7 - filter("T1"."START_DT"=TO_DATE(' 2012-06-02 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"T1"."RECORD_TYP"="T2"."RECORD_TYP")
Statistics
105 recursive calls
0 db block gets
640720 consistent gets
363307 physical reads
635656 redo size
3896682 bytes sent via SQL*Net to client
86718 bytes received via SQL*Net from client
7854 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
117794 rows processed
SQL>TKPROF
SELECT t1.COL_A,
t1.COL_B,
t1.record_typ,
TO_date('14/06/2012','DD/MM/YYYY') ,
MIN(start_dt) AS First_Seen,
MAX(start_dt) AS Last_Seen
FROM TABLE1 t1,
TABLE2 t2
WHERE t1.start_dt = TO_date('14/06/2012','DD/MM/YYYY') - 12
AND
t1.COL_B = t2.COL_B
AND t1.record_typ = t2.record_typ
GROUP BY t1.col_a,t1.col_b,t1.record_typ,TO_date('14/06/2012','DD/MM/YYYY')
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 7853 0.15 0.28 0 0 0 117793
total 7853 0.15 0.28 0 0 0 117793
Misses in library cache during parse: 0
Parsing user id: 85 Which parameters or settings I want to check , because this query run before 4 minutes. now it takes 20 minutes... or in anyway I can rewrite this query using multiple staging table or something like that...Hi,
1) you didn't trace the session correctly -- you probably switched tracing off before the session finished fetching all rows. Do it again, and this time end tracing by exiting the session (this way you make sure that the cursor is closed and plan stats are dumped to the trace file)
2) the plan seems to be sensible -- it costs you only 600k reads to retrieve 150k rows, that's good read-to-row ratio. You can improve it if you get read of TABLE ACCESS BY ROWID operation, but that would require creating an index on all the columns that the query needs (both in WHERE clause and in column projection) which looks like a big overhead (especially given that this is a table with 3 billion records)
3) autotrace stats seem to agree with the plan -- you're making 600k gets and half of them result in single-block disk reads. Assuming 5ms per read that's close to 20 min that you are getting. Of course, 50% buffer cache ratio is far from being perfect, and better caching is most likely the reason why the query was performing better in the past. Look at the the buffer hit ratio trend for the database -- perhaps some other activity is trashing the buffer cache, resulting in performance degradation of this query as well
Best regards,
Nikolay -
SQL query urgent helps needed!!!
Hi all,
I got the following query :-
SELECT RH.REQUEST_NUMBER,
MSIK.CONCATENATED_SEGMENTS,
MSIK.DESCRIPTION,
RL.FROM_SUBINVENTORY_CODE,
RL.UOM_CODE,
RL.QUANTITY,
PP.FULL_NAME ,
M.TRANSACTION_QUANTITY
FROM MTL_TXN_REQUEST_HEADERS RH,
MTL_TXN_REQUEST_LINES RL,
MTL_SYSTEM_ITEMS_KFV MSIK,
FND_USER FU,
PER_PEOPLE_V7 PP,
( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE, SUM(MOQ.TRANSACTION_QUANTITY)
FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
AND MSIK2.ORGANIZATION_ID = 8
AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
WHERE
RH.HEADER_STATUS IN(3,7,8)
AND RH.MOVE_ORDER_TYPE IN(1,2)
and rh.header_id = rl.header_id
AND MSIK.INVENTORY_ITEM_ID = RL.INVENTORY_ITEM_ID
AND MSIK.ORGANIZATION_ID = 8
AND RL.FROM_SUBINVENTORY_CODE LIKE 'ST%'
AND RH.CREATED_BY = FU.USER_ID
AND FU.EMPLOYEE_ID = PP.PERSON_ID
However, when I try to run I got the invalid column for m.transaction_quantity ??? why? does it b'cos of the group sum that I used ?
My intention of this query to display the sum of total qty from the mtl_onhand_quantities table.
Please helps.
Thanks.
Rgds
Limsorry if its too late.....
my guess is alias the SUM(MOQ.TRANSACTION_QUANTITY) in the sub-query table (M) as TRANSACTION_QUANTITY.
-------- code snippet---------
FND_USER FU,
PER_PEOPLE_V7 PP,
( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE,
SUM(MOQ.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY <------------------------------------This is important
FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
AND MSIK2.ORGANIZATION_ID = 8
AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
WHERE
RH.HEADER_STATUS IN(3,7,8)
AND RH.MOVE_ORDER_TYPE IN(1,2)
--------------code snippet ends------------------------
hope this helps, -
Query tuning help required:
I have a query which is taking long time. Is there any way I can improve the query to shorten its time of execution.
I have given below the details of it.
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.25
SQL> SELECT pa.regn_no,
2 (SELECT mst.status_desc
3 FROM m_status mst
4 WHERE mst.trans_id = 'PA01'
5 AND mst.status_code = pa.regn_status) AS regn_status,
6 (SELECT pp.NAME
7 FROM people_profile pp
8 WHERE pp.pp_id = pa.ident_no) AS NAME, pa.ident_no,
9 TO_CHAR (pa.approval_date, 'dd/mm/yyyy') AS approval_date,
10 TO_CHAR (pa.de_reg_date, 'dd/mm/yyyy') AS de_regist_date,
11 TO_CHAR (pa.cert_reg_exp_date, 'dd/mm/yyyy') AS cert_expiry_date,
12 pa.gender, pa.fax_no,
13 (SELECT nationality_desc
14 FROM people_profile pp, m_nationality
15 WHERE pp.pp_id = pa.ident_no
16 AND pp.nationality = nationality_code) AS nationality,
17 (SELECT pp.email_add
18 FROM people_profile pp
19 WHERE pp.pp_id = pa.ident_no) AS email_add,
20 (SELECT pp.mobile_no
21 FROM people_profile pp
22 WHERE pp.pp_id = pa.ident_no) AS mobile_no,
23 TO_CHAR ((SELECT pp.birth_date
24 FROM people_profile pp
25 WHERE pp.pp_id = pa.ident_no),
26 'dd/mm/yyyy'
27 ) AS birth_date,
28 REPLACE (sf_get_address_people (pa.ident_no, '2', 'C'),
29 '<br>',
30 CHR (10)
31 ) AS address,
32 sf_get_pa_firm_info (pa.ident_no) AS firm_profile,
33 sf_get_pa_firm_partner (pa.ident_no) AS firm_partner,
34 sf_get_pa_pmp_code (pa.ident_no) AS pmp_code, ppv.pae_name,
35 ppv.pmp_code AS pmp_code_1, ppv.cycle_no, ppv.seq_no,
36 DECODE (ppv.visit_type,
37 'I', 'INITIAL',
38 'R', 'REVISIT',
39 ''
40 ) AS visit_type,
41 TO_CHAR (ppv.initial_ltr_date, 'dd/mm/yyyy') AS initial_ltr_date,
42 TO_CHAR (ppv.sec_ltr_date, 'dd/mm/yyyy') AS sec_ltr_date,
43 TO_CHAR (ppv.review_from, 'dd/mm/yyyy') AS review_from,
44 TO_CHAR (ppv.review_to, 'dd/mm/yyyy') AS review_to,
45 TO_CHAR (ppv.finding_date, 'dd/mm/yyyy') AS finding_date,
46 TO_CHAR (ppv.finding_due_date, 'dd/mm/yyyy') AS finding_due_date,
47 TO_CHAR (ppv.finding_reply_date,
48 'dd/mm/yyyy'
49 ) AS finding_reply_date,
50 ppv.pmsc,
51 TO_CHAR (ppv.clarif_ltr_date, 'dd/mm/yyyy') AS clarif_ltr_date,
52 ppv.paoc_date,
53 TO_CHAR (ppv.final_paoc_date, 'dd/mm/yyyy') AS final_paoc_date,
54 (SELECT result_desc
55 FROM m_pmp_result ms
56 WHERE result_id = ppv.pmp_status) AS pmp_status,
57 TO_CHAR (ppv.suspension_end_date,
58 'dd/mm/yyyy'
59 ) AS suspension_end_date,
60 TO_CHAR (ppv.final_ltr_date, 'dd/mm/yyyy') AS final_ltr_date,
61 ppv.findings_summary,
62 TO_CHAR (ppv.invoice_date, 'dd/mm/yyyy') AS invoice_date,
63 ppv.amount_billed,
64 TO_CHAR (ppv.payment_date, 'dd/mm/yyyy') AS payment_date,
65 DECODE (ppv.pay_icpas,
66 'Y', 'YES',
67 'N', 'NO',
68 'V', 'NA',
69 ''
70 ) AS pay_icpas,
71 ppv.updated_date, ppv.updated_by, ppv.remarks,
72 DECODE ((SELECT ppr.review_status
73 FROM pa_pmp_reviews ppr
74 WHERE ppr.regn_no = ppv.regn_no
75 AND ppr.cycle_no = ppv.cycle_no),
76 'P', 'In Progress',
77 'C', 'Closed',
78 ''
79 ) AS review_status,
80 pcl.complaint_no,
81 DECODE (pcl.complaint_status,
82 'P', 'Pending',
83 'C', 'Closed',
84 ''
85 ) AS complaint_status,
86 pcl.remarks AS remarks_1,
87 DECODE (pcl.complaint_outcome,
88 'C', 'Cancelled',
89 'R', 'Restriction of Practice',
90 'P', 'Penalty (Fine) - Disciplinary',
91 'E', 'Censure - Disciplinary',
92 'S', 'Suspended - Disciplinary',
93 ''
94 ) AS complaint_outcome,
95 TO_CHAR (pcl.complaint_date, 'dd/mm/yyyy') AS complaint_date,
96 pcl.complainant_nric, pcl.complainant_name, pcl.complaint_details,
97 TO_CHAR (pcl.effective_date, 'dd/mm/yyyy') AS effective_date,
98 TO_CHAR (pcl.effective_date_to,
99 'dd/mm/yyyy') AS effective_date_to,
100 sf_get_pa_exam_info (pa.regn_no, 'L') AS local_exam_detail,
101 sf_get_pa_exam_info (pa.regn_no, 'F') AS foreign_exam_detail,
102 sf_get_pa_exempt_info (pa.regn_no) AS exempt_detail
103 FROM pa_profile pa, pa_pmp_visits ppv, pa_complaint pcl
104 WHERE pa.regn_no = ppv.regn_no(+) AND pa.regn_no = pcl.regn_no(+)
105 ORDER BY pa.regn_no DESC;
1163 rows selected.
Elapsed: 00:02:08.87
Execution Plan
Plan hash value: 2912197266
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1109 | 330K| 17 (12)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | M_STATUS | 1 | 23 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | PK_M_STATUS | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 25 | 3 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C00103408 | 1 | | 2 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 1 | 26 | 4 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID| PEOPLE_PROFILE | 1 | 12 | 3 (0)| 00:00:01 |
|* 7 | INDEX UNIQUE SCAN | SYS_C00103408 | 1 | | 2 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | PK_M_NATIONALITY | 1 | 14 | 1 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 20 | 3 (0)| 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | SYS_C00103408 | 1 | | 2 (0)| 00:00:01 |
| 11 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 11 | 3 (0)| 00:00:01 |
|* 12 | INDEX UNIQUE SCAN | SYS_C00103408 | 1 | | 2 (0)| 00:00:01 |
| 13 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 10 | 3 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | SYS_C00103408 | 1 | | 2 (0)| 00:00:01 |
| 15 | TABLE ACCESS BY INDEX ROWID | M_PMP_RESULT | 1 | 37 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | XPK_M_PMP_RESULT | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PA_PMP_REVIEWS | 1 | 8 | 1 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C00103321 | 1 | | 0 (0)| 00:00:01 |
| 19 | SORT ORDER BY | | 1109 | 330K| 17 (12)| 00:00:01 |
|* 20 | HASH JOIN RIGHT OUTER | | 1109 | 330K| 16 (7)| 00:00:01 |
| 21 | TABLE ACCESS FULL | PA_COMPLAINT | 146 | 20294 | 3 (0)| 00:00:01 |
|* 22 | HASH JOIN RIGHT OUTER | | 1109 | 179K| 13 (8)| 00:00:01 |
| 23 | TABLE ACCESS FULL | PA_PMP_VISITS | 90 | 11340 | 3 (0)| 00:00:01 |
| 24 | TABLE ACCESS FULL | PA_PROFILE | 1109 | 44360 | 9 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("MST"."TRANS_ID"='PA01' AND "MST"."STATUS_CODE"=:B1)
filter("MST"."STATUS_CODE"=:B1)
4 - access("PP"."PP_ID"=:B1)
7 - access("PP"."PP_ID"=:B1)
8 - access("PP"."NATIONALITY"="NATIONALITY_CODE")
10 - access("PP"."PP_ID"=:B1)
12 - access("PP"."PP_ID"=:B1)
14 - access("PP"."PP_ID"=:B1)
16 - access("RESULT_ID"=:B1)
18 - access("PPR"."REGN_NO"=:B1 AND "PPR"."CYCLE_NO"=:B2)
20 - access("PA"."REGN_NO"="PCL"."REGN_NO"(+))
22 - access("PA"."REGN_NO"="PPV"."REGN_NO"(+))
Statistics
17577 recursive calls
0 db block gets
8703644 consistent gets
6138 physical reads
0 redo size
424453 bytes sent via SQL*Net to client
3641 bytes received via SQL*Net from client
13 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1163 rows processed
NAME TYPE VALUE
user_dump_dest string /opt/app/oracle/diag/rdbms/ebi
zfile/EBIZFILE/trace
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 128
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname, pname, pval1, pval2
3 from
4 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 11-20-2009 09:46
SYSSTATS_INFO DSTOP 11-20-2009 09:46
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 1676.76768
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHRHi,
obviously the problem you are having is described by the following lines of your execution plan
SORT ORDER BY | | 1109 | 330K| 17 (12)| 00:00:01 |
|* 20 | HASH JOIN RIGHT OUTER | | 1109 | 330K| 16 (7)| 00:00:01 |
| 21 | TABLE ACCESS FULL | PA_COMPLAINT | 146 | 20294 | 3 (0)| 00:00:01 |
|* 22 | HASH JOIN RIGHT OUTER | | 1109 | 179K| 13 (8)| 00:00:01 |
| 23 | TABLE ACCESS FULL | PA_PMP_VISITS | 90 | 11340 | 3 (0)| 00:00:01 |
| 24 | TABLE ACCESS FULL | PA_PROFILE | 1109 | 44360 | 9
You don't have a "real" "WHERE" condition in the query that could lead the Oracle CBO to consider using an index.
This leads to a full scan of PA_PMP_VISITS and PA_PROFILE and subsequently -in order to process the join condition between these two tables-
to this "HASH JOIN RIGHT OUTER". You cannot avoid this, with the current WHERE condition ...
Following thoughts :
1) Try narrowing down your result set by specifying a "real" WHERE Condition on one of the two tables, specifying an indexed column
2) If this cannot be done, try using query parallelism (parallel hint). This will give you acceptable SQL-execution times.
3) If this is not possible, there would be a third approach : You could consider the definition of an index on "pa.regn" and use a hint on your query in order to use it. Due to your order condition there is a possibility that CBO is going to use it, especially if you specify WHERE ROWNUM < ...
Regards,
Michalis -
In car calls query. Help needed
I'm doing this on behalf of my flat mate who has a Curve 8520. I've just brought her a 3.5mm jack cable to link her phone to her headunit to play her tunes and it worked perfectly. While we were sorted this out we wondered how easy it was to use her new setup up as an in-car call kit. We called her phone to see what would happen and to see if the call would automatically use the car speakers for the call instead of the phone. Unfortunately the call came through the phone and not the speakers. We then went to turn on the speakerphone but as you can imagine isn't really the method we wanted to employ. Does anyone know of any setting on the phone so that the calls can come straight through speakers or any cheap products that would allow her to do this?
Any help would be gratefully recievedI'm doing this on behalf of my flat mate who has a Curve 8520. I've just brought her a 3.5mm jack cable to link her phone to her headunit to play her tunes and it worked perfectly. While we were sorted this out we wondered how easy it was to use her new setup up as an in-car call kit. We called her phone to see what would happen and to see if the call would automatically use the car speakers for the call instead of the phone. Unfortunately the call came through the phone and not the speakers. We then went to turn on the speakerphone but as you can imagine isn't really the method we wanted to employ. Does anyone know of any setting on the phone so that the calls can come straight through speakers or any cheap products that would allow her to do this?
Any help would be gratefully recieved -
hi friends,
Could u please help me how to do this
tables : knb1, "customer master (companycode)
kna1, "genaral data in customer master
knvp. "customer master partener functions
zvarv. "Program Hard Coded Values support table
TYPE-POOLS DEFINATION
type-pools : slis.
TYPES DECLARATION
Customer Master Company code Data
types : begin of t_knb1,
kunnr like knb1-kunnr,
akont like knb1-akont,
end of t_knb1.
data : i_knb1 type t_knb1 occurs 0 with header line .
Customer Master
types : begin of t_kna1,
kunnr like kna1-kunnr,
name1 like kna1-name1,
stras like kna1-stras,
ort01 like kna1-ort01,
stcd1 like kna1-stcd1,
pstlz like kna1-pstlz,
end of t_kna1.
data : i_kna1 type t_kna1 occurs 0 with header line.
Customer Partner Functions
types : begin of t_knvp,
kunnr like knvp-kunnr,
vkorg like knvp-vkorg,
parvw like knvp-parvw,
kunn2 like knvp-kunn2,
end of t_knvp.
data : i_knvp type t_knvp occurs 0 with header line.
Output data
types : begin of t_output,
recordtype type c,
soldtocust(10) type c,
payer(10) type c,
sequence(5) type n,
custname(35) type c,
custaddress(35) type c,
custcity(35) type c,
taxid(16) type c,
postalcode(5) type c,
branch type c,
delivery(3) type c,
end of t_output.
data : i_output type t_output occurs 0 with header line.
ZVARV Table
*types : begin of t_zvarv,
zobject1 like zvarv-zobject1,
zobject2 like zvarv-zobject2,
zseqnumb like zvarv-zseqnumb,
zobjval like zvarv-zobjval,
end of t_zvarv.
*data : i_zvarv type t_zvarv occurs 0 with header line.
Error messages and total records
types : begin of t_error_log,
message(200) type c,
end of t_error_log.
data : i_error_log type t_error_log occurs 0 with header line.
Field catalog
data : t_fieldcat_tab type slis_t_fieldcat_alv with header line.
Variables
data : "v_aufsd like i_zvarv-zobjval, "Central order block for cust
v_knb1 type t_knb1, "Customer master company code
v_kna1 type t_kna1, "Customer master
v_knvp type t_knvp, "Customer masterpartenerfunctions
v_output type t_output, "Output data
v_error_log type t_error_log, "Error data
v_sequence(5) type n, "Total records
v_line type i, "Message
v_count type i, "Counter for KNA1 records
v_count1 type i, "Counter for KNVP records
v_result(100) type c, "Totals for KNA1
v_result1(100) type c, "Totals for KNVP
v_vkorg like knvp-vkorg. "Message for Validation
Constants
data : c_program(30) type c value 'ZSDI0215', " Program Name
c_parvw_rg like knvp-parvw value 'RG', "Partner type
c_aufsd(2) type c value 'CD'. "Central order block for Cust
Selection-screen
selection-screen begin of block b1 with frame title text-001.
parameters : p_vkorg like knvp-vkorg obligatory. "Sales Org
select-options : s_akont for knb1-akont obligatory default
'0001050100'. "Reconciliation Account
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters : p_alv as checkbox,
p_df as checkbox.
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-003.
parameters : p_lfile like filetextci-fileintern
default 'Z_IO01989_CUSTOMER_MASTER_DATA', " Logical file
p_pfile like rfpdo-rfbifile. " Physical File
selection-screen end of block b3.
At selection-screen
at selection-screen on p_vkorg.
Validation of Sales Organization
select single vkorg
into v_vkorg
from tvko
where vkorg = p_vkorg.
if v_vkorg is initial.
message e045 with text-030.
endif.
Start-of-selection
start-of-selection.
Fetch data
perform get_data.
Processing the data
perform process_data.
End-of-Selection
end-of-selection.
if p_alv eq 'X'.
Field catalog
perform f_prepare_fieldcat.
Disply alv report
perform f_display_report.
Disply error log
perform f_error_log.
elseif p_df eq 'x'.
Disply logical file & physical file
perform f_logical_file.
perform f_physical_file.
else.
Display the list
perform f_list_display.
Disply logical file & physical file
perform f_logical_file.
perform f_physical_file.
endif.
Form get_data
Fetch data and store in internal tables
form get_data .
Get zvarv data.
perform get_zvarv.
Get knb1 data
perform get_knb1.
Get kna1 data
perform get_kna1.
Get knvp data
perform get_knvp.
endform. " get_data
form get_zvarv
zvarv data
form get_zvarv .
Fetch data from zvarv.
select zobject1 zobject2 zseqnumb zobjval
from zvarv
into table i_zvarv
where zobject1 eq c_program.
sort i_zvarv by zobject2.
endform. " get_zvarv
form get_knb1
Get KNB1 data
form get_knb1 .
Fetch data from knb1.
select kunnr akont
from knb1
into table i_knb1
where akont in s_akont.
describe table i_knb1 lines v_line.
endform. " get_knb1
Form get_kna1
Get KNB1 data
form get_kna1 .
Fetch data from kna1.
select kunnr name1 stras ort01 stcd1 pstlz
from kna1
into table i_kna1
for all entries in i_knb1
where kunnr = i_knb1-kunnr and
aufsd ne 'cd'."v_aufsd.
endform. " get_kna1
Form get_knvp
Get KNVP data
form get_knvp .
Fetch data from knvp
select kunnr parvw kunn2 vkorg
from knvp
into table i_knvp
for all entries in i_knb1
where kunnr = i_knb1-kunnr
and vkorg = p_vkorg
and parvw = c_parvw_rg.
endform. " get_knvp
Form process_data
Processing output data
form process_data .
Get AUFSD value from ZVARV
perform zvarv_read.
loop at i_knb1.
read table i_kna1 with key kunnr = i_knb1-kunnr.
if sy-subrc ne 0.
concatenate: 'in kna1 no record found for Customer number'
i_knb1-kunnr
into v_result separated by space.
move v_result to v_error_log-message.
append v_error_log to i_error_log.
v_count = v_count + 1.
else.
move : i_kna1-name1 to i_output-custname,
i_kna1-stras to i_output-custaddress,
i_kna1-ort01 to i_output-custcity,
i_kna1-stcd1 to i_output-taxid,
i_kna1-pstlz to i_output-postalcode.
append i_output
endif.
loop at i_knvp where kunnr eq knb1-kunnr.
read table i_knvp with key kunnr = i_knb1-kunnr.
if sy-subrc <> 0.
concatenate : 'in knvp no record found for customer number'
v_knb1-kunnr
into v_result1 separated by space.
move v_result1 to v_error_log-message.
append v_error_log to i_error_log.
v_count1 = v_count1 + 1.
else.
Move the knvp data to output
move : i_knvp-kunnr to i_output-soldtocust,
i_knvp-kunn2 to i_output-payer.
append i_output
endif.
endloop.
v_sequence = v_sequence + 1.
Move non table related data to output
move : 'C' to i_output-recordtype,
v_sequence to i_output-sequence,
'1' to i_output-branch,
'ABC' to i_output-delivery.
append i_output.
endif.
endloop.
when i execute this one same data is displaying two times
for example total records is two
first record displaying two times and second one is displaying two times
please tell me how to do
regards
harshaviHi ,
first check all APPEND stmts ?. In any report u have to maintain one BASE internal table .
If u are working on KUNNR level , So maintain one final Internal table with all KUNNRS then Process all the data for final output.
regards
prabhu -
Hierarchical Query Sort help needed in 9i (9.2.0.6)
Hello all, hope you guys are far away from IKE (it hit us pretty bad last weekend), anyway come to point
My requirement is data sorted by name is such a way after parent show its childs (if exists) i.e first sort parents and then by childs within parants
I am expecting this
1 BBQU-1
2 BBQU-1 Sub event 1
3 BBQU-1 Sub event 2
10 BBQU-1 Sub event 3
6 BBQU-1 Birthday
5 BBQU-1 Advance
7 BBQU-2
4 BBQU-2 Sub event
from
1 BBQU-1
5 BBQU-1 Advance
2 BBQU-1 Sub event 1 1
3 BBQU-1 Sub event 2 1
10 BBQU-1 Sub event 3 1
6 BBQU-1 Birthday
7 BBQU-2
4 BBQU-2 Sub event 7
Here is the script for table and data.
create table no_more_ike (event_id number, event_name varchar2(30), subevent_id number);
insert into no_more_ike values (1, 'BBQU-1', null);
insert into no_more_ike values (5, 'BBQU-1 Advance', null);
insert into no_more_ike values (2, 'BBQU-1 Sub event 1', 1);
insert into no_more_ike values (3, 'BBQU-1 Sub event 2', 1);
insert into no_more_ike values (10, 'BBQU-1 Sub event 3', 1);
insert into no_more_ike values (6, 'BBQU-1 Birthday', null);
insert into no_more_ike values (7, 'BBQU-2', null);
insert into no_more_ike values (4, 'BBQU-2 Sub event', 7);
commit;
Thanks a lotIs this OK?
select
event_id,
event_name,
subevent_id
from no_more_ike
start with SUBEVENT_ID is null
connect by prior EVENT_ID = SUBEVENT_ID
order by decode(subevent_id, null, event_id, subevent_id) asc; -
help needed for writing query
i have the following tables(with data) as mentioned below
FK*-foregin key (SUBJECTS)
FK**-foregin key (COMBINATION)
1)SUBJECTS(table name)
SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
2 02 Computer Science
3 03 Physics
4 04 Chemistry
5 05 Mathematics
7 07 Commerce
8 08 Computer Applications
9 09 Biology
2)COMBINATION
COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
383 S1 9 4 2 3
384 S2 4 2 5 3
---------I actually designed the ABOVE table also like this
3) a)COMBINATION
COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
383 S1
384 S2
b)COMBINATION_DET
COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
1 383 9
2 383 4
3 383 2
4 383 3
5 384 4
6 384 2
7 384 5
8 384 3
Business rule: a combination consists of a maximum of 4 subjects (must contain)
and the user is less relevant to a COMB_NAME(name of combinations) but user need
the subjects contained in combinations
i need the following output
COMB_ID COMB_NAME SUBJECT1 SUBJECT2 SUBJECT3 SUBJECT4
383 S1 Biology Chemistry Computer Science Physics
384 S2 Chemistry Computer Science Mathematics Physics
or even this is enough(what i actually needed)
COMB_ID subjects
383 Biology,Chemistry,Computer Science,Physics
384 Chemistry,Computer Science,Mathematics,Physics
you can use any of the COMBINATION table(either (2) or (3))
and i want to know
1)which design is good in this case
(i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
good method to link with same table but if 4 subjects only(and must) comes
detail table is not neccessary )
now i am achieving the result by program-coding in C# after getting the rows from oracle
i am using oracle 9i (also ODP.NET)
i want to know how can i get the result in the stored procedure itsef.
2)how it could be designed in any other way.
any help/suggestion is welcome
thanks for your time --PradeeshWell I forgot the table-alias, here now with:
SELECT C.COMB_ID
, C.COMB_NAME
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
FROM COMBINATION C;
As you need exactly 4 subjects, the columns-solution is just fine I would say. -
hello all
my one of query is returning result in 1-2 mins only for 1 lakh record but i am not sure if it showed me complete rows or not because when I an trying to get count of result ..its taking lot of time .when I am using this query on plsql code ..code is running slow so just wanted to confirm on query tuning point of view if its fine or not ..please look onto it and let me know if query is fine or not by explain plan .my oracle version is 11g
this is my query
SELECT ROWNUM , TRUNC(rownum/5000) + 20000 ,'FOR_UPDATE', sku_org.NAME ,
acct_promo_sku.src_num , acct_promo_sku.sub_type ,
promo_actual.sku_actual_pos
FROM siebel.s_src acct_promo_hdr,
siebel.s_src acct_title_format,
siebel.s_src acct_promo_sku,
siebel.s_src_x acct_promo_hdrx,
siebel.s_src_x acct_promo_skux,
siebel.s_prod_int prod,
siebel.s_bu promo_hdr_org,
siebel.s_bu sku_org,
siebelwb.stg_sbl_acct_promo_actuals2 promo_actual
WHERE acct_promo_hdr.sub_type = 'PLAN_ACCOUNT_PROMOTION'
AND acct_promo_hdr.row_id = acct_title_format.par_src_id
AND acct_title_format.sub_type = 'PLAN_ACCT_PROMOTION_CATEGORY'
AND acct_title_format.row_id = acct_promo_sku.par_src_id
AND acct_promo_sku.sub_type = 'PLAN_ACCOUNT_PROMOTION_PRODUCT'
AND acct_promo_hdr.row_id = acct_promo_hdrx.par_row_id
AND acct_promo_sku.row_id = acct_promo_skux.par_row_id(+)
AND acct_promo_sku.prod_id = prod.row_id
AND acct_promo_hdr.bu_id = promo_hdr_org.row_id
AND acct_promo_sku.bu_id = sku_org.row_id
AND prod.x_prod_material_num = promo_actual.material_number
and prod.X_PROD_SALES_ORG=promo_actual.sales_org
AND acct_promo_hdr.row_id = promo_actual.acct_promo_id
and nvl(acct_promo_hdr.pr_accnt_id,0)=nvl(promo_actual.acct_siebel_rowid,0)
and nvl(acct_promo_hdr.x_indirect_id,0)=nvl(promo_actual.indirect_acct_siebel_rowid,0)
AND promo_actual.load_date >= TRUNC(SYSDATE)
AND promo_actual.load_date < TRUNC(SYSDATE + 1)
explain plan
PLAN_TABLE_OUTPUT
Plan hash value: 3864590768
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 298 | 2300 (1)| 00:00:28 |
| 1 | COUNT | | | | | |
|* 2 | FILTER | | | | | |
| 3 | NESTED LOOPS | | | | | |
| 4 | NESTED LOOPS | | 1 | 298 | 2300 (1)| 00:00:28 |
| 5 | NESTED LOOPS OUTER | | 1 | 273 | 2298 (1)| 00:00:28 |
| 6 | NESTED LOOPS | | 1 | 263 | 2296 (1)| 00:00:28 |
| 7 | NESTED LOOPS | | 1 | 236 | 2295 (1)| 00:00:28 |
| 8 | NESTED LOOPS | | 1 | 165 | 2292 (1)| 00:00:28 |
| 9 | NESTED LOOPS | | 1 | 117 | 2289 (1)| 00:00:28 |
| 10 | NESTED LOOPS | | 1 | 109 | 2289 (1)| 00:00:28 |
| 11 | NESTED LOOPS | | 1 | 99 | 2287 (1)| 00:00:28 |
|* 12 | TABLE ACCESS FULL | STG_SBL_ACCT_PROMO_ACTUALS2 | 1 | 49 | 2285 (1)| 00:0
|* 13 | TABLE ACCESS BY INDEX ROWID| S_SRC | 1 | 50 | 2 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | S_SRC_P1 | 1 | | 1 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | S_SRC_X_U1 | 1 | 10 | 2 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | S_BU_P1 | 1 | 8 | 0 (0)| 00:00:01 |
|* 17 | TABLE ACCESS BY INDEX ROWID | S_SRC | 1 | 48 | 3 (0)| 00:00:01 |
|* 18 | INDEX RANGE SCAN | S_SRC_F2 | 2 | | 2 (0)| 00:00:01 |
|* 19 | TABLE ACCESS BY INDEX ROWID | S_SRC | 1 | 71 | 3 (0)| 00:00:01 |
|* 20 | INDEX RANGE SCAN | S_SRC_F2 | 2 | | 2 (0)| 00:00:01 |
| 21 | TABLE ACCESS BY INDEX ROWID | S_BU | 1 | 27 | 1 (0)| 00:00:01 |
|* 22 | INDEX UNIQUE SCAN | S_BU_P1 | 1 | | 0 (0)| 00:00:01 |
|* 23 | INDEX RANGE SCAN | S_SRC_X_U1 | 1 | 10 | 2 (0)| 00:00:01 |
|* 24 | INDEX UNIQUE SCAN | S_PROD_INT_P1 | 1 | | 1 (0)| 00:00:01 |
|* 25 | TABLE ACCESS BY INDEX ROWID | S_PROD_INT | 1 | 25 | 2 (0)| 00:00:
Predicate Information (identified by operation id):
2 - filter(TRUNC(SYSDATE@!)<TRUNC(SYSDATE@!+1))
12 - filter("PROMO_ACTUAL"."LOAD_DATE">=TRUNC(SYSDATE@!) AND "PROMO_ACTUAL"."LOAD_DATE"<TRUNC(SYSD
13 - filter("ACCT_PROMO_HDR"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION' AND
NVL("ACCT_PROMO_HDR"."PR_ACCNT_ID",'0')=NVL("PROMO_ACTUAL"."ACCT_SIEBEL_ROWID",'0') AND
NVL("ACCT_PROMO_HDR"."X_INDIRECT_ID",'0')=NVL("PROMO_ACTUAL"."INDIRECT_ACCT_SIEBEL_ROWID",'0'
14 - access("ACCT_PROMO_HDR"."ROW_ID"="PROMO_ACTUAL"."ACCT_PROMO_ID")
15 - access("ACCT_PROMO_HDR"."ROW_ID"="ACCT_PROMO_HDRX"."PAR_ROW_ID")
16 - access("ACCT_PROMO_HDR"."BU_ID"="PROMO_HDR_ORG"."ROW_ID")
17 - filter("ACCT_TITLE_FORMAT"."SUB_TYPE"='PLAN_ACCT_PROMOTION_CATEGORY')
18 - access("ACCT_PROMO_HDR"."ROW_ID"="ACCT_TITLE_FORMAT"."PAR_SRC_ID")
19 - filter("ACCT_PROMO_SKU"."PROD_ID" IS NOT NULL AND
"ACCT_PROMO_SKU"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION_PRODUCT')
20 - access("ACCT_TITLE_FORMAT"."ROW_ID"="ACCT_PROMO_SKU"."PAR_SRC_ID")
22 - access("ACCT_PROMO_SKU"."BU_ID"="SKU_ORG"."ROW_ID")
23 - access("ACCT_PROMO_SKU"."ROW_ID"="ACCT_PROMO_SKUX"."PAR_ROW_ID"(+))
24 - access("ACCT_PROMO_SKU"."PROD_ID"="PROD"."ROW_ID")
25 - filter("PROD"."X_PROD_MATERIAL_NUM" IS NOT NULL AND
"PROD"."X_PROD_MATERIAL_NUM"="PROMO_ACTUAL"."MATERIAL_NUMBER" AND
"PROD"."X_PROD_SALES_ORG"="PROMO_ACTUAL"."SALES_ORG")
55 rows selected.
thanksHi,
the plan you posted has the cost of 2300, i.e. 2300 single-block reads or equivalent number f multi-block reads. Even if none of the blocks is found in cache, 2300 reas shouldn't take more than a couple of minutes, beacause for most of the hard drives available today a disk read is typically within 5-10 ms.
This means that if there is a problem, we will never find out about it by looking in the plan. And it's quite likely that there is, in fact, a problem, because the plan contains a bunch of nested joins, and the cost of each nested join is directly proportional to the cardinality of the previous nested loop. I.e. it suffices to make one bad mistake in estimating the number of rows coming fom one of the nested rows to screw up the entire plan and get all remaining estimates (including the total cost of the query) completely wrong.
In order for us to be able to tell more, we need to see the plan with rowsource statistics, and please don't forget to use tags to preserve formatting (use the preview tab to make sure the posted plan is actually readable).
Best regards,
Nikolay -
Help needed to optimize the query
Help needed to optimize the query:
The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
This is having high cost and taking around 15mins to execute.
Can anyone help to fine-tune this??
SELECT c.H_SEC,
c.S_PAID,
c.H_PAID,
table_c.EFF_DATE
FROM MTCH_TBL c
LEFT OUTER JOIN
(SELECT b.SEC_ALIAS,
b.EFF_DATE,
b.INSTANCE
FROM HIST_TBL b
WHERE b.EFF_DATE =
(SELECT MAX (b2.EFF_DATE)
FROM HIST_TBL b2
WHERE b.SEC_ALIAS = b2.SEC_ALIAS
AND b.INSTANCE =
b2.INSTANCE
AND b2.EFF_DATE >= '01-Jan-2007')
OR b.EFF_DATE IS NULL) table_c
ON table_c.SEC_ALIAS=c.H_SEC
AND table_c.INSTANCE = 100;To start with, I would avoid scanning HIST_TBL twice.
Try this
select c.h_sec
, c.s_paid
, c.h_paid
, table_c.eff_date
from mtch_tbl c
left
join (
select sec_alias
, eff_date
, instance
from (
select sec_alias
, eff_date
, instance
, max(eff_date) over(partition by sec_alias, instance) max_eff_date
from hist_tbl b
where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
or eff_date is null
where eff_date = max_eff_date
or eff_date is null
) table_c
on table_c.sec_alias = c.h_sec
and table_c.instance = 100; -
Urgent Help Needed Union Query
Hello All
I have a complex query (at least i think) which returns result set. Now i want to add to it the records that were not mached by the query i tried
<Query1>
Union all
<Query2> where not in <query1> (hope i am able to express myself)
but it takes a lot of time
is there any way that query1 is refered once or i have to redefine the query
Any Help ??????
Thanks in advanceI think i am unable to clearly express myself
When i try to use outer join error occures end-of-file on communication channel. actualy i have a poorly designed database structure which is not in my control but i am supposed to report on it
<query1>
union all
<Query2> where not in <query1>
i wanted to say query 1 returns a result set and query 2 reurns rows not selected by query 1
any workaround -
This is my first post in this forum regarding query tuning, so my sincere apologies in advance if I have:
1) not included sufficient information,
2) included too much information,
3) not posted to the correct forum
I read through Randolf Geist's web page on instructions to post a query tuning request
and attempted to follow it as closely as possible.
I am attempting to figure out where a view I have constructed can be optimized.
It takes approx. 45 seconds to 1 minute to run; I would like to cut that down to 10 seconds if possible.
The view itself is somewhat complex; I will post the actual code if it will help you help me. Please advise.
I was under the impression that posting the code was not necessary, but if it is, let me know and I will post it.
I have been doing SQL development for a few years, but only recently in Oracle.
I have no experience in looking through the following output and being able to tell where I can improve performance,
so this will be a learning experience for me. Thanks in advance for your help - I appreciate it.
Some additional information - my view is based on tables over which I have no control - it is a third-party application
which I do reporting from. I do have the freedom to create indexes on columns within the tables if necessary.
The statement is simply
SELECT * FROM LLU_V_PRODUCTION_DETAIL_03
which is the name of my view.
here's all the information I've been able to retrieve by following Randolf's instructions:
Oracle version is 10.2.0.1.0 - 64bit
Here are optimizer parameters:
NAME TYPE VALUE
user_dump_dest string C:\ORACLE\PRODUCT\10.2.0\ADMIN
\AXIUMPRODUCTION\UDUMP
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.1
optimizer_index_caching integer 90
optimizer_index_cost_adj integer 20
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
NAME TYPE VALUE
db_file_multiblock_read_count integer 16
NAME TYPE VALUE
db_block_size integer 8192
NAME TYPE VALUE
cursor_sharing string EXACT
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 10-29-2005 01:36
SYSSTATS_INFO DSTOP 10-29-2005 01:36
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 1298.56584
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.Here is the output of EXPLAIN PLAN:
PLAN_TABLE_OUTPUT
Plan hash value: 662813077
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 23M| 53G| | 62330 (2)| 00:12:28 |
| 1 | VIEW | LLU_V_PRODUCTION_DETAIL_03 | 23M| 53G| | 62330 (2)| 00:12:28 |
| 2 | UNION-ALL | | | | | | |
|* 3 | HASH JOIN | | 18M| 5062M| | 1525 (10)| 00:00:19 |
| 4 | VIEW | index$_join$_007 | 1725 | 25875 | | 4 (25)| 00:00:01 |
|* 5 | HASH JOIN | | | | | | |
| 6 | INDEX FAST FULL SCAN | USERS_PRIMARY | 1725 | 25875 | | 1 (0)| 00:00:01 |
| 7 | INDEX FAST FULL SCAN | USERS_PRODUCER | 1725 | 25875 | | 2 (0)| 00:00:01 |
|* 8 | HASH JOIN | | 416K| 105M| | 1399 (2)| 00:00:17 |
| 9 | TABLE ACCESS FULL | PRODUCER | 1396 | 118K| | 24 (0)| 00:00:01 |
|* 10 | HASH JOIN | | 29819 | 5183K| | 1372 (2)| 00:00:17 |
| 11 | TABLE ACCESS FULL | CLASS | 20 | 1660 | | 3 (0)| 00:00:01 |
|* 12 | TABLE ACCESS FULL | QR_PRODUCTION | 149K| 13M| | 1367 (2)| 00:00:17 |
|* 13 | FILTER | | | | | | |
|* 14 | HASH JOIN | | 16M| 5651M| | 32983 (2)| 00:06:36 |
| 15 | VIEW | index$_join$_014 | 1725 | 25875 | | 4 (25)| 00:00:01 |
|* 16 | HASH JOIN | | | | | | |
| 17 | INDEX FAST FULL SCAN | USERS_PRIMARY | 1725 | 25875 | | 1 (0)| 00:00:01 |
| 18 | INDEX FAST FULL SCAN | USERS_PRODUCER | 1725 | 25875 | | 2 (0)| 00:00:01 |
|* 19 | HASH JOIN | | 149K| 49M| | 32874 (1)| 00:06:35 |
| 20 | TABLE ACCESS FULL | CLASS | 20 | 1660 | | 3 (0)| 00:00:01 |
|* 21 | HASH JOIN | | 149K| 37M| | 32870 (1)| 00:06:35 |
| 22 | TABLE ACCESS FULL | PRODUCER | 1396 | 118K| | 24 (0)| 00:00:01 |
|* 23 | HASH JOIN | | 222K| 37M| 12M| 32844 (1)| 00:06:35 |
| 24 | TABLE ACCESS FULL | PATIENT | 188K| 10M| | 6979 (1)| 00:01:24 |
|* 25 | HASH JOIN | | 222K| 24M| | 23860 (2)| 00:04:47 |
|* 26 | TABLE ACCESS FULL | PROCEDUR | 888 | 44400 | | 11 (0)| 00:00:01 |
|* 27 | TABLE ACCESS FULL | TRX | 442K| 28M| | 23845 (2)| 00:04:47 |
|* 28 | TABLE ACCESS FULL | USERS | 1 | 11 | | 55 (0)| 00:00:01 |
| 29 | NESTED LOOPS | | 1 | 473 | | 25798 (1)| 00:05:10 |
| 30 | NESTED LOOPS | | 1 | 413 | | 25797 (1)| 00:05:10 |
| 31 | NESTED LOOPS | | 1 | 398 | | 25796 (1)| 00:05:10 |
| 32 | NESTED LOOPS | | 1 | 390 | | 25795 (1)| 00:05:10 |
|* 33 | HASH JOIN | | 1 | 303 | | 25794 (1)| 00:05:10 |
| 34 | TABLE ACCESS FULL | LLU_EVALUATION_DESCRIPTIONS | 95 | 6175 | | 3 (0)| 00:00:01 |
|* 35 | HASH JOIN | | 4630 | 1076K| | 25791 (1)| 00:05:10 |
|* 36 | HASH JOIN | | 9607 | 1623K| | 23834 (1)| 00:04:47 |
| 37 | MERGE JOIN | | 888 | 91464 | | 13 (8)| 00:00:01 |
| 38 | TABLE ACCESS BY INDEX ROWID | CLASS | 20 | 1660 | | 1 (0)| 00:00:01 |
| 39 | INDEX FULL SCAN | CLASS_PRIMARY | 20 | | | 1 (0)| 00:00:01 |
|* 40 | SORT JOIN | | 888 | 17760 | | 12 (9)| 00:00:01 |
|* 41 | TABLE ACCESS FULL | PROCEDUR | 888 | 17760 | | 11 (0)| 00:00:01 |
|* 42 | TABLE ACCESS FULL | TRX | 19125 | 1307K| | 23820 (1)| 00:04:46 |
|* 43 | TABLE ACCESS FULL | GRADITEM | 655K| 40M| | 1952 (1)| 00:00:24 |
| 44 | TABLE ACCESS BY INDEX ROWID | PRODUCER | 1 | 87 | | 1 (0)| 00:00:01 |
|* 45 | INDEX UNIQUE SCAN | PRODUCER_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
|* 46 | TABLE ACCESS BY INDEX ROWID | GRADING | 1 | 8 | | 1 (0)| 00:00:01 |
|* 47 | INDEX UNIQUE SCAN | GRADING_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
| 48 | TABLE ACCESS BY INDEX ROWID | USERS | 221 | 3315 | | 1 (0)| 00:00:01 |
|* 49 | INDEX RANGE SCAN | USERS_PRODUCER | 1 | | | 1 (0)| 00:00:01 |
| 50 | TABLE ACCESS BY INDEX ROWID | PATIENT | 1 | 60 | | 1 (0)| 00:00:01 |
|* 51 | INDEX UNIQUE SCAN | PATIENT_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
| 52 | TABLE ACCESS BY INDEX ROWID | USERS | 109 | 1635 | | 1 (0)| 00:00:01 |
| 53 | NESTED LOOPS | | 1 | 438 | | 2023 (1)| 00:00:25 |
| 54 | NESTED LOOPS | | 1 | 423 | | 2022 (1)| 00:00:25 |
| 55 | NESTED LOOPS | | 1 | 363 | | 2021 (1)| 00:00:25 |
| 56 | NESTED LOOPS | | 1 | 276 | | 2020 (1)| 00:00:25 |
| 57 | NESTED LOOPS | | 1 | 193 | | 2019 (1)| 00:00:25 |
| 58 | NESTED LOOPS | | 1 | 185 | | 2018 (1)| 00:00:25 |
| 59 | NESTED LOOPS | | 1 | 173 | | 2017 (1)| 00:00:25 |
| 60 | NESTED LOOPS | | 1 | 140 | | 2016 (1)| 00:00:25 |
|* 61 | TABLE ACCESS FULL | GRADITEM | 317 | 23141 | | 1953 (2)| 00:00:24 |
|* 62 | TABLE ACCESS BY INDEX ROWID| TRX | 1 | 67 | | 1 (0)| 00:00:01 |
|* 63 | INDEX UNIQUE SCAN | TRX_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
|* 64 | TABLE ACCESS BY INDEX ROWID | TRX | 1 | 33 | | 1 (0)| 00:00:01 |
|* 65 | INDEX UNIQUE SCAN | TRX_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
|* 66 | TABLE ACCESS BY INDEX ROWID | GRADITEM | 1 | 12 | | 1 (0)| 00:00:01 |
|* 67 | INDEX RANGE SCAN | GRADITEM_ID | 19 | | | 1 (0)| 00:00:01 |
|* 68 | TABLE ACCESS BY INDEX ROWID | GRADING | 1 | 8 | | 1 (0)| 00:00:01 |
|* 69 | INDEX UNIQUE SCAN | GRADING_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
| 70 | TABLE ACCESS BY INDEX ROWID | CLASS | 1 | 83 | | 1 (0)| 00:00:01 |
|* 71 | INDEX UNIQUE SCAN | CLASS_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
| 72 | TABLE ACCESS BY INDEX ROWID | PRODUCER | 1 | 87 | | 1 (0)| 00:00:01 |
|* 73 | INDEX UNIQUE SCAN | PRODUCER_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
| 74 | TABLE ACCESS BY INDEX ROWID | PATIENT | 1 | 60 | | 1 (0)| 00:00:01 |
|* 75 | INDEX UNIQUE SCAN | PATIENT_PRIMARY | 1 | | | 1 (0)| 00:00:01 |
|* 76 | INDEX RANGE SCAN | USERS_PRODUCER | 1 | | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("QRP"."ProviderID"="U1"."Producer")
5 - access(ROWID=ROWID)
8 - access(TRIM("QRP"."ProviderID")=TRIM("P"."Producer"))
10 - access(TRIM("QRP"."axiUm_Discipline")=TRIM("CLASS"."Class"))
12 - filter("QRP"."ProviderID" IS NOT NULL AND "QRP"."Location"<'9990' AND "QRP"."ProcedureID"<>185 AND
"QRP"."PatientFirstName"<>'NON-PATIENT' AND ("QRP"."PatientFirstName"<>'TED' OR "QRP"."PatientLastName" NOT LIKE
'CAVENDER%'))
13 - filter( NOT EXISTS (SELECT 0 FROM AXIUM."USERS" "USERS" WHERE "Custom3"='YES' AND LNNVL("User"<>:B1)) OR
TO_CHAR(INTERNAL_FUNCTION("P"."EndDate"),'YYYY')<'2011' OR TRIM(TO_CHAR(INTERNAL_FUNCTION("P"."EndDate"),'YYYY')) IS
NULL OR "TRX"."Procedure"='A0021' OR "TRX"."Procedure"='A0022')
14 - access("TRX"."Producer"="U1"."Producer")
16 - access(ROWID=ROWID)
19 - access("PROC"."Discipline"="CLASS"."Class")
21 - access("TRX"."Producer"="P"."Producer")
23 - access("TRX"."Patient"="PAT"."Patient")
25 - access("TRX"."Procedure"="PROC"."Procedure")
26 - filter("PROC"."Discipline" IS NOT NULL)
27 - filter("TRX"."Deleted"=0 AND "TRX"."Status"='C' AND "TRX"."Procedure" NOT LIKE 'D0149%' AND
"TRX"."Procedure"<>'D5001C')
28 - filter("Custom3"='YES' AND LNNVL("User"<>:B1))
33 - access(TRIM(UPPER("GI"."QuestionText"))=TRIM(UPPER("LLU"."GRADITEM_QuestionText")) AND
TRIM(UPPER("GI"."Text"))=TRIM(UPPER("LLU"."GRADITEM_Text")) AND TRIM("TRX"."Procedure")=TRIM("LLU"."ProcedureCode"))
35 - access("TRX"."Type"="GI"."Type" AND "TRX"."Id"="GI"."Id" AND "TRX"."Treatment"="GI"."Treatment")
36 - access("TRX"."Procedure"="PROC"."Procedure")
40 - access("PROC"."Discipline"="CLASS"."Class")
filter("PROC"."Discipline"="CLASS"."Class")
41 - filter("PROC"."Discipline" IS NOT NULL)
42 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C')
43 - filter("GI"."Grading"<>0)
45 - access("TRX"."Producer"="P"."Producer")
46 - filter("G"."Deleted"=0)
47 - access("TRX"."Grading"="G"."Grading")
filter("G"."Grading"<>0 AND "G"."Grading"="GI"."Grading")
49 - access("TRX"."Producer"="U1"."Producer")
51 - access("TRX"."Patient"="PAT"."Patient")
61 - filter("GI"."IsHeading"=3 AND TRIM("GI"."QuestionText")='Comments' AND "GI"."Grading"<>0)
62 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C' AND ("TRX"."Procedure"='G1002' OR
"TRX"."Procedure"='G1003'))
63 - access("GI"."Type"="TRX"."Type" AND "GI"."Id"="TRX"."Id" AND "GI"."Treatment"="TRX"."Treatment")
64 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C' AND ("TRX"."Procedure"='G1002' OR
"TRX"."Procedure"='G1003') AND "TRX"."Grading"="TRX"."Grading")
65 - access("TRX"."Type"="TRX"."Type" AND "TRX"."Id"="TRX"."Id" AND "TRX"."Treatment"="TRX"."Treatment")
66 - filter("GI"."RelValue"<>0 AND "TRX"."Type"="GI"."Type" AND "TRX"."Treatment"="GI"."Treatment")
67 - access("TRX"."Id"="GI"."Id")
68 - filter("G"."Deleted"=0)
69 - access("TRX"."Grading"="G"."Grading")
filter("G"."Grading"<>0 AND "GI"."Grading"="G"."Grading")
71 - access("TRX"."Discipline"="CLASS"."Class")
73 - access("TRX"."Producer"="P"."Producer")
75 - access("TRX"."Patient"="PAT"."Patient")
76 - access("TRX"."Producer"="U1"."Producer")
138 rows selected.
Elapsed: 00:00:00.62
631015 rows selected.
Elapsed: 00:01:49.13Output from AUTOTRACE (I think)
NOTE: this post was too long for the forum, so I have removed a number of lines in the following output which appeared to be duplicating the above section (EXPLAIN PLAN).
Statistics
2657 recursive calls
0 db block gets
12734113 consistent gets
13499 physical reads
0 redo size
103697740 bytes sent via SQL*Net to client
69744 bytes received via SQL*Net from client
6312 SQL*Net roundtrips to/from client
76 sorts (memory)
0 sorts (disk)
631015 rows processedThe TKPROF output
select * from llu_v_production_detail_03
call count cpu elapsed disk query current rows
Parse 1 0.51 0.51 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 6312 88.09 98.01 13490 12733584 0 631015
total 6314 88.60 98.52 13490 12733584 0 631015
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 57
Rows Row Source Operation
631015 VIEW LLU_V_PRODUCTION_DETAIL_03 (cr=12733584 pr=13490 pw=0 time=92145592 us)
631015 UNION-ALL (cr=12733584 pr=13490 pw=0 time=91514573 us)
125485 HASH JOIN (cr=8099 pr=6396 pw=0 time=1523326 us)
1725 VIEW index$_join$_007 (cr=24 pr=0 pw=0 time=4777 us)
1725 HASH JOIN (cr=24 pr=0 pw=0 time=3051 us)
1725 INDEX FAST FULL SCAN USERS_PRIMARY (cr=7 pr=0 pw=0 time=50 us)(object id 55023)
1725 INDEX FAST FULL SCAN USERS_PRODUCER (cr=17 pr=0 pw=0 time=16 us)(object id 55024)
144513 HASH JOIN (cr=8075 pr=6396 pw=0 time=2326445 us)
1396 TABLE ACCESS FULL PRODUCER (cr=107 pr=0 pw=0 time=29 us)
144513 HASH JOIN (cr=7968 pr=6396 pw=0 time=2035684 us)
20 TABLE ACCESS FULL CLASS (cr=7 pr=0 pw=0 time=71 us)
151043 TABLE ACCESS FULL QR_PRODUCTION (cr=7961 pr=6396 pw=0 time=313553 us)
462685 FILTER (cr=10755862 pr=7094 pw=0 time=58570941 us)
466790 HASH JOIN (cr=145247 pr=7094 pw=0 time=11007301 us)
1725 VIEW index$_join$_014 (cr=24 pr=0 pw=0 time=6817 us)
1725 HASH JOIN (cr=24 pr=0 pw=0 time=5091 us)
1725 INDEX FAST FULL SCAN USERS_PRIMARY (cr=7 pr=0 pw=0 time=35 us)(object id 55023)
1725 INDEX FAST FULL SCAN USERS_PRODUCER (cr=17 pr=0 pw=0 time=19 us)(object id 55024)
485205 HASH JOIN (cr=145223 pr=7094 pw=0 time=10945107 us)
20 TABLE ACCESS FULL CLASS (cr=7 pr=0 pw=0 time=105 us)
507772 HASH JOIN (cr=145216 pr=7094 pw=0 time=11947534 us)
1396 TABLE ACCESS FULL PRODUCER (cr=107 pr=0 pw=0 time=18 us)
507772 HASH JOIN (cr=145109 pr=7094 pw=0 time=10924473 us)
188967 TABLE ACCESS FULL PATIENT (cr=31792 pr=0 pw=0 time=188998 us)
507772 HASH JOIN (cr=113317 pr=7094 pw=0 time=9652037 us)
895 TABLE ACCESS FULL PROCEDUR (cr=46 pr=0 pw=0 time=65 us)
509321 TABLE ACCESS FULL TRX (cr=113271 pr=7094 pw=0 time=5604567 us)
8548 TABLE ACCESS FULL USERS (cr=10610615 pr=0 pw=0 time=39053120 us)
42669 NESTED LOOPS (cr=507317 pr=0 pw=0 time=3686506 us)
42669 NESTED LOOPS (cr=421535 pr=0 pw=0 time=3217140 us)
45269 NESTED LOOPS (cr=301155 pr=0 pw=0 time=2449542 us)
45323 NESTED LOOPS (cr=210131 pr=0 pw=0 time=2134056 us)
45323 HASH JOIN (cr=119056 pr=0 pw=0 time=1635472 us)
95 TABLE ACCESS FULL LLU_EVALUATION_DESCRIPTIONS (cr=7 pr=0 pw=0 time=118 us)
98272 HASH JOIN (cr=119049 pr=0 pw=0 time=1446703 us)
46996 HASH JOIN (cr=109018 pr=0 pw=0 time=944857 us)
786 MERGE JOIN (cr=50 pr=0 pw=0 time=1528 us)
20 TABLE ACCESS BY INDEX ROWID CLASS (cr=4 pr=0 pw=0 time=99 us)
20 INDEX FULL SCAN CLASS_PRIMARY (cr=1 pr=0 pw=0 time=10 us)(object id 53850)
786 SORT JOIN (cr=46 pr=0 pw=0 time=750 us)
895 TABLE ACCESS FULL PROCEDUR (cr=46 pr=0 pw=0 time=18 us)
47196 TABLE ACCESS FULL TRX (cr=108968 pr=0 pw=0 time=805137 us)
696300 TABLE ACCESS FULL GRADITEM (cr=10031 pr=0 pw=0 time=277 us)
45323 TABLE ACCESS BY INDEX ROWID PRODUCER (cr=91075 pr=0 pw=0 time=414937 us)
45323 INDEX UNIQUE SCAN PRODUCER_PRIMARY (cr=45752 pr=0 pw=0 time=198709 us)(object id 54581)
45269 TABLE ACCESS BY INDEX ROWID GRADING (cr=91024 pr=0 pw=0 time=353081 us)
45270 INDEX UNIQUE SCAN GRADING_PRIMARY (cr=45753 pr=0 pw=0 time=173185 us)(object id 54088)
42669 TABLE ACCESS BY INDEX ROWID USERS (cr=120380 pr=0 pw=0 time=703786 us)
42669 INDEX RANGE SCAN USERS_PRODUCER (cr=46127 pr=0 pw=0 time=249186 us)(object id 55024)
42669 TABLE ACCESS BY INDEX ROWID PATIENT (cr=85782 pr=0 pw=0 time=407452 us)
42669 INDEX UNIQUE SCAN PATIENT_PRIMARY (cr=43098 pr=0 pw=0 time=198477 us)(object id 54370)
176 TABLE ACCESS BY INDEX ROWID USERS (cr=49426 pr=0 pw=0 time=1783886 us)
367 NESTED LOOPS (cr=49149 pr=0 pw=0 time=6159428 us)
190 NESTED LOOPS (cr=48953 pr=0 pw=0 time=409391 us)
190 NESTED LOOPS (cr=48569 pr=0 pw=0 time=407105 us)
190 NESTED LOOPS (cr=48185 pr=0 pw=0 time=404820 us)
191 NESTED LOOPS (cr=47991 pr=0 pw=0 time=410291 us)
193 NESTED LOOPS (cr=47603 pr=0 pw=0 time=422507 us)
193 NESTED LOOPS (cr=46979 pr=0 pw=0 time=416890 us)
193 NESTED LOOPS (cr=46396 pr=0 pw=0 time=414374 us)
14285 TABLE ACCESS FULL GRADITEM (cr=9602 pr=0 pw=0 time=85793 us)
193 TABLE ACCESS BY INDEX ROWID TRX (cr=36794 pr=0 pw=0 time=128427 us)
8218 INDEX UNIQUE SCAN TRX_PRIMARY (cr=28576 pr=0 pw=0 time=64353 us)(object id 54930)
193 TABLE ACCESS BY INDEX ROWID TRX (cr=583 pr=0 pw=0 time=2169 us)
193 INDEX UNIQUE SCAN TRX_PRIMARY (cr=390 pr=0 pw=0 time=918 us)(object id 54930)
193 TABLE ACCESS BY INDEX ROWID GRADITEM (cr=624 pr=0 pw=0 time=4840 us)
1547 INDEX RANGE SCAN GRADITEM_ID (cr=395 pr=0 pw=0 time=2910 us)(object id 54093)
191 TABLE ACCESS BY INDEX ROWID GRADING (cr=388 pr=0 pw=0 time=1887 us)
191 INDEX UNIQUE SCAN GRADING_PRIMARY (cr=197 pr=0 pw=0 time=943 us)(object id 54088)
190 TABLE ACCESS BY INDEX ROWID CLASS (cr=194 pr=0 pw=0 time=1306 us)
190 INDEX UNIQUE SCAN CLASS_PRIMARY (cr=4 pr=0 pw=0 time=551 us)(object id 53850)
190 TABLE ACCESS BY INDEX ROWID PRODUCER (cr=384 pr=0 pw=0 time=1617 us)
190 INDEX UNIQUE SCAN PRODUCER_PRIMARY (cr=194 pr=0 pw=0 time=715 us)(object id 54581)
190 TABLE ACCESS BY INDEX ROWID PATIENT (cr=384 pr=0 pw=0 time=1941 us)
190 INDEX UNIQUE SCAN PATIENT_PRIMARY (cr=194 pr=0 pw=0 time=939 us)(object id 54370)
176 INDEX RANGE SCAN USERS_PRODUCER (cr=196 pr=0 pw=0 time=1389 us)(object id 55024)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 6312 0.00 0.00
db file scattered read 1614 0.02 2.08
SQL*Net message from client 6312 0.00 10.11
SQL*Net more data to client 48662 0.00 0.70
db file sequential read 4645 0.02 7.11
latch: shared pool 7 0.00 0.00
latch: cache buffers chains 1 0.00 0.00
********************************************************************************Again, I apologize if this is way more information than is necessary.
All advice/suggestions/assistance will be gratefully accepted.
CarlHi Rob,
Thank you for replying. Here is the view definition . . . it looks pretty convoluted, I know.
I am reporting from a database which I have no control over other than to add indexes where needed.
For reporting purposes, I am needing to create the dataset from a number of different tables; hence all the UNION clauses.
-- CODE FOLLOWS
CREATE OR REPLACE VIEW LLU_V_PRODUCTION_DETAIL_03
AS
SELECT
'QR' AS "Source",
U1."User" AS "UserID",
QRP."ProviderID" AS "ProviderID",
P."LastName" AS "ProviderLastName",
P."FirstName" AS "ProviderFirstName",
TO_CHAR(P."EndDate",'YYYY') AS "GraduationYear",
P."PGroup",
QRP."PatientID",
QRP."ChartNumber",
QRP."PatientLastName",
QRP."PatientFirstName",
QRP."ProcedureID" || '-' || QRP."ProcedureSuffix" AS "Procedure",
QRP."ProcedureDescription",
QRP."Tooth" AS "Site",
QRP."Surface",
QRP."axiUm_Discipline" AS "Discipline",
"CLASS"."Rank" AS "DisciplineSorter",
"CLASS"."Name" AS "DisciplineName",
QRP."Points",
0 AS "Hours",
QRP."ServiceDate",
0 AS "Id",
QRP."UniqueID" AS "Grading",
0 AS "LastSort",
QRP."CategoryID",
'' AS "CPAR comments"
FROM QR_PRODUCTION QRP
INNER JOIN PRODUCER P
ON TRIM(QRP."ProviderID") = TRIM(P."Producer")
INNER JOIN CLASS
ON TRIM(QRP."axiUm_Discipline") = TRIM(CLASS."Class")
INNER JOIN USERS U1
ON QRP."ProviderID" = U1."Producer"
WHERE (QRP."Location" < '9990')
AND (QRP."ProviderID" IS NOT NULL)
AND (QRP."ProcedureID" <> 185)
-- skip the Cavender family - training patients
AND NOT (QRP."PatientLastName" LIKE 'CAVENDER%' AND QRP."PatientFirstName" = 'TED')
AND QRP."PatientFirstName" <> 'NON-PATIENT'
--ORDER BY QRP."ProcedureID"
UNION ALL
SELECT
'axiUm TRX' AS "Source",
U1."User" AS "UserID",
TRX."Producer" AS "ProviderID",
P."LastName",
P."FirstName",
TO_CHAR(P."EndDate",'YYYY') AS "GraduationYear",
P."PGroup",
PAT."Patient",
PAT."Chart",
PAT."Last" AS "PatientLastName",
PAT."First" AS "PatientFirstName",
TRX."Procedure",
PROC."Description",
TRX."Site",
TRX."Surface",
TRIM(PROC."Discipline") AS "Discipline",
"CLASS"."Rank" AS "DisciplineSorter",
"CLASS"."Name",
CASE WHEN
((TRX."Procedure" IN ('A0013','A0019','A0020','A0021','A0023','A0024','A0025','A0026','A0027','A0028','A0029','A0030','O179'))
OR
-- no points are to be awarded for any procedures performed on typodonts
(EXISTS (SELECT 1 FROM PTTYPES PTT WHERE PTT."Patient" = PAT."Patient" and PTT."PatType" = 'TYPO' and PTT."Deleted" = 0)))
AND -- except for the following procedures
(TRX."Procedure" NOT IN ('A0015','A0016','A0018','D0210'))
THEN 0 ELSE PROC."RelValue" END AS "Points",
CASE WHEN TRX."Procedure" IN ('A0013','A0019','A0020','A0021','A0023','A0024','A0025','A0026','A0027','A0028','A0029','A0030','O179')
THEN PROC."RelValue" ELSE 0 END AS "Hours",
TRX."TreatmentDate",
TRX."Id",
TRX."Grading",
-1 AS "LastSort",
-- additional link conditions added and table name changed on 1 July 2009 - cji
SELECT "CategoryID" FROM LLU_CATEGORIES_X_PROCEDURES_03 LLU
WHERE TRX."Procedure" = LLU."ProcedureID"
AND TO_CHAR(P."EndDate",'YYYY') = LLU."GraduationYear"
AND SUBSTR(TRX."Producer",1,1) = LLU."ProviderType"
AND LLU."CategoryID" NOT IN (82)
) AS "CategoryID",
'' AS "CPAR comments"
FROM TRX
INNER JOIN PATIENT PAT
ON TRX."Patient" = PAT."Patient"
INNER JOIN USERS U1
ON TRX."Producer" = U1."Producer"
INNER JOIN PROCEDUR PROC
ON TRX."Procedure" = PROC."Procedure"
INNER JOIN CLASS
ON PROC."Discipline" = CLASS."Class"
INNER JOIN PRODUCER P
ON TRX."Producer" = P."Producer"
WHERE (TRX."Status" = 'C')
AND (TRX."Deleted" = 0)
--AND (TRX."Grading" = 0)
AND (TRX."Procedure" NOT LIKE 'D0149%')
AND (TRX."Procedure" <> 'D5001C')
-- exclude all procedures approved by Peds faculty ONLY FOR CLASS OF 2011 AND LATER
-- EXCEPT FOR the Peds Block code (A0021 and A0022) - always include those
AND NOT
TRX."AppUser" IN (SELECT "User" FROM USERS WHERE "Custom3" = 'YES') -- Peds faculty
AND
TO_CHAR(P."EndDate",'YYYY') >= '2011'
AND
TRIM(TO_CHAR(P."EndDate",'YYYY')) IS NOT NULL
AND
TRX."Procedure" NOT IN ('A0021','A0022')
UNION ALL
SELECT
'axiUm GRADING' AS "Source",
U1."User" AS "UserID",
TRX."Producer" AS "ProviderID",
P."LastName",
P."FirstName",
TO_CHAR(P."EndDate",'YYYY'), -- Graduation year
P."PGroup",
PAT."Patient",
PAT."Chart",
PAT."Last" AS "PatientLastName",
PAT."First" AS "PatientFirstName",
TRX."Procedure",
LLU."Description",
TRX."Site",
TRX."Surface",
TRIM(PROC."Discipline") AS "Discipline",
"CLASS"."Rank" AS "DisciplineSorter",
"CLASS"."Name",
LLU."Points", --LLU_POINTS_FROM_EVALUATIONS(TRX."Procedure", nvl(GI."Text",0)),
0 AS "Hours",
TRX."TreatmentDate",
GI."Id",
GI."Grading",
GI."Row" AS "LastSort",
LLU."CategoryID",
'' AS "CPAR comments"
FROM TRX
INNER JOIN PATIENT PAT
ON TRX."Patient" = PAT."Patient"
INNER JOIN PRODUCER P
ON TRX."Producer" = P."Producer"
INNER JOIN GRADING G
ON TRX."Grading" = G."Grading"
INNER JOIN GRADITEM GI
ON G."Grading" = GI."Grading"
AND TRX."Type" = GI."Type"
AND TRX."Id" = GI."Id"
AND TRX."Treatment" = GI."Treatment"
INNER JOIN PROCEDUR PROC
ON TRX."Procedure" = PROC."Procedure"
INNER JOIN CLASS
ON PROC."Discipline" = CLASS."Class"
INNER JOIN LLU_EVALUATION_DESCRIPTIONS LLU
ON (TRIM(UPPER(GI."QuestionText")) = TRIM(UPPER(LLU."GRADITEM_QuestionText")))
AND (TRIM(UPPER(GI."Text")) = TRIM(UPPER(LLU."GRADITEM_Text")))
AND (TRIM(TRX."Procedure") = TRIM(LLU."ProcedureCode"))
INNER JOIN USERS U1
ON TRX."Producer" = U1."Producer"
WHERE (TRX."Status" = 'C')
AND (TRX."Deleted" = 0)
AND (TRX."Grading" <> 0)
AND (G."Deleted" = 0)
UNION ALL
SELECT 'ClinPtsAdj',
U1."User" AS "UserID",
TRX."Producer",
P."LastName", P."FirstName",
TO_CHAR(P."EndDate",'YYYY'), -- Graduation year
P."PGroup", PAT."Patient", PAT."Chart", PAT."Last", PAT."First",
TRX."Procedure",
'Clinic points adjustment',
'' AS "Site",
'' AS "Surface",
TRIM(TRX."Discipline"),
"CLASS"."Rank",
"CLASS"."Name",
DERIVED."Points",
0 AS "Hours",
GI."Date",
GI."Id",
GI."Grading",
GI."Row",
NULL AS "CategoryID",
TRIM(REPLACE(GI."Note", CHR(13) || CHR(10), ' '))
FROM TRX
INNER JOIN PATIENT PAT
ON (TRX."Patient" = PAT."Patient")
INNER JOIN PRODUCER P
ON (TRX."Producer" = P."Producer")
INNER JOIN CLASS
ON (TRX."Discipline" = CLASS."Class")
INNER JOIN GRADING G
ON (TRX."Grading" = G."Grading")
INNER JOIN GRADITEM GI
ON (GI."Grading" = G."Grading")
AND (GI."Type" = TRX."Type")
AND (GI."Id" = TRX."Id")
AND (GI."Treatment" = TRX."Treatment")
INNER JOIN USERS U1
ON TRX."Producer" = U1."Producer"
INNER JOIN
SELECT TRX."Type", TRX."Id", TRX."Treatment", TRX."Grading",
CASE WHEN TRX."Procedure" = 'G1003' THEN GI."RelValue" * -1 ELSE "RelValue" END AS "Points"
FROM TRX, GRADITEM GI
WHERE (TRX."Type" = GI."Type")
AND (TRX."Id" = GI."Id")
AND (TRX."Treatment" = GI."Treatment")
AND (TRX."Procedure" IN ('G1002','G1003'))
AND (TRX."Status" = 'C')
AND (TRX."Deleted" = 0)
AND (TRX."Grading" <> 0)
AND (GI."RelValue" <> 0)
) DERIVED
ON (TRX."Type" = DERIVED."Type")
AND (TRX."Id" = DERIVED."Id")
AND (TRX."Treatment" = DERIVED."Treatment")
AND (TRX."Grading" = DERIVED."Grading")
WHERE (TRX."Status" = 'C')
AND (TRX."Deleted" = 0)
AND (TRX."Grading" <> 0)
AND (G."Deleted" = 0)
AND (TRX."Procedure" IN ('G1002','G1003'))
AND (GI."IsHeading" = 3)
AND (TRIM(GI."QuestionText") = 'Comments')
--ORDER BY "ProviderID", "DisciplineSorter", "Id", "Grading", "Site", "LastSort";A couple of additional points:
The table USERS already had an index on column "Producer"; I added an index on column "Custom3" but it did not seem to make any difference.
Table USERS has 1,725 rows
Table PRODUCER (aliased as P) has 1,396 rows
Table TRX has 1,443,764 rows.
Any additional information you need I will be glad to provide.
Thanks a bunch; it may not be too late to teach an old dog new tricks.
And thank you all for the kind words about the posting; about the only thing I can do well is follow directions.
Carl -
Query tuning : you can do it yourself
Hello,
This thread is not a question.
How tune my query ?
My query didn't use indexes why ?
I have indexes on table, stats are up-to-date why Oracle does a full scan on table ?
What are the hint which I can use ?
etc...
I would like try to answer to many such questions posted in this forum about query tuning.
And explain that tuning is not always complicated, is not always reserved to some consultants, is not always solved by hints usage, and not require to buy some books which would give some magic solutions.
By this thread, I would explain to people which have some query performance issues, that the solution is maybe here, in front of their eyes, inside the query itself. The solution may come from their own side, and that they can be happy to solve such question themself.
I'll develop here below a case from a real word situation encountered some time ago.At this point, remove this huge and nightmarish hint. We'll use it only if no other ways may found.
First, a look into the data model to see if the joins may be rewrite differently.
Original joins :
dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID and
dw.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID and
dw.REGION_ROUTING_ID = rr.REGION_ROUTING_ID and
dw.CITY_ROUTING_ID = cr.CITY_ROUTING_ID andAnd indeed, the join may be rewrite as below :
and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
and ar.CITY_ROUTING_ID = cr.CITY_ROUTING_ID
and cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID
and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_IDNote the aliases were change here. Is it complicated to try to rewrite query like that ?
Secondly, we will try to see how avoid or, at least, workaround the all OR conditions. It would be well if we could merge all the FROM (bind variable :a) in one column, same for all TO (bind variable :b), unfortunately, the data model cannot be change (of course). Ok, we will try to work with a temporary table by combining all the possiblities between the two conditions.
create global temporary table REGION_ROUTING_TMP
on commit preserve rows
as
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
from REGION_ROUTING
where 1=2;And an index based on the two mains criteria of the query may help :
create index IDX_REGION_ROUTING_TMP on REGION_ROUTING_TMP(REGION_FROM,REGION_TO);Then we'll populate table :
insert into REGION_ROUTING_TMP
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP2 as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP3 as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_TO as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP2 as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP3 as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_TO as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_STOP3 as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_TO as REGION_TO
from REGION_ROUTING
union
select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP3 as REGION_FROM, REGION_TO as REGION_TO
from REGION_ROUTING;The insert take near 9 seconds, which is a reasonnable elapse time.
At this point, the query become :
Select
ap.AIRPORT_PAIR,
dw.DELIVERY_PERIOD,
dw.TOTAL_PAX As Demand,
od.GLOBAL_TOTAL_PAX as Total_OD_Demand,
dw.REPORTED_PAX As ReportedPax,
ap.AIRPORT_FROM,
ap.AIRPORT_TO,
ap.CITY_FROM,
ap.CITY_TO,
ap.COUNTRY_FROM_NAME,
ap.COUNTRY_TO_NAME,
ap.REGION_FROM_NAME,
ap.REGION_TO_NAME,
ar.AIRPORT_ROUTING,
cr.CITY_ROUTING,
cor.COUNTRY_ROUTING_NAMES,
rr.REGION_ROUTING_NAMES,
ar.NUMBER_OF_STOP,
dw.PERCENT_OF_TOTAL_PAX_VS_OD,
dw.AIRLINE1,
dw.AIRLINE2,
dw.AIRLINE3,
dw.AIRLINE4,
dw.NUMBER_OF_AIRLINE,
dw.AIRCRAFTCLASS_NAME,
dw.FARE
From
REGION_ROUTING_TMP rr, -- here we use now the temporary table instead of REGION_ROUTING table
DETAILED_FLIGHTS dw,
AIRPORT_PAIR ap,
AIRPORT_ROUTING ar,
CITY_ROUTING cr,
COUNTRY_ROUTING cor,
OD od
where
dw.DELIVERY_PERIOD in ('2006-09','2006-08','2006-07')
and dw.AIRPORT_PAIR_ID = ap.AIRPORT_PAIR_ID
and dw.OD_ID = od.OD_ID
and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
and ar.CITY_ROUTING_ID = cr.CITY_ROUTING_ID
and cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID
and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_ID
and rr.REGION_FROM = '7' |
and rr.REGION_TO = '8' |-> these two lines replace all the OR conditions;And explain plan :
| Id | Operation | Name | Rows | Bytes | Cost | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 469 | 174K| 3462 | | |
| 1 | NESTED LOOPS | | 469 | 174K| 3462 | | |
| 2 | NESTED LOOPS | | 458 | 166K| 3004 | | |
| 3 | NESTED LOOPS | | 454 | 127K| 2096 | | |
| 4 | NESTED LOOPS | | 258 | 58308 | 548 | | |
| 5 | NESTED LOOPS | | 246 | 48216 | 56 | | |
| 6 | NESTED LOOPS | | 26 | 4420 | 4 | | |
| 7 | TABLE ACCESS BY INDEX ROWID | REGION_ROUTING_TMP | 1 | 123 |
|* 8 | INDEX RANGE SCAN | IDX_REGION_ROUTING_TMP | 1 | | 1 | |
| 9 | TABLE ACCESS BY INDEX ROWID | COUNTRY_ROUTING | 32 | 1504 | 2
|* 10 | INDEX RANGE SCAN | IX9_COUNTRY_ROUTING | 32 | | 1 | |
| 11 | TABLE ACCESS BY INDEX ROWID | CITY_ROUTING | 9 | 234 | 2 |
|* 12 | INDEX RANGE SCAN | IX9_CITY_ROUTING | 12 | | 1 |
| 13 | TABLE ACCESS BY INDEX ROWID | AIRPORT_ROUTING | 1 | 30 | 2
|* 14 | INDEX RANGE SCAN | IX10_AIRPORT_ROUTING | 1 | | 1 |
|* 15 | TABLE ACCESS BY GLOBAL INDEX ROWID| DETAILED_FLIGHTS | 2 | 122 |
|* 16 | INDEX RANGE SCAN | IX3_DETAILED_FLIGHTS | 9 | | 2 |
| 17 | TABLE ACCESS BY INDEX ROWID | AIRPORT_PAIR | 1 | 85 | 2 |
|* 18 | INDEX RANGE SCAN | IX1_AIRPORT_PAIR | 1 | | 1 | |
| 19 | TABLE ACCESS BY INDEX ROWID | OD | 1 | 10 | 1 | |
|* 20 | INDEX UNIQUE SCAN | PK_OD | 1 | | | | |
----------------------------------------------------------------------------------------------------Ouf, this sound like better, isn't it ? Was it complicated to arrive as such result ?
Ok, now launch the query and see the elapse time :
104103 rows selected.
Elapsed: 00:09:00.12
Statistics
0 recursive calls
0 db block gets
1214845 consistent gets
272481 physical reads
0 redo size
11164355 bytes sent via SQL*Net to client
257032 bytes received via SQL*Net from client
6942 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
104103 rows processedWoaw, developer is now very happy, less than 10 minutes instead of one hour... and without modify anything else in database and server settings, without add indexes, without add any hints...
Ok, now the problem is in the number of returned lines. Have you see the number of return client/server ? We'll now to try to reduce this one. Increasing the number of line returned by fetch :
set arraysize 5000
--run the query
104103 rows selected.
Elapsed: 00:02:25.49
Statistics
0 recursive calls
0 db block gets
1150893 consistent gets
271432 physical reads
0 redo size
11018641 bytes sent via SQL*Net to client
1013 bytes received via SQL*Net from client
22 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
104103 rows processedOk, the number of retunr client/server is now low, and elapse time is ok user.
Maybe you are looking for
-
Volume of voice memos suddenly dropped
I was listening to some voice memos and it was completely fine until my iPhone 6+ restarts by itself. When I unlock it and go back on the voice memos, the volume is suddenly extremely low and even on the highest volume, it's barely audible. I restart
-
Can't open web addresses from an email-get an ERROR message saying-no application could be found
-
Flash 9.0.31.0 Crashes Mozilla 1.7.8 in SuSE Linux 9.0
Any time there is a Flash file on a page, Mozilla will crash fairly quickly. Just disappears without warning. I had the same problem with v8.something of Adobe Flash. I switched back to Flash 7 for a while and decided to try 9.. thinking that issue m
-
How can I transfer my long list of organized favorites I have on MS Internet Explorer over to Firefox?
-
Why rollback doesn't work?
hello, I am mantaining a servlet application with Tomcat and MySQL 4.0.16 . Here is a part of the code that is giving me lots of problems with concurrent users: public void saveUpdate(String gameName, int IDAzienda, int periodo) throws ClassNotFoundE