Slow running query, plan attached
Oracle Database 10g Release 10.2.0.1.0
A particular query is taking a rather long time to run. This was something which used to run rather quick until a couple of days back.
Indexes seem to be used and nothing else seem to have changed muck. The 5.38 sec cpu time is what i am trying to trace down.
Does the attached plan show anything that indicates an underlying issue?
SELECT NVL(SUM(NVL(TCR.EMPLOYEEHOURSWORKED, 0) + NVL(TCR.EMPLOYEEOTHOURSWORKED,0)), 0)
FROM TYPE TYP, EQUIPMENT EQ, TIMECARD TC, TIMECARDRESOURCE TCR
WHERE TYP.TYPEID = EQ.TYPEID
AND TCR.EQUIPMENTID = EQ.EQUIPMENTID
AND EQ.TYPEID = :B2
AND TCR.EMPLOYEEID = :B1
AND TCR.TIMECARDID = TC.TIMECARDID
call count cpu elapsed disk query current rows
Parse 2 0.00 0.00 0 0 0 0
Execute 218 0.05 0.04 0 0 0 0
Fetch 218 5.33 5.23 0 2176948 0 218
total 438 5.38 5.28 0 2176948 0 218
Misses in library cache during parse: 1
Misses in library cache during execute: 2
Optimizer mode: ALL_ROWS
Parsing user id: 91 (recursive depth: 1)
Rows Row Source Operation
68 SORT AGGREGATE (cr=679048 pr=0 pw=0 time=1580234 us)
56 TABLE ACCESS BY INDEX ROWID TIMECARDRESOURCE (cr=679048 pr=0 pw=0 time=1479170 us)
743036 NESTED LOOPS (cr=9656 pr=0 pw=0 time=1507400 us)
2788 TABLE ACCESS BY INDEX ROWID EQUIPMENT (cr=1972 pr=0 pw=0 time=15059 us)
2788 INDEX RANGE SCAN IDX_EQP_TYPEID (cr=204 pr=0 pw=0 time=6075 us)(object id 193877)
740180 INDEX RANGE SCAN IDX_TCR_EQPID (cr=7684 pr=0 pw=0 time=848397 us)(object id 193878)
********************************************************************************
997026 wrote:
Oracle Database 10g Release 10.2.0.1.0
A particular query is taking a rather long time to run. This was something which used to run rather quick until a couple of days back.
Indexes seem to be used and nothing else seem to have changed muck. The 5.38 sec cpu time is what i am trying to trace down.
Does the attached plan show anything that indicates an underlying issue?
SELECT NVL(SUM(NVL(TCR.EMPLOYEEHOURSWORKED, 0) + NVL(TCR.EMPLOYEEOTHOURSWORKED,0)), 0)
FROM TYPE TYP, EQUIPMENT EQ, TIMECARD TC, TIMECARDRESOURCE TCR
WHERE TYP.TYPEID = EQ.TYPEID
AND TCR.EQUIPMENTID = EQ.EQUIPMENTID
AND EQ.TYPEID = :B2
AND TCR.EMPLOYEEID = :B1
AND TCR.TIMECARDID = TC.TIMECARDID
call count cpu elapsed disk query current rows
Parse 2 0.00 0.00 0 0 0 0
Execute 218 0.05 0.04 0 0 0 0
Fetch 218 5.33 5.23 0 2176948 0 218
total 438 5.38 5.28 0 2176948 0 218
Misses in library cache during parse: 1
Misses in library cache during execute: 2
Optimizer mode: ALL_ROWS
Parsing user id: 91 (recursive depth: 1)
Rows Row Source Operation
68 SORT AGGREGATE (cr=679048 pr=0 pw=0 time=1580234 us)
56 TABLE ACCESS BY INDEX ROWID TIMECARDRESOURCE (cr=679048 pr=0 pw=0 time=1479170 us)
743036 NESTED LOOPS (cr=9656 pr=0 pw=0 time=1507400 us)
2788 TABLE ACCESS BY INDEX ROWID EQUIPMENT (cr=1972 pr=0 pw=0 time=15059 us)
2788 INDEX RANGE SCAN IDX_EQP_TYPEID (cr=204 pr=0 pw=0 time=6075 us)(object id 193877)
740180 INDEX RANGE SCAN IDX_TCR_EQPID (cr=7684 pr=0 pw=0 time=848397 us)(object id 193878)
Notice how smart the optimizer has been - you've written a query with 4 tables in it, but the optimizer has recognised that it can eliminate two of the tables because of the primary key and referential integrity constraints.
From the remaining two tables, you have a query that looks as if it is inherently NON-SCALABLE. You select all timecardresources for a given employee, and all pieces of equiplment of a given type, and join them on the equipment id.
I am going to guess that the number of timecardresources for an employee will always grow with time - which means the volume of work you need to do will grow with time; moreover that on some regular basis you add rows to timecardresources, which means the number of random block visits per employeeid will grow with time.
It's possible that hash join that you've engineered in your current solution was the original path, but the optimizer reached the breakpoint where the cost of random visits by employeeid became too great and the decided to use a nested loop from the equipment. (These things happen). However, the point may come when you current solution is also too expensive and the optimizer may then decide to do a tablescan on the timecradresources table.
This is a fairly classic type of problem - a (relatively) small result set arising from a join with a single predicate on each of the joined tables.
If my assumptions are correct, you need to find a way to do one of three things
a) reduce the cost of finding all the timecardresources for an employee - recreating the table as an IOT (index organized table) may be an appropriate mechanism
b) restructure you indexes to minimise random visits to tables - eliminating data as early as possible.
c) re-engineer your indexes and SQL so that you don't do random visits to tables unless you need the rows that you're going to find (Here's a link to my blog which let's you access a video made a couple of years ago of a presentation I did on the topic: https://jonathanlewis.wordpress.com/2011/06/23/video/ )
A couple of other notes:
a) Christian Antognini's book is probably the best practical book available at present on Oracle Tuning
b) The index you've dropped in your solution looks like it might be an index created to protect a foreign key constraint from the "foreign key locking" problem.
Keep an eye open for enqueue waits of type TM, and TM deadlocks.
Regards
Jonathan Lewis
Similar Messages
-
Problem trying to diagnose slow running query
Hi, Group.
I have two versions of the same query. sql1 contains an inner select, sql2 contains the hard-coded values that the inner select returns. Other than that the queries look the exact same.
sql1 takes over 8 minutes to complete.
sql2 takes about 250ms to complete.
I tried running explain plan on both queries and sql1 appears to be the better query based on the plan_table cost columns. I even ran a query that shows the plan hash value for the currently running query. Both times, the slower query appears to be quicker.
So my problem is that all the diagnosis indicates that sql1 is faster than sql2 but in reality, sql2 is waaaaaaaaaaaaaaaaaaaaay faster than sql1. Does anyone have any other suggestions for tools that I can use that show why the supposedly fast query is actually the slower query?
Thanks, Max
EDIT: here is an example of sql1 and sql2 to help you visualize the problem.
SELECT <column list>
FROM <table list>
WHERE column IN (SELECT column FROM table)
AND <some more predicates>
SELECT <column list>
FROM <table list>
WHERE column IN (value1, value2, value3)
AND <some more predicates>The slow query is listed first.
PLAN_TABLE_OUTPUT
Plan hash value: 2494202055
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 869 | 10 (20)| 00:00:01 |
| 1 | SORT UNIQUE | | 1 | 869 | 9 (12)| 00:00:01 |
| 2 | NESTED LOOPS OUTER | | 1 | 869 | 8 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 1 | 749 | 7 (0)| 00:00:01 |
| 4 | NESTED LOOPS | | 1 | 725 | 6 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 1 | 701 | 6 (0)| 00:00:01 |
| 6 | NESTED LOOPS | | 1 | 685 | 3 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 1 | 645 | 1 (0)| 00:00:01 |
|* 8 | TABLE ACCESS BY INDEX ROWID| MASTERDATA_ATTRIBUTE | 1 | 387 | 1 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | I_MSTRRBT_M_VALUE | 1 | | 1 (0)| 00:00:01 |
|* 10 | TABLE ACCESS BY INDEX ROWID| MASTERDATA_ELEMENT | 1 | 258 | 0 (0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | I_MSTRMNT_M_VOCABULARYELEMENTI | 1 | | 0 (0)| 00:00:01 |
| 12 | TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT | 1 | 40 | 2 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | I_PCS_VNT_M_BUSINESSLOCATIONUR | 65659 | | 2 (0)| 00:00:01 |
|* 14 | TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT_EPC | 2 | 32 | 3 (0)| 00:00:01
|* 15 | INDEX RANGE SCAN | I_PCS__PC_EVENT_ID | 2 | | 2 (0)| 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT_EPC | 2 | 48 | 0 (0)| 00:00:01
|* 17 | INDEX RANGE SCAN | I_PCS__PC_EVENT_ID | 2 | | 2 (0)| 00:00:01 |
|* 18 | TABLE ACCESS BY INDEX ROWID | EPC | 1 | 24 | 1 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | SYS_C0012080 | 1 | | 0 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | EPC | 1 | 120 | 1 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | SYS_C0012080 | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
8 - filter("T4"."MD_ATTRIBUTE_META_ID"='urn:epcglobal:epcis:mda:coun
try')
9 - access("T4"."VALUE"='USA')
10 - filter("T3"."MD_ELEMENT_META_ID"='urn:epcglobal:epcis:vtype:BusinessLo
cation')
11 - access("T3"."MD_ELEMENT_ID"="T4"."PARENT_MD_ELEMENT_ID")
13 - access("T0"."BUSINESS_LOCATION_URI"="T3"."MD_ELEMENT_ID")
14 - filter(("T0"."EVENT_TYPE"='AGGREGATION' OR "T0"."EVENT_TYPE"='TRANSACTION') AND
"T1"."PARENT_EVENT_EPC_ID" IS NOT NULL OR "T0"."EVENT_TYPE"='OBJECT')
15 - access("T0"."EVENT_ID"="T1"."EVENT_ID")
17 - access("T0"."EVENT_ID"="T5"."EVENT_ID")
18 - filter("T2"."COMPANY_PREFIX"='1' AND "T2"."REFERENCE"='1' AND "T2"."SCHEME"='gid')
19 - access("T1"."EPC_ID"="T2"."EPC_ID")
21 - access("T5"."EPC_ID"="T6"."EPC_ID"(+))
46 rows selected.
Explained.
PLAN_TABLE_OUTPUT
Plan hash value: 3062511058
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 7 | 1568 | 38 (6)| 00:00:01 |
| 1 | SORT UNIQUE | | 7 | 1568 | 37 (3)| 00:00:01 |
| 2 | NESTED LOOPS OUTER | | 7 | 1568 | 36 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 7 | 728 | 29 (0)| 00:00:01 |
| 4 | NESTED LOOPS | | 4 | 320 | 17 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 4 | 160 | 13 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID| EPC | 1 | 24 | 10 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN | I_EPC_M_COMPANYPREFIX | 220 | | 3 (0)| 00:00:01 |
| 8 | TABLE ACCESS BY INDEX ROWID| EPCIS_EVENT_EPC | 6 | 96 | 3 (0)| 00:00:01
|* 9 | INDEX RANGE SCAN | I_PCS__PC_EPC_ID | 7 | | 2 (0)| 00:00:01 |
|* 10 | TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT | 1 | 40 | 1 (0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | SYS_C0012082 | 1 | | 0 (0)| 00:00:01 |
| 12 | TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT_EPC | 2 | 48 | 3 (0)| 00:00:01
|* 13 | INDEX RANGE SCAN | I_PCS__PC_EVENT_ID | 2 | | 2 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID | EPC | 1 | 120 | 1 (0)| 00:00:01 |
|* 15 | INDEX UNIQUE SCAN | SYS_C0012080 | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
6 - filter("T2"."REFERENCE"='1' AND "T2"."SCHEME"='gid')
7 - access("T2"."COMPANY_PREFIX"='1')
9 - access("T1"."EPC_ID"="T2"."EPC_ID")
10 - filter(("T0"."BUSINESS_LOCATION_URI"='businesslocation_ADD' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_DELETE' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE1' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE10' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE11' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE12' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE2' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE3' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE4' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE5' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE6' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE7' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE8' OR
"T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE9') AND (("T0"."EVENT_TYPE"='AGGREGATIO
OR "T0"."EVENT_TYPE"='TRANSACTION') AND "T1"."PARENT_EVENT_EPC_ID" IS NOT NULL OR
"T0"."EVENT_TYPE"='OBJECT'))
11 - access("T0"."EVENT_ID"="T1"."EVENT_ID")
13 - access("T0"."EVENT_ID"="T5"."EVENT_ID")
15 - access("T5"."EPC_ID"="T6"."EPC_ID"(+)) -
Slow running query after upgrading to Oracle 10.2.0.4
Hello
I had posted a query in Database Upgrade section , but all in vian as i have had no replies . So i am posing this in general section as i can now confirm with the exact query issue .
1. I upgraded my oracle instance windows 64 bit from 10.2.0.1 to 10.2.0.4
2. All is good except when i use SUM or MAX in queries i get a very slow performance below is the complete example
Your help is much appreciated .
Regards
Harshad
=====================================================================================================
Example.
=====================================================================================================The query runs on a single table of 275,000,000 records, partitioned by Feed_Id in 53 partitions:-
SELECT *
FROM Fact_Life
WHERE Life_Id = 11555269
AND Feed_Id = 2;
This returns 18 rows in sub-second response time.
Explain Plan for it:-
SELECT *
FROM Fact_Life
WHERE Life_Id = 11555269
AND Feed_Id = 2;
Statement Id=3 Type=INDEX
Cost=938 TimeStamp=11-06-09::11::25:55
(1) SELECT STATEMENT ALL_ROWS
Est. Rows: 66 Cost: 940
(4) PARTITION RANGE SINGLE
Est. Rows: 66 Cost: 940
(3) TABLE TABLE ACCESS BY GLOBAL INDEX ROWID RDS.FACT_LIFE [Analyzed]
Blocks: 2,765,931 Est. Rows: 66 of 275,979,985 Cost: 940
(2) INDEX INDEX SKIP SCAN RDS.PIX_FTLE_1 [Analyzed]
Est. Rows: 3 Cost: 938
However, when the query employs an aggregate function:-
SELECT MAX(Cap_Period_Id)
FROM Fact_Life
WHERE Life_Id = 11555269
AND Feed_Id = 2;
This takes anything from 200-400 seconds to return.
Explain plan for it:-
SELECT MAX(CAP_Period_Id)
FROM Fact_Life
WHERE Life_Id = 11555269
AND Feed_Id = 2;
Statement Id=3 Type=PARTITION RANGE
Cost=7 TimeStamp=11-06-09::11::26:50
(1) SELECT STATEMENT ALL_ROWS
Est. Rows: 1 Cost: 7
(5) SORT AGGREGATE
Est. Rows: 1
(4) FIRST ROW
Est. Rows: 66 Cost: 7
(3) PARTITION RANGE SINGLE
Est. Rows: 66 Cost: 7
(2) INDEX INDEX RANGE SCAN (MIN/MAX) RDS.PIX_FTLE_1 [Analyzed]
Est. Rows: 66 Cost: 7
However when the query is run with a different Life_Id for the same partition:-
SELECT MAX(Cap_Period_Id)
FROM Fact_Life
WHERE Life_Id = 11555275
AND Feed_Id = 2;
Returns sub-second.
Explain plan for it:-
SELECT MAX(CAP_Period_Id)
FROM Fact_Life
WHERE Life_Id = 11555275
AND Feed_Id = 2;
Statement Id=3 Type=PARTITION RANGE
Cost=7 TimeStamp=11-06-09::11::29:29
(1) SELECT STATEMENT ALL_ROWS
Est. Rows: 1 Cost: 7
(5) SORT AGGREGATE
Est. Rows: 1
(4) FIRST ROW
Est. Rows: 66 Cost: 7
(3) PARTITION RANGE SINGLE
Est. Rows: 66 Cost: 7
(2) INDEX INDEX RANGE SCAN (MIN/MAX) RDS.PIX_FTLE_1 [Analyzed]
Est. Rows: 66 Cost: 7
Is this a problem with b-tree indexes? The Life_Id is allocated from a sequence and there are 67,535,682 rows in the partition. The stats are up to date.
=====================================================================================================
=====================================================================================================Hello Randolf,
Sorry for the late reply was down with flue and could not mail , as mentioned i below is the DDL for PIX_FTLE_1 & PIX_FTLE_2 . I have used TOAD to extract the script.
As i cant send the both the DDL in single post i will send it in 2 post , There is a limit of 30000 characters in sigle post .
Thanks once again for your help .
Regards
Harshad
CREATE INDEX RDS.PIX_FTLE_1 ON RDS.FACT_LIFE
(FEED_ID, CAP_PERIOD_ID, LIFE_ID, ISO_CURRENCY_ID, LIFE_SCD_ID)
TABLESPACE RDS_TABLESPACE01
INITRANS 2
MAXTRANS 255
LOGGING
GLOBAL PARTITION BY RANGE (FEED_ID) (
PARTITION HA1 VALUES LESS THAN (2)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 1225M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION NU6 VALUES LESS THAN (3)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 2761M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION FP1 VALUES LESS THAN (4)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 971M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION PRU VALUES LESS THAN (5)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 993M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION GAC VALUES LESS THAN (6)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 622M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION NU3 VALUES LESS THAN (7)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 2136M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION LEG VALUES LESS THAN (8)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 847M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RSC VALUES LESS THAN (9)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 144M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SW1 VALUES LESS THAN (10)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 80M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION PRI VALUES LESS THAN (11)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 34M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION BAL VALUES LESS THAN (12)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION NA1 VALUES LESS THAN (13)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION MID VALUES LESS THAN (14)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION EGS VALUES LESS THAN (15)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION ARK VALUES LESS THAN (16)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 1088M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SKA VALUES LESS THAN (17)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 136M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION NU1 VALUES LESS THAN (18)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 196M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SK2 VALUES LESS THAN (19)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 9M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION CU1 VALUES LESS THAN (20)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 11M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION DLI VALUES LESS THAN (21)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION AEG VALUES LESS THAN (22)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION COM VALUES LESS THAN (23)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION CU2 VALUES LESS THAN (24)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION CUL VALUES LESS THAN (25)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION EAG VALUES LESS THAN (26)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION FP2 VALUES LESS THAN (27)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION HAG VALUES LESS THAN (28)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION HAL VALUES LESS THAN (29)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION JRA VALUES LESS THAN (30)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION LEL VALUES LESS THAN (31)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION MGA VALUES LESS THAN (32)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION MGM VALUES LESS THAN (33)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION NU2 VALUES LESS THAN (34)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION PEG VALUES LESS THAN (35)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RLM VALUES LESS THAN (36)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RL2 VALUES LESS THAN (37)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RL3 VALUES LESS THAN (38)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RL4 VALUES LESS THAN (39)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RL5 VALUES LESS THAN (40)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION BG4 VALUES LESS THAN (41)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION BG5 VALUES LESS THAN (42)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RS2 VALUES LESS THAN (43)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RS3 VALUES LESS THAN (44)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION RS4 VALUES LESS THAN (45)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SA1 VALUES LESS THAN (46)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SAF VALUES LESS THAN (47)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SCA VALUES LESS THAN (48)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SL1 VALUES LESS THAN (49)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SL2 VALUES LESS THAN (50)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SPI VALUES LESS THAN (51)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION SWP VALUES LESS THAN (52)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION VDL VALUES LESS THAN (53)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 240M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION ZUR VALUES LESS THAN (54)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION AR3 VALUES LESS THAN (55)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 360M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
PARTITION ZZZ VALUES LESS THAN (MAXVALUE)
NOLOGGING
NOCOMPRESS
TABLESPACE RDS_TABLESPACE01
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
NOPARALLEL; -
Slow running query --General question
This is just a scenario that you may have come across too. For example there is a query (tables and views) that returned data very quickly until yesterday but slowed down today and takes forever. What do you make out of it and why did it run fine until yesterday?
What would you first look at to resolve this?
This only a general scenario. I understand there could be a lot of factors like data loads but i want to know the best approach. Thanks in advance for your answer.
svkFirst thing I would see is the amount of data. How much of data was I querying yesterday, how much of data am I querying today? Is it a possible situation to have a slow query(just by some minutes but not hours and so on)..
Then, I will look at the query execution plan and try to avoid any table scan's or seeks by creating any possible valid indexes over the tables being joined.
Use necessary tables only in the query, remove any unnecessary LEFT join's and use them only if needed..
Remove ORDER BY in the queries. Not using NOT IN or UNION or DISTINCT such kind of operations if permitted.
Avoid any sort of Bookmark lookups..
These are the primary things I would consider to look at when any query is slow, at first...
Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles. -
Hi,
I am having some performance problems on OBIEE dashboards so I am trying to figure out what is going wrong by looking at the query being generated.
I have spent time simplifying the query down to a very basic select statement, and trying to see why it still takes about ~5 seconds to run. See the following explain plan:
SQL> explain plan for
2 select count(distinct CASES_FACT.CASE_KEY) as CASE_COUNT
3 from
4 COMPSTAT_CASES_DIM CASES_DIM /* Dim - COMPSTAT_CASES_DIM */ ,
5 COMPSTAT_CASES_FACT CASES_FACT /* Fact - COMPSTAT_CASES_FACT */
6 where ( CASES_FACT.CASE_KEY = CASES_DIM.CASE_KEY );
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 372393383
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 12 | | 2741 (3)| 00:00:33 |
| 1 | SORT GROUP BY | | 1 | 12 | | | |
|* 2 | HASH JOIN | | 925K| 10M| 15M| 2741 (3)| 00:00:33 |
| 3 | INDEX FAST FULL SCAN| CASE_KEY | 909K| 5327K| | 674 (3)| 00:00:09 |
| 4 | INDEX FAST FULL SCAN| CASES_FACT_IDX4 | 925K| 5421K| | 466 (4)| 00:00:06 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
2 - access("CASES_FACT"."CASE_KEY"="CASES_DIM"."CASE_KEY")
16 rows selected.We have the indexes on the columns being joined on, and it appears to use a fast full scan on that index, but still the query takes about 5 seconds to run, just for this very simple query. When I add the rest of the joins and conditions that are in the actual OBIEE query, it's more like a 15 second query. It needs to be much faster.
Any ideas? Btw I am not a DBA or tuning expert, simply an OBIEE developer that was tasked with fixing this performance.
Thanks.both tables have ~1M rows so no much choice. Assuming the dim table has unique index, nest loop join is usually faster. try the two sql below to see any improvement
select /*+ use_nl(a b) */ count(distinct a.CASE_KEY)
from COMPSTAT_CASES_FACT a,
inner join COMPSTAT_CASES_DIM b on b.CASE_KEY = a.CASE_KEY
select /*+ use_nl(a b) */ count(*)
from (select distinct CASE_KEY from COMPSTAT_CASES_FACT) a
inner join COMPSTAT_CASES_DIM b on b.CASE_KEY = a.CASE_KEY
; -
Slow running query on heavily updating table
Hi,
I am working on a live gps tracking project. The project is using SQL Server 2008 web edition. There are thousands of devices which are sending data packets in every 10 seconds or less depending on various settings to the server. On server there is a tcp
server listener program which reads and parse data and insert it into a "Table-A". Table-A has a trigger which updates Table-B on each insertion (Table-B is used to show live updated status on website). Now Table-A has millions of records per day
and high insertion rate per second.
We also need to show the history reports and other reports using "Table-A". The problem is query on "Table-A" is very slow and affacts the insertion on "Table-A". Please help to overcome this problem.Since there are frequent inserts ,I believe you are selecting records using NOLOCK hint to avoid shared locks.
Niting,
I am pretty much sure in OP scenario NOLOCK will cause blunder. Please don't advise NOLOCK on forum where we have no or minimal information about OP database and infrastructure. Its not a good coding practice.
Your comment to perform regular stats update also does not makes sense, are you sure stats is the issue I can sense some app design problem.
Ganesh,
I guess trigger on Table A is making things slow as it has to complete and I guess this is what taking time , I am not sure.
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
My Technet Wiki Article
MVP -
Need help tuning slow running query
Need help tuning below two Oracle queries:
Query #1:
======================
SELECT "WORK_ORDER_FACT_ALL_YESTERDAY"."WORK_ORDER_HISTORY_ID",
"WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_NUMBER",
"ACCOUNT_DIM"."ACCOUNT_NUMBER", "ACCOUNT_DIM"."ACCOUNT_WS_DISC_DATE"
FROM "CDWD"."WORK_ORDER_FACT_ALL_YESTERDAY" "WORK_ORDER_FACT_ALL_YESTERDAY",
"CDWD"."ACCOUNT_DIM" "ACCOUNT_DIM"
WHERE (SUBSTR ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_FIRST_NAME", 1, 1) =
SUBSTR ("ACCOUNT_DIM"."ACCOUNT_FIRST_NAME", 1, 1)
AND (SUBSTR ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_LAST_NAME", 1, 4) =
SUBSTR ("ACCOUNT_DIM"."ACCOUNT_LAST_NAME", 1, 4)
AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_DL_NUMBER" =
"ACCOUNT_DIM"."ACCOUNT_DL_NUMBER"
AND "WORK_ORDER_FACT_ALL_YESTERDAY"."WO_TYPE_CODE" IN ('25', '27')
AND ("ACCOUNT_DIM"."REVENUE_TYPE_ID" = 1)
AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."TRANSFER_COUNT" = 0)
AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."WINBACK_ADD_COUNT" = 0)
AND ("ACCOUNT_DIM"."ACCOUNT_WS_ENTRY_DATE" <
(TO_DATE ('2006.05.02', 'yyyy.mm.dd') - 11
AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."IS_DERIVED" = 0)
AND ("ACCOUNT_DIM"."EXPIRATION_DATE" IS NULL)
AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACT_ACCOUNT_TYPE_CD" <> '50');
Query #2
==================
UPDATE work_order_fact_all_yesterday g
SET returns_count = 1
WHERE EXISTS (SELECT 1
FROM (SELECT a.phone_dim_key AS transactional_phone_dim_key,
b.mdn_number AS transactional_mdn_number,
b.account_number AS transactional_account_number
FROM work_order_fact_all_yesterday a INNER JOIN phone_dim b ON a.phone_dim_key = b.phone_dim_key
WHERE a.gross_deactivations_count = 1) e
INNER JOIN (SELECT c.phone_dim_key AS historical_phone_dim_key,
d.mdn_number AS historical_mdn_number,
d.account_number AS historical_account_number
FROM (SELECT phone_dim_key
FROM work_order_activity_fact
WHERE gross_adds_count = 1
AND report_date >= :b1 - 66
AND NVL (is_derived, 0 ) = 0
UNION
SELECT phone_dim_key
FROM work_order_fact_all_yesterday
WHERE gross_adds_count = 1
AND is_derived = 0) c
INNER JOIN phone_dim d ON c.phone_dim_key = d.phone_dim_key ) f
ON e.transactional_mdn_number = f.historical_mdn_number
AND e.transactional_account_number = f.historical_account_number
WHERE e.transactional_phone_dim_key = g.phone_dim_key)
AND g.gross_deactivations_count = 1
AND g.account_revenue_type_id = 1;
I ran the DBMS_SQLTUNE on it for 10g and did not get any advice. How can I tune the above queries? Thanks!Tune the SQL? Looking at the join criteria of SUBSTR("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_FIRST_NAME", 1, 1) = SUBSTR ("ACCOUNT_DIM"."ACCOUNT_FIRST_NAME", 1, 1) and other substrings, it seems to me that you have basic flaws in your relation design.
Column must be atomic values. Having to extract a sub-set value from a column to create the intelligence needed to join to another table - that is just plain wrong in relation design. Never mind the performance impact and overheads it causes in the database. -
How to change the explain plan for currently running query?
Hi All,
I am using Oracle enterprise 9i edition. I have a query which frames dynamically and running in the database. I noticed a table with 31147758 rows
in the query which has no indexes and taking more time to process. I tried to create an INdex on that table. I know the query is already running with a FULL table scan. Is it possible to change the explain plan for the current running query to consider the INDEX?
[code]
SELECT /*+ USE_HASH (c,e,b,a) */
d.att_fcc extrt_prod_dim_id,
d.att_fcc compr_prod_dim_id,
a.glbl_uniq_id glbl_uniq_id,
to_date(c.dit_code,'RRRRMMDD')STRT_DT,
(to_date(c.dit_code,'RRRRMMDD')+150)END_DT,
a.pat_nbr pat_id,
a.rxer_id rxer_id,
e.rxer_geog_id rxer_geog_id,
a.pharmy_id pharmy_id,
a.pscr_pack_id pscr_pack_id,
a.dspnsd_pack_id dspnsd_pack_id,
DENSE_RANK () OVER (PARTITION BY a.pat_nbr ORDER BY c.dit_code) daterank,
COUNT( DISTINCT d.att_fcc ) OVER (PARTITION BY a.pat_nbr, c.dit_code) event_cnt
DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
d.att_fcc
ORDER BY c.dit_code) prodrank,
DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
d.att_fcc
ORDER BY c.dit_code DESC) stoprank
FROM
pd_dimitems c,
pd_pack_attribs d ,
lrx_tmp_rxer_geog e,
lrx_tmp_pat_daterank p,
lrx_tmp_valid_fact_link a
WHERE c.dit_id = a.tm_id
AND e.rxer_id = a.rxer_id
AND a.glbl_uniq_id = p.glbl_uniq_id
AND p.daterank > 1
AND a.pscr_pack_id = d.att_dit_id
[/code]
The table lrx_tmp_pat_daterank is having that 31147758 rows. So I am wondering how to make the query to use the newly created index on the table?Why do you think using Indexes will improve the performance of the query? How many rows this query is returning? Optimizer might chose a Full table scan when it finds out that Index plan might not be useful. Why are you using /*+ USE_HASH (c,e,b,a) */ hint? This Hint will force oracle to use Full table scan instead of using the index. Try removing it and see if the plan changes.
Regards, -
I am using SQL Server 2012 (11.0.5058.0) and I am trying to learn Execution Plan Basics. One of the tasks is to run the "Actual Query Plan" by CTRL+M. When I try this nothing happens. I can do the "Display Estimated
Query Plan" and it works. Why can't I do the Actual Query Plan?Hi,
To display Actual Query Plan, you have to execute the query. CTRL+M merely toggles to display Actual Query Plan or not.
See:
Display an Actual Execution Plan
Hope this helps,
~ J. -
How to setup a query plan in effective at any time for SP or SQL query?
I have a SP which include a group by SQL statement. It retrieve data from a couple of tables which are over 1G size,
When I run this SP at first time, it take more than 5 minutes to get the result. then I run it again and again, Finally, it become very quick, I can get the result within second.
Not sure why. I guess it is because of query plan.
How to make it running at first time to get result within second? How to force a better best query plan in effective at first time to run the query?
If the engine has better plan in memory, could it be lost at some point? because I have the complain from end user said some times it is fast, sometime it is very slow.
How to resolve this problem?thanks, kevin. Here is the pesudo query( I modify table name as business rule from my company). you are right, mytab3 is a lookup table.
Select d.stock,i.description,c.categoryname,
Round(IsNull(Sum(d.qty),0),2) AS qty,
From mytab1 d,mytab2 s,invent i,mytab3 c
Where
d.stock != 'param1'
And d.id1 = s.id1 --id1: univarchar(11)
And i.code = c.code --code:univarchar(2)
And d.stock = i.stock --stock: univarchar(12)
And i.code2 = d.code2 --code2: univarchar(2)
And d.code2 = 'param2'
And s.id2 = 'param3' --id2: univarchar(6)
Group By c.categoryname,d.stock,i.description
Order By d.stock
here is the query plan when run this query:
The command completed with no results returned
QUERY PLAN FOR STATEMENT 1 (at line 1).
Executed in parallel by coordinating process and 4 worker processes.
STEP 1
The type of query is SELECT (into Worktable1).
GROUP BY
Evaluate Grouped SUM OR AVERAGE AGGREGATE.
Evaluate Grouped SUM OR AVERAGE AGGREGATE.
Evaluate Grouped SUM OR AVERAGE AGGREGATE.
Executed in parallel by coordinating process and 4 worker processes.
FROM TABLE
mytab2
s
Nested iteration.
Index : ind_mytab2 _id2
Forward scan.
Positioning by key.
Keys are:
id2 ASC
Executed in parallel with a 4-way hash scan.
Using I/O Size 16 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
mytab1
d
Nested iteration.
Index : ind_det_inv
Forward scan.
Positioning by key.
Keys are:
id1 ASC
Using I/O Size 16 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
invent
i
Nested iteration.
Using Clustered Index.
Index : invent_pk
Forward scan.
Positioning by key.
Keys are:
stock ASC
code2 ASC
Using I/O Size 2 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
mytab3
c
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 2 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable1.
Parallel work table merge.
STEP 2
The type of query is INSERT.
The update mode is direct.
Executed by coordinating process.
Worktable2 created, in allpages locking mode, for ORDER BY.
FROM TABLE
Worktable1.
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 8 Kbytes for data pages.
With MRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable2.
STEP 3
The type of query is SELECT.
Executed by coordinating process.
This step involves sorting.
FROM TABLE
Worktable2.
Using GETSORTED
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 8 Kbytes for data pages.
With MRU Buffer Replacement Strategy for data pages.
Total estimated I/O cost for statement 1 (at line 1): 1409882.
The sort for Worktable2 is done in Serial -
Oracle 10g:
I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:
select * from (select * from A where b = 1) where ROWNUM < 1000 becomes very slow:
Query Plan for select * from A where b = 1 (Query is just an example):
Rows Plan
208912 SELECT STATEMENT
208912 SORT ORDER BY
208912 HASH JOIN RIGHT OUTER
408 INDEX FULL SCAN PK_BAD_ACK_TASK
208912 HASH JOIN RIGHT OUTER
16 INDEX FULL SCAN PK_INFORMATIONAL_TASK
208912 HASH JOIN RIGHT OUTER
1 INDEX FULL SCAN PK_SYSTEM_ERROR_TASK
208912 HASH JOIN RIGHT OUTER
1 INDEX FULL SCAN PK_REJECTED_TRANSMISSION
208912 HASH JOIN RIGHT OUTER
1 INDEX FULL SCAN PK_ONHOLD_TASK
208912 HASH JOIN RIGHT OUTER
329465 INDEX FAST FULL SCAN PK_FAILED_MESSAGE
208912 TABLE ACCESS FULL TASK
Query when I add ROWNUM (slow query as mentioned above):
Rows Plan
999 SELECT STATEMENT
<NULL> COUNT STOPKEY
208912 VIEW
208912 SORT ORDER BY STOPKEY
208912 HASH JOIN RIGHT OUTER
408 INDEX FULL SCAN PK_BAD_ACK_TASK
208912 NESTED LOOPS OUTER
208912 NESTED LOOPS OUTER
208912 NESTED LOOPS OUTER
208912 HASH JOIN RIGHT OUTER
329465 INDEX FAST FULL SCAN PK_FAILED_MESSAGE
208912 HASH JOIN RIGHT OUTER
16 INDEX FULL SCAN PK_INFORMATIONAL_TASK
208912 TABLE ACCESS FULL TASK
1 INDEX FAST FULL SCAN PK_ONHOLD_TASK
1 INDEX FAST FULL SCAN PK_REJECTED_TRANSMISSION
1 INDEX FAST FULL SCAN PK_SYSTEM_ERROR_TASKuser628400 wrote:
Oracle 10g:
I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:Some notes:
* When using ROWNUM the cost based optimizer switches to a FIRST_ROWS_N mode, this might explain the significant difference in the execution plan
* Try to get a more meaningful output using DBMS_XPLAN.DISPLAY
* Since you're already on 10g, try to compare the actual cardinalities to the estimates using DBMS_XPLAN.DISPLAY_CURSOR with the "ALLSTATS LAST" option and the GATHER_PLAN_STATISTICS hint.
See e.g. here for more information how to do it: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
This way you should be able to tell where the optimizer assumptions go wrong so that it thinks that the second one is better than the first one
A simple remedy you might want to try that should get you back to plan 1 is the following:
select * from (
select ROWNUM as rn, a.* from (select * from A where b = 1 ORDER BY<your_order_criteria>) a
where rn < 1000;Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Edited by: Randolf Geist on Jan 11, 2009 9:33 PM
Added the obvious sort ORDER BY -
Hi all,
We are using Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production on
Linux 2.6.5-7.282-bigsmp #1 SMP box.
The following query is taking aproximately 1 hr to execute.
SELECT item.ap_id, item.ap_version_id, oa.customer_id,CI.CAPTION OFFER_ID, ITEM.BILL_START_DATE , ITEM.CTDB_CRE_DATETIME , oa.order_unit_id
FROM tbap_item item,
tbprice_plan pp,
tborder_action oa,
tborder_action_impl oaimpl,
TBCATALOG_ITEM CI
WHERE item.entity_type = 'amdocs.oms.sbcproduct.ApPricePlanImpl'
AND item.item_def_id = pp.cid
AND item.item_def_ver = pp.pcversion_id
AND pp.is_promote = '1'
AND item.order_action_id = oa.order_unit_id
AND oa.order_unit_id = oaimpl.order_unit_id
AND oaimpl.bypass_reason_id = 'MI'
AND oa.xml_id IS NOT NULL
AND item.state IN ('AS', 'OR')
AND item.status = 'AC'
AND CI.CID = ITEM.ITEM_DEF_ID
AND CI.PCVERSION_ID = ITEM.ITEM_DEF_VER
AND item.ap_version_id = '0'
AND EXISTS (SELECT 1 FROM TBAP_ITEM TEMP WHERE TEMP.AP_ID = ITEM.AP_ID AND TEMP.END_DATE > SYSDATE AND TEMP.STATE IN ('AS' , 'OR') AND TEMP.STATUS ='AC');
the execution plan before collecting the stats is:
Query Plan
SELECT STATEMENT [CHOOSE] Cost=120002
NESTED LOOPS SEMI Cost=120002 Card=98407 Bytes=18402109
MERGE JOIN Cost=80639 Card=98407 Bytes=16040341
SORT JOIN Cost=80607 Card=98407 Bytes=13481759
MERGE JOIN Cost=78626 Card=98407 Bytes=13481759
SORT JOIN Cost=76699 Card=119937 Bytes=14992125
MERGE JOIN Cost=76699 Card=119937 Bytes=14992125
SORT JOIN Cost=76682 Card=171602 Bytes=19219424
MERGE JOIN Cost=76682 Card=171602 Bytes=19219424
SORT JOIN Cost=74698 Card=990661 Bytes=82224863
TABLE ACCESS FULL TBAP_ITEM [ANALYZED] Cost=62069 Card=990661 Bytes=82224863
SORT JOIN Cost=1985 Card=89365 Bytes=2591585
TABLE ACCESS FULL TBORDER_ACTION [ANALYZED] Cost=1511 Card=89365 Bytes=2591585
SORT JOIN Cost=17 Card=195 Bytes=2535
TABLE ACCESS FULL TBPRICE_PLAN [ANALYZED] Cost=2 Card=195 Bytes=2535
SORT JOIN Cost=1928 Card=73323 Bytes=879876
TABLE ACCESS FULL TBORDER_ACTION_IMPL [ANALYZED] Cost=1698 Card=73323 Bytes=879876
SORT JOIN Cost=33 Card=3017 Bytes=78442
TABLE ACCESS FULL TBCATALOG_ITEM [ANALYZED] Cost=4 Card=3017 Bytes=78442
TABLE ACCESS BY INDEX ROWID TBAP_ITEM [ANALYZED] Cost=1 Card=2037512 Bytes=48900288
INDEX RANGE SCAN TBAP_ITEM_PK [ANALYZED] Cost=2 Card=2 Bytes=
after collecting the stats:
SELECT STATEMENT [CHOOSE] Cost=64972
NESTED LOOPS SEMI Cost=64972 Card=333 Bytes=62937
NESTED LOOPS Cost=64839 Card=333 Bytes=54945
MERGE JOIN Cost=64446 Card=1965 Bytes=300645
SORT JOIN Cost=64414 Card=1965 Bytes=249555
MERGE JOIN Cost=64414 Card=1965 Bytes=249555
SORT JOIN Cost=62429 Card=13393 Bytes=1312514
MERGE JOIN Cost=62429 Card=13393 Bytes=1312514
SORT JOIN Cost=2 Card=140 Bytes=1820
TABLE ACCESS FULL TBPRICE_PLAN [ANALYZED] Cost=2 Card=140 Bytes=1820
SORT JOIN Cost=62428 Card=26785 Bytes=2276725
TABLE ACCESS FULL TBAP_ITEM [ANALYZED] Cost=62072 Card=26785 Bytes=2276725
SORT JOIN Cost=1985 Card=89365 Bytes=2591585
TABLE ACCESS FULL TBORDER_ACTION [ANALYZED] Cost=1511 Card=89365 Bytes=2591585
SORT JOIN Cost=33 Card=3017 Bytes=78442
TABLE ACCESS FULL TBCATALOG_ITEM [ANALYZED] Cost=4 Card=3017 Bytes=78442
TABLE ACCESS BY INDEX ROWID TBORDER_ACTION_IMPL [ANALYZED] Cost=1 Card=1 Bytes=12
INDEX UNIQUE SCAN TBORDER_ACTION_IMPL_PK [ANALYZED] Cost=1 Card=1 Bytes=
TABLE ACCESS BY INDEX ROWID TBAP_ITEM [ANALYZED] Cost=1 Card=2972308 Bytes=71335392
INDEX RANGE SCAN TBAP_ITEM_PK [ANALYZED] Cost=2 Card=2 Bytes=
I am now taking the level 4 trace now.will post it once Its done. I found some "latchfree" timeouts while running it now...
I also find that few cols refered in where clause doesn't have indexes...So I am going to discuss this with the developers. also I want modify the query too..as below.
ELECT item.ap_id, item.ap_version_id, oa.customer_id,CI.CAPTION OFFER_ID, ITEM.BILL_START_DATE , ITEM.CTDB_CRE_DATETIME , oa.order_unit_id
FROM tbap_item item,
tbprice_plan pp,
tborder_action oa,
tborder_action_impl oaimpl,
TBCATALOG_ITEM CI
WHERE
item.entity_type = 'amdocs.oms.sbcproduct.ApPricePlanImpl'
AND item.status = 'AC'
AND item.state IN ('AS', 'OR')
AND item.ap_version_id = '0'
AND pp.is_promote = '1'
AND oaimpl.bypass_reason_id = 'MI'
AND oa.xml_id IS NOT NULL
AND item.item_def_id = pp.cid
AND item.item_def_ver = pp.pcversion_id
AND item.order_action_id = oa.order_unit_id
AND oa.order_unit_id = oaimpl.order_unit_id
AND CI.CID = ITEM.ITEM_DEF_ID
AND CI.PCVERSION_ID = ITEM.ITEM_DEF_VER
AND EXISTS (SELECT 1 FROM TBAP_ITEM TEMP WHERE
TEMP.STATE IN ('AS' , 'OR') AND TEMP.STATUS ='AC' AND TEMP.AP_ID = ITEM.AP_ID AND TEMP.END_DATE > SYSDATE );
Please suggest. what else I need to check to imporve the performace .
Thanks in advace for your help and suggestions.here is formatted one:
call count cpu elapsed disk query current rows
Parse 1 0.14 0.19 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 8 58.21 4169.28 1663901 1699503 10 103
total 10 58.36 4169.47 1663901 1699503 10 103
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 139
Rows Row Source Operation
103 NESTED LOOPS SEMI
158 NESTED LOOPS
3613 MERGE JOIN
3613 SORT JOIN
3613 MERGE JOIN
110996 SORT JOIN
110996 MERGE JOIN
195 SORT JOIN
195 TABLE ACCESS FULL OBJ#(33959)
110996 SORT JOIN
820046 TABLE ACCESS FULL OBJ#(33563)
3613 SORT JOIN
89365 TABLE ACCESS FULL OBJ#(33538)
3613 SORT JOIN
3017 TABLE ACCESS FULL OBJ#(33889)
158 TABLE ACCESS BY INDEX ROWID OBJ#(33534)
3613 INDEX UNIQUE SCAN OBJ#(33645) (object id 33645)
103 TABLE ACCESS BY INDEX ROWID OBJ#(33563)
275 INDEX RANGE SCAN OBJ#(48320) (object id 48320)
******************************************************************************** -
We are getting multiple 8623 Errors in SQL Log while running Vendor's software.
How can you catch which Query causes the error?
I tried to catch it using SQL Profiler Trace but it doesn't show which Query/Sp is the one causing an error.
I also tried to use Extended Event session to catch it, but it doesn't create any output either.
Error:
The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that
reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.
Extended Event Session that I used;
CREATE EVENT SESSION
overly_complex_queries
ON SERVER
ADD EVENT sqlserver.error_reported
ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.username)
WHERE ([severity] = 16
AND [error_number] = 8623)
ADD TARGET package0.asynchronous_file_target
(SET filename = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xel' ,
metadatafile = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xem',
max_file_size = 10,
max_rollover_files = 5)
WITH (MAX_DISPATCH_LATENCY = 5SECONDS)
GO
-- Start the session
ALTER EVENT SESSION overly_complex_queries
ON SERVER STATE = START
GO
It creates only .xel file, but not .xem
Any help/advice is greatly appreciatedHi VK_DBA,
According to your error message, about which query statement may fail with error message 8623, as other post, you can use trace flag 4102 & 4118 for overcoming this error. Another way is looking for queries with very long IN lists, a large number of
UNIONs, or a large number of nested sub-queries. These are the most common causes of this particular error message.
The error 8623 occurs when attempting to select records through a query with a large number of entries in the "IN" clause (> 10,000). For avoiding this error, I suggest that you could apply the latest Cumulative Updates media for SQL Server 2012 Service
Pack 1, then simplify the query. You may try divide and conquer approach to get part of the query working (as temp table) and then add extra joins / conditions. Or You could try to run the query using the hint option (force order), option (hash join), option
(merge join) with a plan guide.
For more information about error 8623, you can review the following article.
http://blogs.technet.com/b/mdegre/archive/2012/03/13/8623-the-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan.aspx
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support -
Long running query--- included steps given by Randolf
Hi,
I have done my best to follow Randolf instruction word-by-word and hope to get solution for my
problem soon. Sometime back I have posted a thread on this problem then got busy with other
stuff and was not able to follow it. Here I am again with same issue.
here is link for my previous post
long running query in database 10gHere is backgroud of my requriemment.
I am working on Oracle forms 10g which is using package given below. We want to display client information
with order count basd on different status like Pending, Error, back Order, expedited, std shipping.
Output will look something like.
client name pending error backorder expedited std shipping
ABC 24 0 674 6789 78900
XYZ 35 673 5700 0 798274
.There are total 40 clients . The long running query are expedited and std shipping.
When i run package from Oracle Form Developer it takes 3 mintues to run but when I run same query in our application using forms
(which uses Oracle Application Server) it takes around 1 hour, which is completly unacceptable.
User wants it be done in less than 1 mintue.
I have tried combining Pending,error and backorder queries together but as far as I know it will not
work in Oracle Form as we need a place holder for each status.
Please dont think it is Forms related question, it is a Performance problem.
PACKAGE BODY ORDER_COUNT_PKG IS
PROCEDURE post_query IS
BEGIN
BEGIN
SELECT count(*)
INTO :ORDER_STATUS.PENDING
FROM orders o
WHERE o.status = 'P'
AND (parent_order_id is null
OR (order_type='G'
AND parent_order_id=original_order_number))
AND o.client = :ORDER_STATUS.CLIENT_NUMBER;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
SELECT count(*)
INTO :ORDER_STATUS.ERROR
FROM orders o
WHERE o.status = 'E'
AND (parent_order_id is null
OR (order_type='G'
AND parent_order_id=original_order_number))
AND o.client = :ORDER_STATUS.CLIENT_NUMBER;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
SELECT count(*)
INTO :ORDER_STATUS.BACK_ORDER
FROM orders o
WHERE o.status = 'B'
AND (parent_order_id is null
OR (order_type='G'
AND parent_order_id=original_order_number))
AND o.client = :ORDER_STATUS.CLIENT_NUMBER;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
SELECT count(*)
INTO :ORDER_STATUS.EXPEDITE
FROM orders o,shipment_type_methods stm
WHERE o.status in ('A','U')
AND (o.parent_order_id is null
OR (o.order_type = 'G'
AND o.parent_order_id = o.original_order_number))
AND o.client = stm.client
AND o.shipment_class_code = stm.shipment_class_code
AND (nvl(o.priority,'1') = '2'
OR stm.surcharge_amount <> 0)
AND o.client = :ORDER_STATUS.CLIENT_NUMBER
GROUP BY o.client;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
SELECT count(*)
INTO :ORDER_STATUS.STD_SHIP
FROM orders o,shipment_type_methods stm
WHERE o.status in ('A','U')
AND (o.parent_order_id is null
OR (o.order_type = 'G'
AND o.parent_order_id = o.original_order_number))
AND nvl(o.priority,'1') <> '2'
AND o.client = stm.client
AND o.shipment_class_code = stm.shipment_class_code
AND stm.surcharge_amount = 0
AND o.client = :ORDER_STATUS.CLIENT_NUMBER
GROUP BY o.client;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END post_query;
END ORDER_COUNT_PKG;one of the query which is taking long time is
SELECT count(*)
FROM orders o,shipment_type_methods stm
WHERE o.status in ('A','U')
AND (o.parent_order_id is null
OR (o.order_type = 'G'
AND o.parent_order_id = o.original_order_number))
AND nvl(o.priority,'1') <> '2'
AND o.client = stm.client
AND o.shipment_class_code = stm.shipment_class_code
AND stm.surcharge_amount = 0
AND o.client = :CLIENT_NUMBER
GROUP BY o.clientThe version of the database is 10.2.1.0.2
SQL> alter session force parallel dml;These are the parameters relevant to the optimizer:
SQL> show parameter user_dump_dest
NAME TYPE VALUE
user_dump_dest string /u01/app/oracle/admin/mcgemqa/
udump
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.4
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 16
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 EXACTHere is the output of EXPLAIN PLAN:
SQL> explain plan for
2 SELECT count(*)
3 FROM orders o,shipment_type_methods stm
4 WHERE o.status in ('A','U')
5 AND (o.parent_order_id is null
6 OR (o.order_type = 'G'
7 AND o.parent_order_id = o.original_order_number))
8 AND nvl(o.priority,'1') <> '2'
9 AND o.client = stm.client
10 AND o.shipment_class_code = stm.shipment_class_code
11 AND stm.surcharge_amount = 0
12 AND o.client = :CLIENT_NUMBER
13 GROUP BY o.client
14 /
Explained.
Elapsed: 00:00:00.12
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 559278019
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 35 | 46764 (3)| 00:09:22 |
| 1 | SORT GROUP BY NOSORT | | 1 | 35 | 46764 (3)| 00:09:22 |
|* 2 | TABLE ACCESS BY INDEX ROWID | ORDERS | 175K| 3431K| 25979 (3)| 00:05:12 |
| 3 | NESTED LOOPS | | 25300 | 864K| 46764 (3)| 00:09:22 |
|* 4 | TABLE ACCESS BY INDEX ROWID| SHIPMENT_TYPE_METHODS | 1 | 15 | 2 (0)| 00:00
|* 5 | INDEX RANGE SCAN | U_SHIPMENT_TYPE_METHODS | 2 | | 1 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | ORDERS_ORDER_DATE | 176K| | 2371 (8)| 00:00:29 |
Predicate Information (identified by operation id):
2 - filter(("O"."PARENT_ORDER_ID" IS NULL OR "O"."ORDER_TYPE"='G' AND
"O"."PARENT_ORDER_ID"=TO_NUMBER("O"."ORIGINAL_ORDER_NUMBER")) AND NVL("O"."PRIORITY",'1')<>'2
AND "O"."SHIPMENT_CLASS_CODE"="STM"."SHIPMENT_CLASS_CODE")
4 - filter("STM"."SURCHARGE_AMOUNT"=0)
5 - access("STM"."CLIENT"=:CLIENT_NUMBER)
6 - access("O"."CLIENT"=:CLIENT_NUMBER)
filter("O"."STATUS"='A' OR "O"."STATUS"='U')
24 rows selected.
Elapsed: 00:00:00.86
SQL> rollback;
Rollback complete.
Elapsed: 00:00:00.07Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
SQL> SELECT count(*)
2 FROM orders o,shipment_type_methods stm
3 WHERE o.status in ('A','U')
4 AND (o.parent_order_id is null
5 OR (o.order_type = 'G'
6 AND o.parent_order_id = o.original_order_number))
7 AND nvl(o.priority,'1') <> '2'
8 AND o.client = stm.client
9 AND o.shipment_class_code = stm.shipment_class_code
10 AND stm.surcharge_amount = 0
11 AND o.client = :CLIENT_NUMBER
12 GROUP BY o.client
13 /
Elapsed: 00:00:03.09
Execution Plan
Plan hash value: 559278019
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 35 | 46764 (3)| 00:09:22 |
| 1 | SORT GROUP BY NOSORT | | 1 | 35 | 46764 (3)| 00:09:22 |
|* 2 | TABLE ACCESS BY INDEX ROWID | ORDERS | 175K| 3431K| 25979 (3)| 00:05:12 |
| 3 | NESTED LOOPS | | 25300 | 864K| 46764 (3)| 00:09:22 |
|* 4 | TABLE ACCESS BY INDEX ROWID| SHIPMENT_TYPE_METHODS | 1 | 15 | 2 (0)| 00:00
|* 5 | INDEX RANGE SCAN | U_SHIPMENT_TYPE_METHODS | 2 | | 1 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | ORDERS_ORDER_DATE | 176K| | 2371 (8)| 00:00:29 |
Predicate Information (identified by operation id):
2 - filter(("O"."PARENT_ORDER_ID" IS NULL OR "O"."ORDER_TYPE"='G' AND
"O"."PARENT_ORDER_ID"=TO_NUMBER("O"."ORIGINAL_ORDER_NUMBER")) AND NVL("O"."PRIORITY",'1')<>'2
AND "O"."SHIPMENT_CLASS_CODE"="STM"."SHIPMENT_CLASS_CODE")
4 - filter("STM"."SURCHARGE_AMOUNT"=0)
5 - access("STM"."CLIENT"=:CLIENT_NUMBER)
6 - access("O"."CLIENT"=:CLIENT_NUMBER)
filter("O"."STATUS"='A' OR "O"."STATUS"='U')
Statistics
55 recursive calls
0 db block gets
7045 consistent gets
0 physical reads
0 redo size
206 bytes sent via SQL*Net to client
238 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> The TKPROF output for this statement looks like the following:
SELECT count(*)
FROM orders o,shipment_type_methods stm
WHERE o.status in ('A','U')
AND (o.parent_order_id is null
OR (o.order_type = 'G'
AND o.parent_order_id = o.original_order_number))
AND nvl(o.priority,'1') <> '2'
AND o.client = stm.client
AND o.shipment_class_code = stm.shipment_class_code
AND stm.surcharge_amount = 0
AND o.client = :CLIENT_NUMBER
GROUP BY o.client
call count cpu elapsed disk query current rows
Parse 1 0.01 0.00 0 0 0 0
Execute 1 0.04 0.04 0 0 0 0
Fetch 2 2.96 2.91 0 7039 0 1
total 4 3.01 2.95 0 7039 0 1
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 95
Rows Row Source Operation
1 SORT GROUP BY NOSORT (cr=7039 pr=0 pw=0 time=2913701 us)
91 TABLE ACCESS BY INDEX ROWID ORDERS (cr=7039 pr=0 pw=0 time=261997906 us)
93 NESTED LOOPS (cr=6976 pr=0 pw=0 time=20740 us)
1 TABLE ACCESS BY INDEX ROWID SHIPMENT_TYPE_METHODS (cr=2 pr=0 pw=0 time=208 us)
3 INDEX RANGE SCAN U_SHIPMENT_TYPE_METHODS (cr=1 pr=0 pw=0 time=88 us)(object id 81957)
91 INDEX RANGE SCAN ORDERS_ORDER_DATE (cr=6974 pr=0 pw=0 time=70 us)(object id 81547)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 0.02 0.02
********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
SQL> variable CLIENT_NUMBER varchar2(20)
SQL> exec :CLIENT_NUMBER := '14'
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.06
SQL> SELECT /*+ gather_plan_statistics */ count(*)
2 FROM orders o,shipment_type_methods stm
3 WHERE o.status in ('A','U')
4 AND (o.parent_order_id is null
5 OR (o.order_type = 'G'
6 AND o.parent_order_id = o.original_order_number))
7 AND nvl(o.priority,'1') <> '2'
8 AND o.client = stm.client
9 AND o.shipment_class_code = stm.shipment_class_code
10 AND stm.surcharge_amount = 0
11 AND o.client = :CLIENT_NUMBER
12 GROUP BY o.client
13 /
COUNT(*)
91
Elapsed: 00:00:02.85
SQL> set termout on
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 4nfj368y8w6a3, child number 0
SELECT /*+ gather_plan_statistics */ count(*) FROM orders o,shipment_type_methods stm WHERE
o.status in ('A','U') AND (o.parent_order_id is null OR (o.order_type = 'G'
AND o.parent_order_id = o.original_order_number)) AND nvl(o.priority,'1') <> '2' AND
o.client = stm.client AND o.shipment_class_code = stm.shipment_class_code AND
stm.surcharge_amount = 0 AND o.client = :CLIENT_NUMBER GROUP BY o.client
Plan hash value: 559278019
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | SORT GROUP BY NOSORT | | 1 | 1 | 1 |00:00:02.63 | 7039 |
|* 2 | TABLE ACCESS BY INDEX ROWID | ORDERS | 1 | 175K| 91 |00:03:56.87 | 7039 |
| 3 | NESTED LOOPS | | 1 | 25300 | 93 |00:00:00.02 | 6976 |
|* 4 | TABLE ACCESS BY INDEX ROWID| SHIPMENT_TYPE_METHODS | 1 | 1 | 1 |00:00:00.01 | 2 |
|* 5 | INDEX RANGE SCAN | U_SHIPMENT_TYPE_METHODS | 1 | 2 | 3 |00:00:00.01 | 1 |
|* 6 | INDEX RANGE SCAN | ORDERS_ORDER_DATE | 1 | 176K| 91 |00:00:00.01 | 6974 |
Predicate Information (identified by operation id):
2 - filter((("O"."PARENT_ORDER_ID" IS NULL OR ("O"."ORDER_TYPE"='G' AND
"O"."PARENT_ORDER_ID"=TO_NUMBER("O"."ORIGINAL_ORDER_NUMBER"))) AND NVL("O"."PRIORITY",'1')<>'
"O"."SHIPMENT_CLASS_CODE"="STM"."SHIPMENT_CLASS_CODE"))
4 - filter("STM"."SURCHARGE_AMOUNT"=0)
5 - access("STM"."CLIENT"=:CLIENT_NUMBER)
6 - access("O"."CLIENT"=:CLIENT_NUMBER)
filter(("O"."STATUS"='A' OR "O"."STATUS"='U'))
32 rows selected.
Elapsed: 00:00:01.30
SQL> I'm looking forward for suggestions how to improve the performance of this statement.
Thanks
SandyPlease find explain plan for No hint
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 559278019
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 35 | 46764 (3)| 00:09:22 |
| 1 | SORT GROUP BY NOSORT | | 1 | 35 | 46764 (3)| 00:09:22 |
|* 2 | TABLE ACCESS BY INDEX ROWID | ORDERS | 175K| 3431K| 25979 (3)| 00:05:12 |
| 3 | NESTED LOOPS | | 25300 | 864K| 46764 (3)| 00:09:22 |
|* 4 | TABLE ACCESS BY INDEX ROWID| SHIPMENT_TYPE_METHODS | 1 | 15 | 2 (0)| 00:00
|* 5 | INDEX RANGE SCAN | U_SHIPMENT_TYPE_METHODS | 2 | | 1 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | ORDERS_ORDER_DATE | 176K| | 2371 (8)| 00:00:29 |
Predicate Information (identified by operation id):
2 - filter(("O"."PARENT_ORDER_ID" IS NULL OR "O"."ORDER_TYPE"='G' AND
"O"."PARENT_ORDER_ID"=TO_NUMBER("O"."ORIGINAL_ORDER_NUMBER")) AND NVL("O"."PRIORITY",'1')<>'2
AND "O"."SHIPMENT_CLASS_CODE"="STM"."SHIPMENT_CLASS_CODE")
4 - filter("STM"."SURCHARGE_AMOUNT"=0)
5 - access("STM"."CLIENT"=:CLIENT_NUMBER)
6 - access("O"."CLIENT"=:CLIENT_NUMBER)
filter("O"."STATUS"='A' OR "O"."STATUS"='U')
24 rows selected.
Elapsed: 00:00:00.86Explain Plan for Parallel Hint
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 559278019
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 35 | 46764 (3)| 00:09:22 |
| 1 | SORT GROUP BY NOSORT | | 1 | 35 | 46764 (3)| 00:09:22 |
|* 2 | TABLE ACCESS BY INDEX ROWID | ORDERS | 175K| 3431K| 25979 (3)| 00:05:12 |
| 3 | NESTED LOOPS | | 25300 | 864K| 46764 (3)| 00:09:22 |
|* 4 | TABLE ACCESS BY INDEX ROWID| SHIPMENT_TYPE_METHODS | 1 | 15 | 2 (0)| 00:00
|* 5 | INDEX RANGE SCAN | U_SHIPMENT_TYPE_METHODS | 2 | | 1 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | ORDERS_ORDER_DATE | 176K| | 2371 (8)| 00:00:29 |
Predicate Information (identified by operation id):
2 - filter(("O"."PARENT_ORDER_ID" IS NULL OR "O"."ORDER_TYPE"='G' AND
"O"."PARENT_ORDER_ID"=TO_NUMBER("O"."ORIGINAL_ORDER_NUMBER")) AND NVL("O"."PRIORITY",'1')<>'2
AND "O"."SHIPMENT_CLASS_CODE"="STM"."SHIPMENT_CLASS_CODE")
4 - filter("STM"."SURCHARGE_AMOUNT"=0)
5 - access("STM"."CLIENT"='14')
6 - access("O"."CLIENT"='14')
filter("O"."STATUS"='A' OR "O"."STATUS"='U')
24 rows selected.
Elapsed: 00:00:08.92Explain Plan for USE_Hash hint
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1465232248
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 35 | 46786 (3)| 00:09:22 |
| 1 | SORT GROUP BY NOSORT | | 1 | 35 | 46786 (3)| 00:09:22 |
|* 2 | HASH JOIN | | 25300 | 864K| 46786 (3)| 00:09:22 |
|* 3 | TABLE ACCESS BY INDEX ROWID| SHIPMENT_TYPE_METHODS | 1 | 15 | 2 (0)| 00:00:0
|* 4 | INDEX RANGE SCAN | U_SHIPMENT_TYPE_METHODS | 2 | | 1 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID| ORDERS | 175K| 3431K| 46763 (3)| 00:09:22 |
|* 6 | INDEX RANGE SCAN | ORDERS_ORDER_DATE | 176K| | 4268 (8)| 00:00:52 |
Predicate Information (identified by operation id):
2 - access("O"."CLIENT"="STM"."CLIENT" AND "O"."SHIPMENT_CLASS_CODE"="STM"."SHIPMENT_CLASS_COD
E")
3 - filter("STM"."SURCHARGE_AMOUNT"=0)
4 - access("STM"."CLIENT"='14')
5 - filter(("O"."PARENT_ORDER_ID" IS NULL OR "O"."ORDER_TYPE"='G' AND
"O"."PARENT_ORDER_ID"=TO_NUMBER("O"."ORIGINAL_ORDER_NUMBER")) AND NVL("O"."PRIORITY",'1')<>'2
6 - access("O"."CLIENT"='14')
filter("O"."STATUS"='A' OR "O"."STATUS"='U')
25 rows selected.
Elapsed: 00:00:01.09
SQL> Thanks
Sandy -
Select Query Hangs / No DB Locks / Query Plan is good
I have below query in application which hangs ( Only sometimes ) and there are some session which also try to insert data into this tables also starts getting hanged.
SELECT DISTINCT F2 || ' - ' || F3 || ' - ' || F4
FROM Table1
WHERE F4 = 6160
AND F1|| F2|| F3 NOT IN (
SELECT F2|| F3 || F4
FROM Table2
WHERE F1 = 181)
F2 - varchar(4)
F3- varchar(100)
F4- varchar(20)
F1,F1 are NUMBER
Table1 has one unique index comprising all fields in ORDER F1,F2, X,F3, F4,Y - X,Y are some different field.
Table2 has one unique index comprising all fields in ORDER F1,F3, F4,F2 are some different field.
Below are facts from DBA ----
1- Session Query Plan was excellent -
2 - No tables were locked in DB
3 - Statistics on this table Table1 was calculated on Feb, 2008 and shows 8 millions rows but actual current row count is 13 million. DBA says sometime analyzing statistics again may cause poor query performance.
4- There were 8 session in DB, 1 was for above select statement and other 7 were trying to insert data into above table.
Can you please advise what could else be verified to root cause issue as it has been hanging many times - hence causing other session to hang ?
Many ThanksCan you clarify exactly what the DBA meant by "No tables were locked in DB"? What was the exact query that was used to determine this? Was it hitting V$LOCK (GV$LOCK in a RAC system)? Or the DBA_BLOCKERS and DBA_WAITERS tables? Or something else? The specific query here is important because there is a world of difference between a row-level lock and a table-level lock. Of course, locks would never prevent a SELECT statement from running, but it could cause problems for the INSERT statements.
I strongly concur with Old DBA's suggestion about refactoring the query to not do the concatenation in the NOT IN clause.
Are the F4 = 6160 and F1 = 181 conditions really using hard-coded numeric literals? Or are these bind variables? Is the data in F1 or F4 skewed-- that is, are there certain values that are more likely than other values?
How many rows would you expect to be in Table1 with an F4 value of 6160? How many rows in Table2 with a F1 value of 181?
Justin
Maybe you are looking for
-
All, If this isn't the best forum to post in, please let me know. I am having an issue when I accept calendar invites in the native/modern application for calendaring in Win 8.1. Whenever I then go back to open and view the contents of a meeting, all
-
How to pass parameter in Discoverer inner query PLZ give solution-URGENT
Hi All, My need is I have a query in Disco Admin which has inner query as mention below: select Net_Drawn_Amount,Undrawn_Amount,Business_Date from (select * from t_FacilityExtract) A, We are creating a workbook using Diso Plus and creating a paramete
-
Is there a way to batch delete voicemails?
Hi everyone, I have a Droid Razr M and I love it. I am TERRIBLE at listening to voice mails and I want to just delete all the ones I have sitting in there. Is there a way to mass delete voicemails? Thanks everyone!
-
How does one select the language of a piece of text in Pages 5
I often work with multipel language in one document. In the pre version 5 Pages one could select the text and go in inspector and change the language. Not very handy, MS Word is always been much better at this. Even WordPerfect 1.0 was better. But in
-
Backing everything up over IP and not WiFi?
Is there someway to use a external hard drive or Apple Time Capsule with Time Machine when I am not at home using my WiFi network? Maybe I am on vacation and I want to backup everything over IP to my home Time Capsule or external drive. Thanks.