Union All query help
Hi,
I have a union all query like this :
select a.prod_id,count(a.app_id) as noofapplications from enrollment a,attest b
where a.e_id=b.e_id group by a.prod_id
union all
select a.prod_id,count(a.app_id) as noofapplications from data_feed x,prod_feed y
where x.agent_num=y.prod_id group by y.prod_id
I get the results something like this :
prod_id noofapplications
x1824787 2
y397458 4
y397458 3
r457868 3
i876247 6
In below results y397458 is showing twice since it results from both the queries .But i want a single result like this :
prod_id noofapplications
x1824787 2
y397458 7
r457868 3
i876247 6
For y397458 it should add 4+3 and the result should be displayed one time only .
Please help ..
Thanks in Advance
Slightly reorder your query text:
select prod_id,count(app_id) as noofapplications
from
select a.prod_id,a.app_id
from enrollment a,attest b
where a.e_id=b.e_id
union all
select a.prod_id,a.app_id
from data_feed x,prod_feed y
where x.agent_num=y.prod_id
group by prod_id
/
Similar Messages
-
Hi,
Is Order by in Union ALL query allowed? If not what is the solution while using Unoin ALL?
thxWhat isn't working? These are all OK:
SELECT dummy FROM dual
UNION ALL
SELECT dummy FROM dual
ORDER BY dummy;
SELECT dummy FROM dual
UNION ALL
SELECT dummy FROM dual
ORDER BY 1;
SELECT dummy AS c1 FROM dual
UNION ALL
SELECT dummy FROM dual
ORDER BY c1;The name used in the ORDER BY clause has to be one of the names in the first SELECT list, or a number. -
Help : UNION ALL Query tuning
Hi all,
I want to fetch records from mview m_view1 joining the columns in table1 and table2.
select mv1.col1,mv2.col2.., from mview1 mv1
where mv1.col1 in (
SELECT t1.col1
FROM table1 t1
WHERE t1.col2 = SUBSTR(user,3)
UNION ALL
SELECT t2.col1
FROM table2 t2
WHERE t2.col2 = SUBSTR(user,3)
UNION ALL
SELECT t1.col1
FROM table1 t1, table2 t2
WHERE t2.col2 = SUBSTR(user,3)
AND t2.col1 = t1.col2
Below is the explain plan I got :
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 616 | 2690 (1)| 00:00:33 |
| 1 | NESTED LOOPS | | 1 | 616 | 2690 (1)| 00:00:33 |
| 2 | VIEW | VW_NSO_1 | 2657 | 34541 | 30 (0)| 00:00:01 |
| 3 | HASH UNIQUE | | 2657 | 61164 | 30 (90)| 00:00:01 |
| 4 | UNION-ALL | | | | | |
|* 5 | INDEX RANGE SCAN | table1_indx1 | 176 | 1760 | 3 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | table2_prim1 | 14 | 196 | 2 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 2467 | 59208 | 25 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | table2_prim1 | 14 | 196 | 2 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | table1_indx2 | 176 | 1760 | 2 (0)| 00:00:01 |
|* 10 | MAT_VIEW ACCESS BY INDEX ROWID| mview1 | 1 | 603 | 1 (0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | indx1 | 1 | | 0 (0)| 00:00:01 |
table1_indx2 - index on col1 & col2 of table1.
table1_indx1 - index on col1 & col2 & col3 of table1.
Im new to oracle tuning. Could you please help me in tuning this.
Thanks in advance.Hi Rob,
Given below the explain plan for the same:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 616 | 2690 (1)| 00:00:33 |
| 1 | NESTED LOOPS | | 1 | 616 | 2690 (1)| 00:00:33 |
| 2 | VIEW | VW_NSO_1 | 2657 | 34541 | 30 (0)| 00:00:01 |
| 3 | HASH UNIQUE | | 2657 | 61164 | 30 (90)| 00:00:01 |
| 4 | UNION-ALL | | | | | |
|* 5 | INDEX RANGE SCAN | table1_indx1 | 176 | 1760 | 3 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | table2_prim1 | 14 | 196 | 2 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 2467 | 59208 | 25 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | table2_prim1 | 14 | 196 | 2 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | table1_indx2 | 176 | 1760 | 2 (0)| 00:00:01 |
|* 10 | MAT_VIEW ACCESS BY INDEX ROWID| mview1 | 1 | 603 | 1 (0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | indx1 | 1 | | 0 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------ -
Error while executing UNION ALL query
Hello everyone,
I'm executing the below query on Oracle 9.2.0.8 version.
select hdr.*
from ttl_hdr hdr, ttl_service ser
where hdr.cus_nbr = ser.cus_nbr
and hdr.dn in ('1232','2342',343','343')
union all
select hdr.*
from ttl_hdr_his hdr, ttl_service ser
where hdr.cus_nbr = ser.cus_nbr
and hdr.dn in ('1232','2342',343','343')
and I encounter following error:
ORA-01790: expression must have same datatype as corresponding expression
But instead of * if I'm specifying a list of few columns, it executes the query properly.
Can anybody tell me what the problem is ?
regards,
RossyHi,
All columns in your tables TTL_HDR and TTL_HDR_HIS are not with same data type.
I'm sure you get same error if you specify all columns that * brings.
Specify column names and use conversion function to get data type same to column from both selects.
PS: and I think this is not Application Express related
Br, Jari -
Is the order in which a UNION ALL query returns rows guaranteed?
Guys
I'm doing a kind of query where I want to return matching rows in a priority order and take the first one. THink of it as getting the most specific error message for a particular context.
SELECT * FROM (
SELECT msg FROM errormessages WHERE device = 'x'
UNION ALL
SELECT msg FROM errormessages WHERE client = 'y'
UNION ALL
SELECT msg FROM (SELECT msg from errormessages WHERE class LIKE 'generic_' ORDER BY class)
UNION ALL
SELECT 'missing error message' FROM dual
WHERE ROWNUM =1
If UNION ALL is guaranteed to return rows in this order, great. If not, would it be better to have:
SELECT * FROM ( SELECT * FROM(
SELECT 1 as ord, msg FROM errormessages WHERE device = 'x'
UNION ALL
SELECT 2, msg FROM errormessages WHERE client = 'y'
UNION ALL
SELECT 4+SUBSTR(class, 7, 1), msg FROM errormessages WHERE class LIKE 'generic_'
UNION ALL
SELECT 9999, 'missing error message' FROM dual
) ORDER BY ord )
WHERE ROWNUM =1Or, another option:
SELECT msg FROM(
SELECT
CASE
WHEN device = 'x' THEN 1
WHEN client = 'y' THEN 2
WHEN class LIKE 'generic_' THEN 4+SUBSTR(class, 7, 1)
END as ord, msg
FROM (
SELECT * FROM errormessages WHERE device = 'x' OR client = 'y' OR class LIKE 'generic_'
UNION ALL
SELECT 999, 'missing error' FROM dual
) ORDER BY ord
)WHERE ROWNUM =1As you can see there is a complication in the generic; devices may advertise that they accept 1,2,3 or 4 lines of info, so I want to use the advertised capabiltiy to pick the most relevant message from the generic set if no specifics exist for the device or the client
Which was would you go?
Cheers
Edited by: charred on Feb 11, 2009 4:56 AM - code tagscharred wrote:
So tell me guys, do I go for:
4 queries unioned together
or
1 query with 4 ORs in the where clause and a case when to determine priority?It will depend on your conditions, but if you look at your explain plans you should get an idea for which is the better one; typically I would expect this to be the OR method...
SQL> select * from emp where deptno = 20
2 union all
3 select * from emp where job = 'CLERK'
4 union all
5 select * from emp where sal > 2500;
Execution Plan
Plan hash value: 3153085224
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 8 (75)| 00:00:01 |
| 1 | UNION-ALL | | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 195 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | DEPT_IDX | 5 | | 1 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | EMP | 4 | 156 | 3 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | EMP | 5 | 195 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("DEPTNO"=20)
4 - filter("JOB"='CLERK')
5 - filter("SAL">2500)
Statistics
1 recursive calls
0 db block gets
18 consistent gets
1 physical reads
0 redo size
1328 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14 rows processed
SQL> select * from emp
2 where deptno = 20 or job = 'CLERK' or sal > 2500;
Execution Plan
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10 | 390 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 10 | 390 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DEPTNO"=20 OR "SAL">2500 OR "JOB"='CLERK')
Statistics
1 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
1146 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
SQL> -
Date table accross the year with a union all query
Hi
I'm trying to create a table in SQL that will show the Output Values acrross the year.
I'm basically trying to change a date range of BETWEEN '2014-01-01' AND '2014-01-30' as Jan show the Columns look like the below.
Jan
Feb
March
April
May
June
July
121
12
154
78
21
32
21
SELECT count(distinct [Form Number]) as Starts
FROM dbo.WATP
WHERE [Cohort Desc] IN ('BBC APPs', 'ETP', 'Foundation Learning', 'WBL Scheme')
AND [Episode Start] BETWEEN '2014-01-01' AND '2014-01-30'
UNION ALL
SELECT count(distinct [Form Number]) as Starts
FROM dbo.WATP
WHERE [Cohort Desc] IN ('BBC APPs', 'ETP', 'Foundation Learning', 'WBL Scheme')
AND [Episode Start] BETWEEN '2014-02-01' AND '2014-02-28'
UNION ALL
SELECT count(distinct [Form Number]) as Starts
FROM dbo.WATP
WHERE [Cohort Desc] IN ('BBC APPs', 'ETP', 'Foundation Learning', 'WBL Scheme')
AND [Episode Start] BETWEEN '2014-03-01' AND '2014-02-30'
UNION ALL
SELECT count(distinct [Form Number]) as Starts
FROM dbo.WATP
WHERE [Cohort Desc] IN ('BBC APPs', 'ETP', 'Foundation Learning', 'WBL Scheme')
AND [Episode Start] BETWEEN '2014-04-01' AND '2014-04-30'
Hope you can help,
SIIOBIIBYou can simplify that, like this:
DECLARE @WATP TABLE ([Form Number] INT IDENTITY, [Episode Start] DATE)
INSERT INTO @WATP ([Episode Start])
VALUES
('2013-01-01'),('2013-02-01'),('2013-04-01'),('2013-04-01'),('2013-05-01'),('2013-06-01'),
('2013-01-01'),('2013-02-01'),('2013-04-01'),('2013-04-01'),('2013-05-01'),('2013-06-01'),
('2014-01-01'),('2014-02-01'),('2014-03-01'),('2014-04-01'),('2014-05-01'),('2014-06-01'),
('2014-01-01'),('2014-02-01'),('2014-04-01'),('2014-04-01'),('2014-05-01'),('2014-06-01'),
('2014-01-01'),('2014-02-01'),('2014-04-01'),('2014-04-01'),('2014-05-01'),('2014-06-01'),
('2014-07-01'),('2014-08-01'),('2014-09-01'),('2014-10-01'),('2014-11-01'),('2014-12-01'),
('2014-07-01'),('2014-08-01'),('2014-09-01'),('2014-10-01'),('2014-11-01'),('2014-12-01'),
('2014-04-01'),('2014-05-01'),('2014-06-01'),('2014-04-01'),('2014-05-01'),('2014-06-01'),
('2014-04-01'),('2014-05-01'),('2014-06-01'),('2014-10-01'),('2014-11-01'),('2014-12-01'),
('2014-10-01'),('2014-11-01'),('2014-12-01')
SELECT YEAR([Episode Start]) AS year, COUNT(DISTINCT [Form Number]) AS yearTotal,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 1 THEN [Form Number] END) AS Jan,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 2 THEN [Form Number] END) AS Feb,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 3 THEN [Form Number] END) AS Mar,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 4 THEN [Form Number] END) AS Apr,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 5 THEN [Form Number] END) AS May,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 6 THEN [Form Number] END) AS Jun,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 7 THEN [Form Number] END) AS Jul,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 8 THEN [Form Number] END) AS Aug,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 9 THEN [Form Number] END) AS Sep,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 10 THEN [Form Number] END) AS Oct,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 11 THEN [Form Number] END) AS Nov,
COUNT(DISTINCT CASE WHEN MONTH([Episode Start]) = 12 THEN [Form Number] END) AS Dec
FROM @WATP
GROUP BY YEAR([Episode Start])
Please include DDL,DML and example data when posing a question, it makes it much easier for us to help you. -
Query using Union All and CTEs is slow
TypePatient
[ednum] int NOT NULL, PK
[BackgroundID] int NOT NULL, FK
[Patient_No] varchar(50) NULL, FK
[Last_Name] varchar(30) NULL,
[First_Name] varchar(30) NULL,
[ADateTime] datetime NULL,
Treat
[ID] int NOT NULL, PK
[Ednum] numeric(10, 0) NOT NULL, FK
[Doctor] char(50) NULL,
[Dr_ID] numeric(10, 0) NULL,
background
[ID] int NOT NULL, PK
[Patient_No] varchar(50) NULL, FK
[Last_Name] char(30) NULL,
[First_Name] char(30) NULL,
[DateofBirth] datetime NULL,
pdiagnose
[ID] int NOT NULL, PK
[Ednum] int NOT NULL, FK
[DSMNo] char(10) NULL,
[DSMNoIndex] char(5) NULL,
substance
[ID] int NOT NULL, PK
[Ednum] int NOT NULL, FK
[Substance] varchar(120) NULL,
DXCAT
[id] int NULL, PK
[dx_description] char(100) NULL,
[dx_code] char(10) NULL,
[dx_category_description] char(100) NULL,
[diagnosis_category_code] char(10) NULL)
Substance
ID
Ednum
Substance
1
100
Alcohol Dependence
4
200
Caffeine Dependence
5
210
Cigarettes
dxcat
id
dx_description
dx_code
dx_category_description
diagnosis_category_code
10
Tipsy
zzz
Alcohol
SA
20
Mellow
ppp
Mary Jane
SA
30
Spacey
fff
LSD
SA
50
Smoker
ggg
Nicotine
SA
pdiagnose
ID
Ednum
DSMNo
Diagnosis
1
100
zzz
Alcohol
2
100
ddd
Caffeine
3
210
ggg
Smoker
4
130
ppp
Mary Jane
TypePatient
ednum
Patient_No
Last_Name
First_Name
ADateTime
100
sssstttt
Wolly
Polly
12/4/2013
130
rrrrqqqq
Jolly
Molly
12/8/2013
200
bbbbcccc
Wop
Doo
12/12/2013
210
vvvvwww
Jazz
Razz
12/14/2013
Treat
ID
Ednum
Doctor
Dr_ID
2500
100
Welby, Marcus
1000
2550
200
Welby, Marcus
1000
3000
210
Welby, Marcus
1000
3050
130
Welby, Marcus
1000
background
ID
Patient_No
Last_Name
First_Name
DateofBirth
2
sssstttt
Wolly
Polly
8/6/1974
3
rrrrqqqq
Jolly
Molly
3/10/1987
5
bbbbcccc
Wop
Doo
8/12/1957
6
vvvvwww
Jazz
Razz
7/16/1995
Desired output:
Staff ID
Doctor
Patient_No
Client Name
Date of Service
Ednum
DX Code
DX Cat
DX Desc
Substance
1000
Welby, Marcus
bbbcccc
Wop, Doo
12/12/2013
200
Caffeine Dependence
1000
Welby, Marcus
rrrqqq
Jolly, Molly
12/8/2013
130
ppp
SA
Mary Jane
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
zzz
SA
Alcohol
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
ddd
SA
LSD
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
Alcohol Dependence
1000
Welby, Marcus
vvvvwww
Jazz, Razz
12/14/2013
210
ggg
SA
Smoker
1000
Welby, Marcus
vvvvwww
Jazz, Razz
12/14/2013
210
Cigarettes
A patient is assigned an ednum. There are two different menus for staff to enter
diagnoses. Each menu stores the entries in a different table. The two tables are substance and pdiagnose. A patient’s diagnosis for a substance abuse can be entered in one table and not the other.
The number of entries for different substances for each patient can vary between the two tables. John Doe might be entered for alcohol and caffeine abuse in the pdiagnosis table and entered only for caffeine abuse in the substance table. They are only
linked by the ednum which has nothing to do with the diagnosis/substance. The substance entered in one table is not linked to the substance entered in the other. A query will not put an entry for alcohol from the pdiagnosis table on the same row as an alcohol
entry from the substance table except by chance. That is the reason for the way the query is written.
The query accepts parameters for a Dr ID and a start and end date. It takes about 7 to 15 seconds to run. Hard coding the dates cuts it down to about a second.
I might be able to select directly from the union all query instead of having it separate. But then I’m not sure about the order by clauses using aliases.
Is there a way to rewrite the query to speed it up?
I did not design the tables or come up with the process of entering diagnoses. It can’t be changed at this time.
Please let me know if you notice any inconsistencies between the DDLs, data, and output. I did a lot of editing.
Thanks for any suggestions.
with cte_dxcat (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name, Adatetime,Ednum,
dx_code,diagnosis_category_code,dx_description,substance,
DateofBirth) as
(Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
TP.First_Name, TP.Adatetime as 'Date of Service',TP.Ednum,
DXCAT.dx_code,DXCAT.diagnosis_category_code,DXCAT.dx_description,
null as 'substance',BG.DateofBirth
From TypePatient TP
inner join treat t on TP.ednum = t.Ednum
inner join background BG on BG.Patient_No = TP.Patient_No
inner join pdiagnose PD on TP.Ednum = PD.Ednum
inner join Live_Knowledge.dbo.VA_DX_CAT_MAPPING DXCAT on DXCAT.dx_code = PD.DSMNo
Where (TP.Adatetime >= convert(varchar(10), :ST, 121)+ ' 00:00:00.000'
and TP.Adatetime <= convert(varchar(10), :SP, 121)+ ' 23:59:59.000')
and DXCAT.diagnosis_category_code = 'SA'
and t.Dr_ID =:DBLookupComboBox2
cte_substance (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name,Adatetime, Ednum,
dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
(Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
TP.First_Name, TP.Adatetime as 'Date of Service', TP.Ednum,
null as 'dx_code',null as 'diagnosis_category_code',null as 'dx_description',s.Substance, BG.DateofBirth
From TypePatient TP
inner join treat t on TP.ednum = t.Ednum
inner join background BG on BG.Patient_No = TP.Patient_No
inner join pdiagnose PD on TP.Ednum = PD.Ednum
inner join substance s on TP.Ednum = s.Ednum
Where (TP.Adatetime >= convert(varchar(10), '12/1/2013', 121)+ ' 00:00:00.000'
and TP.Adatetime <= convert(varchar(10), '12/31/2013', 121)+ ' 23:59:59.000')
and t.Dr_ID =:DBLookupComboBox2
cte_all (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name,Adatetime, Ednum,
dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
(select cte_dxcat.Dr_ID as 'Staff ID', cte_dxcat.Doctor as 'Doctor',
cte_dxcat.Patient_No as 'Patient_No',
cte_dxcat.Last_Name as 'Last',cte_dxcat.First_Name as 'First',
cte_dxcat.Adatetime as 'Date of Service',cte_dxcat.Ednum as 'Ednum',
cte_dxcat.dx_code as 'DX Code',cte_dxcat.diagnosis_category_code as 'DX Category Code',
cte_dxcat.dx_description as 'DX Description',
cte_dxcat.substance as 'Substance',cte_dxcat.DateofBirth as 'DOB'
from cte_dxcat
union all
select cte_substance.Dr_ID as 'Staff ID', cte_substance.Doctor as 'Doctor',
cte_substance.Patient_No as 'Patient_No',
cte_substance.Last_Name as 'Last',cte_substance.First_Name as 'First',
cte_substance.Adatetime as 'Date of Service',cte_substance.Ednum as 'Ednum',
cte_substance.dx_code as 'DX Code',cte_substance.diagnosis_category_code as 'DX Category Code',
cte_substance.dx_description as 'DX Description',
cte_substance.substance as 'Substance',cte_substance.DateofBirth as 'DOB'
from cte_substance)
select cte_all.Dr_ID as 'Staff ID', cte_all.Doctor as 'Doctor',
cte_all.Patient_No as 'Patient_No',
(cte_all.Last_Name + ', '+ cte_all.First_Name) as 'Client Name',
cte_all.Adatetime as 'Date of Service',cte_all.Ednum as 'Ednum',
cte_all.dx_code as 'DX Code',cte_all.diagnosis_category_code as 'DX Category Code',
cte_all.dx_description as 'DX Description',
cte_all.substance as 'Substance',
CONVERT(char(10), cte_all.DateofBirth,101) as 'DOB'
from cte_all
order by cte_all.Patient_No,cte_all.AdatetimePlease post real DDL instead of your invented non-language, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions
and formatting rules. Your rude, non-SQL narrative is so far away from standards I cannot even use you as a bad example in book.
Temporal data should use ISO-8601 formats (we have to re-type the dialect you used!). Code should be in Standard SQL as much as possible and not local dialecT.
This is minimal polite behavior on SQL forums. You posted a total mess! Do you really have patients without names?? You really use a zero to fifty characters for a patient_nbr??? Give me an example. That is insane!
Your disaster has more NULLs than entire major corporate systems. Since you cannot change it, can you quit? I am serious. I have been employed in IT since 1965, and can see a meltdown.
I looked at this and I am not even going to try to help you; it is not worth it. I am sorry for you; you are in an environment where you cannot learn to do any right.
But you are still responsible for the rudeness of not posting DDL.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Union All in a Subquery - Help
Hello All,
I am trying to create a Union All query but when i put a parameter in the where clause, i get an error. The Query is mentioned below:
SELECT T0.U_Srv_TechName, T0.ItemCode, T0.Dscription, SUM(T0.Quantity) AS [Bal Qty]
FROM (SELECT dbo.OWTR.U_Srv_TechName, dbo.WTR1.ItemCode, dbo.WTR1.Dscription, SUM(dbo.WTR1.Quantity) AS Quantity
FROM dbo.OWTR INNER JOIN
dbo.WTR1 ON dbo.OWTR.DocEntry = dbo.WTR1.DocEntry
GROUP BY dbo.OWTR.U_Srv_TechName, dbo.WTR1.ItemCode, dbo.WTR1.Dscription
UNION ALL
SELECT dbo.ODLN.U_Srv_TechName, dbo.DLN1.ItemCode, dbo.DLN1.Dscription, SUM(dbo.DLN1.Quantity * - 1) AS Quantity
FROM dbo.ODLN INNER JOIN
dbo.DLN1 ON dbo.ODLN.DocEntry = dbo.DLN1.DocEntry
GROUP BY dbo.ODLN.U_Srv_TechName, dbo.DLN1.ItemCode, dbo.DLN1.Dscription) T0
GROUP BY T0.U_Srv_TechName, T0.ItemCode, T0.Dscription
HAVING T0.U_Srv_TechName = [%0]
It gives me the error
1). [Microsoft][SQL Native Client][SQL Server]Must specify table to select from.
2). [Microsoft][SQL Native Client][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.
If I enter the name of the Technician (HAVING T0.U_Srv_TechName = 'xyz') it works fine. Also, if I execute the query in SQL Server with or without a prompt, it works fine. It's only on the SAP Query Manager that i'm having this problem. Please Help!
RezaReza,
Try this modification of the previous code, see if it works for you.
declare @stn varchar(20)
set @stn=/*SELECT T0.[DocNum] FROM OWTR T0 WHERE T0.[U_Srv_TechName] =*/'[%0]'
SELECT T0.U_Srv_TechName, T0.ItemCode, T0.Dscription, SUM(T0.Quantity) AS [Bal Qty]
FROM (SELECT T0.U_Srv_TechName, T1.ItemCode, T1.Dscription, SUM(T1.Quantity) AS Quantity
FROM OWTR T0 INNER JOIN
WTR1 T1 ON T0.DocEntry = T1.DocEntry
GROUP BY T0.U_Srv_TechName, T1.ItemCode, T1.Dscription
UNION ALL
SELECT T2.U_Srv_TechName, T3.ItemCode, T3.Dscription, SUM(T3.Quantity * - 1) AS Quantity
FROM ODLN T2 INNER JOIN
DLN1 T3 ON T2.DocEntry = T3.DocEntry
GROUP BY T2.U_Srv_TechName, T3.ItemCode, T3.Dscription) T0
GROUP BY T0.U_Srv_TechName, T0.ItemCode, T0.Dscription
HAVING T0.U_Srv_TechName =@stn
Hope this helps,
Lucas -
hi Following is my query and am unable to accomplish my order by statement in Union All . please help me in this.
<code>
SELECT b.audit_trail_id,
TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
(u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
b.col_name "Field",
b.new_value "New Value",b.previous_value "Old Value",
a.lot_id,
b.comment_text "Comments"
FROM clem_audit_trail b,lot a, users u
WHERE a.lot_id = b.lot_id(+)
AND u.user_id(+) = b.last_update_user_id
AND a.lot_id in (select lot_id from request_lot where request_id = 51914)
AND col_name IN
('Interim Release Date',
'Final Disposition Date',
'On Time Disposition',
'Intended Use',
'REJECTS_YN',
'# of QARs',
'# of Quality Events',
'# of LIRs',
'# of Change Controls',
'# of Batch Records',
'# of GMP Batch Records',
'EXPLANATION',
'QA Notes',
'GDMS_LINK')
AND UPPER (table_name) IN('LOT') order by b.last_update_date
UNION ALL
SELECT b.audit_trail_id,
TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
(u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
b.col_name "Field",
b.new_value "New Value",b.previous_value "Old Value",
r.request_id,
b.comment_text "Comments"
FROM clem b,request r, users u
WHERE r.request_id = b.request_id(+)
AND u.user_id(+) = b.last_update_user_id
AND r.request_id = 51914
AND UPPER (table_name) IN ('REQUEST') AND
b.col_name IN ('Partial Release',
'All QP Docs in GDMS',
'Number of Batch Records',
'Request',
'QP Issues',
'Snag Comments',
'Responsible Group',
'Reason Late',
'Study Impact',
'Other Details',
'Request Status',
'QP Link to GDMS'
) order by b.last_update_date
</code>
If i execute individually it works fine, if i use union all it throughs error for me.
Any suggestion...Hi,
In a set operation (such as UNION) table aliases (such as b.) only have meaning within the branch in which they are defined. The ORDER BY clause is not part of any 1 branch, so a table alias can't be used there.
In most cases, you can use a column name (or alias) from the first branch, like this:
SELECT b.audit_trail_id,
TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
order by "Revision Date"
;and you can always order by column number, like this:
SELECT b.audit_trail_id,
TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
order by 2
;In this case, however, there's an extra problem. You're transforming the DATE to a string in the SELECT clause. The string is all that's available in the ORDER BY clause, and the string '19-NOV-2012' comes after the string '01-JAN-2015', because the character '1' comes after '0'. Perhaps the simplest solution is to have your front end, and not the query, format the dates. In SQL*Plus, you can do this:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
SELECT b.audit_trail_id,
b.last_update_date AS "Revision Date",
order by 2
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Materalized view with union all and fast referesh
I have a one view which is very slow. in this view we are joining many tables and many union all queries.
now I am planing to make materalized view
Tell me how i will created view with fast refresh with union all query.
Pls help its urgent..
Thanks
ReenaRefer to the Replication Manual for the create syntax and exceptions.
-
UNION ALL destroys performance
Strangely, we have 2 queries, which when they run independently, run pretty fast (2 seconds for one, instantaneous for the other), but when they're concatenated into a UNION ALL query with no ORDER BY clause, it takes 45 seconds for it to run.
We tried pushing the SQL into a WITH clause, and some other subquery rewrites, but no perfomance boost. Has anyone seen this before?
version 10.1.0.4
--=ChuckHere are the results from DBMS_XPLAN. The prior explain plan was copied & pasted from TOAD.
SQL> explain plan for SELECT rownum, RUN_DATE.RUN_DATE,
2 RUN_TIME.RUN_TIME,
3 cc_report_work.report_name,
4 cc_report_work.line_sequence,
5 PURGE_DATE.PURGE_DATE,
6 NULL AS LAD_GROUP,
7 NULL AS NP_REASON,
8 SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
9 SUBSTR (cc_report_work.print_line, 21, 27) AS CLAIMANT,
10 SUBSTR (cc_report_work.print_line, 48, 10) AS LAD,
11 SUBSTR (cc_report_work.print_line, 62, 11) AS SSN
12 FROM claims.cc_report_work,
13 (SELECT report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
14 FROM claims.cc_report_work
15 WHERE report_name = 'CC2518B' AND line_sequence = 8) RUN_DATE,
16 (SELECT report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
17 FROM claims.cc_report_work
18 WHERE report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
19 (SELECT DISTINCT
20 report_name, SUBSTR (print_line, 66, 10) AS PURGE_DATE
21 FROM claims.cc_report_work
22 WHERE cc_report_work.report_name = 'CC2518B'
23 AND SUBSTR (cc_report_work.print_line, 54, 11) =
24 'Purged Thru') PURGE_DATE
25 WHERE cc_report_work.report_name = 'CC2518B'
26 AND SUBSTR (cc_report_work.print_line, 14, 1) = ' '
27 AND TRIM (cc_report_work.print_line) <>
28 'M A N U A L P U R G E L I S T I N G'
29 AND cc_report_work.report_name = RUN_DATE.report_name
30 AND cc_report_work.report_name = PURGE_DATE.report_name;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 3196380662
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time |
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 1 | 206 | 16903 (2)|00:03:23 |
| 1 | COUNT | | | | | |
| 2 | MERGE JOIN CARTESIAN | | 1 | 206 | 16903 (2)|00:03:23 |
|* 3 | HASH JOIN | | 1 | 192 | 12674 (2)|00:02:33 |
| 4 | MERGE JOIN CARTESIAN| | 1 | 128 | 8445 (2)|00:01:42 |
|* 5 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4222 (2)|00:00:51 |
| 6 | BUFFER SORT | | 1 | 64 | 4222 (2)|00:00:51 |
|* 7 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4222 (2)|00:00:51 |
|* 8 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4229 (2)|00:00:51 |
| 9 | BUFFER SORT | | 1 | 14 | 12675 (2)|00:02:33 |
| 10 | VIEW | | 1 | 14 | 4230 (2)|00:00:51 |
| 11 | SORT UNIQUE | | 1 | 62 | 4230 (2)|00:00:51 |
|* 12 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 62 | 4229 (2)|00:00:51 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
3 - access("CC_REPORT_WORK"."REPORT_NAME"="REPORT_NAME")
5 - filter("REPORT_NAME"='CC2518B' AND "LINE_SEQUENCE"=8)
7 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)
8 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)=' ' AND
TRIM("CC_REPORT_WORK"."PRINT_LINE")<>'M A N U A L P U R G E L I S T I N G')
12 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
PLAN_TABLE_OUTPUT
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",54,11)='Purged Thru')
31 rows selected.
SQL> explain plan for SELECT rownum, RUN_DATE.RUN_DATE,
2 RUN_TIME.RUN_TIME,
3 cc_report_work.report_name,
4 cc_report_work.line_sequence,
5 PURGE_DATE.PURGE_DATE,
6 LAD_GROUP.LAD_GROUP,
7 NP_REASON.NP_REASON,
8 SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
9 SUBSTR (cc_report_work.print_line, 21, 31) AS CLAIMANT,
10 SUBSTR (cc_report_work.print_line, 52, 10) AS LAD,
11 SUBSTR (cc_report_work.print_line, 70, 11) AS SSN
12 FROM claims.cc_report_work,
13 (SELECT DISTINCT
14 report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
15 FROM claims.cc_report_work
16 WHERE report_name = 'CC2518C'
17 AND SUBSTR (print_line, 7, 8) LIKE '%/%/%') RUN_DATE,
18 (SELECT report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
19 FROM claims.cc_report_work
20 WHERE report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
21 (SELECT DISTINCT
22 report_name, SUBSTR (print_line, 67, 10) AS PURGE_DATE
23 FROM claims.cc_report_work
24 WHERE report_name = 'CC2518C'
25 AND SUBSTR (print_line, 37, 29) =
26 'Claims with No Activity since') PURGE_DATE,
27 (SELECT TRIM (print_line) AS LAD_GROUP, page_advance
28 FROM claims.cc_report_work
29 WHERE report_name = 'CC2518C'
30 AND SUBSTR (print_line, 11, 13) = 'Last Activity')
31 LAD_GROUP,
32 (SELECT TRIM (print_line) AS NP_REASON,
33 page_advance,
34 line_sequence,
35 LEAD (page_advance, 1, NULL)
36 OVER (ORDER BY page_advance, line_sequence)
37 AS NEXT_PAGE,
38 LEAD (line_sequence, 1, NULL)
39 OVER (ORDER BY page_advance, line_sequence)
40 AS NEXT_LINE
41 FROM claims.cc_report_work
42 WHERE cc_report_work.report_name = 'CC2518C'
43 AND SUBSTR (cc_report_work.print_line, 11, 20) =
44 'Reason for Non-Purge') NP_REASON
45 WHERE cc_report_work.report_name = 'CC2518C'
46 AND cc_report_work.page_advance = LAD_GROUP.page_advance
47 AND cc_report_work.report_name = PURGE_DATE.report_name
48 AND cc_report_work.report_name = RUN_DATE.report_name
49 AND SUBSTR (cc_report_work.print_line, 14, 1) = '-'
50 AND ( (cc_report_work.page_advance = NP_REASON.page_advance
51 AND cc_report_work.line_sequence BETWEEN NP_REASON.line_sequence
52 AND NP_REASON.NEXT_LINE)
53 OR ( cc_report_work.page_advance = NP_REASON.page_advance
54 AND NP_REASON.NEXT_PAGE IS NULL
55 AND NP_REASON.NEXT_LINE IS NULL
56 AND cc_report_work.line_sequence > NP_REASON.line_sequence));
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1773249683
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 1 | 381 | 25361 (2)| 00:05:05 |
| 1 | COUNT | | | || |
| 2 | NESTED LOOPS | | 1 | 381 | 25361 (2)| 00:05:05 |
| 3 | MERGE JOIN CARTESIAN | | 1 | 221 | 21131 (2)| 00:04:14 |
| 4 | MERGE JOIN CARTESIAN | | 1 | 207 | 16902 (2)| 00:03:23 |
|* 5 | HASH JOIN | | 1 | 194 | 12672 (2)| 00:02:33 |
| 6 | MERGE JOIN CARTESIAN| | 1 | 128 | 8447 (2)| 00:01:42 |
|* 7 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4222 (2)| 00:00:51 |
| 8 | BUFFER SORT | | 1 | 64 | 4225 (2)| 00:00:51 |
|* 9 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4225 (2)| 00:00:51 |
|* 10 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 66 | 4225 (2)| 00:00:51 |
| 11 | BUFFER SORT | | 1 | 13 | 12677 (2)| 00:02:33 |
| 12 | VIEW | | 1 | 13 | 4230 (2)| 00:00:51 |
| 13 | SORT UNIQUE | | 1 | 62 | 4230 (2)| 00:00:51 |
|* 14 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 62 | 4229 (2)| 00:00:51 |
| 15 | BUFFER SORT | | 1 | 14 | 16902 (2)| 00:03:23 |
| 16 | VIEW | | 1 | 14 | 4230 (2)| 00:00:51 |
| 17 | SORT UNIQUE | | 1 | 62 | 4230 (2)| 00:00:51 |
|* 18 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 62 | 4229 (2)| 00:00:51 |
|* 19 | VIEW | | 1 | 160 | 4230 (2)| 00:00:51 |
| 20 | WINDOW SORT | | 1 | 66 | 4230 (2)| 00:00:51 |
|* 21 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 66 | 4229 (2)| 00:00:51 |
Predicate Information (identified by operation id):
5 - access("CC_REPORT_WORK"."PAGE_ADVANCE"="PAGE_ADVANCE")
7 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)
9 - filter("PAGE_ADVANCE" IS NOT NULL AND "REPORT_NAME"='CC2518C' AND
SUBSTR("PRINT_LINE",11,13)='Last Activity')
10 - filter("CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
"CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)='-')
14 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",7,8) LIKE '%/%/%')
18 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",37,29)='Claims with No Activity since')
19 - filter("CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
"CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
"CC_REPORT_WORK"."LINE_SEQUENCE">="NP_REASON"."LINE_SEQUENCE" AND
"CC_REPORT_WORK"."LINE_SEQUENCE"<="NP_REASON"."NEXT_LINE" OR
"CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
"CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND "NP_REASON"."NEXT_PAGE" IS NULL AND
"NP_REASON"."NEXT_LINE" IS NULL AND "CC_REPORT_WORK"."LINE_SEQUENCE">"NP_REASON"."LINE_SEQUENCE")
21 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",11,20)='Reason for Non-Purge')
52 rows selected.
SQL> explain plan for SELECT rownum, RUN_DATE.RUN_DATE,
2 RUN_TIME.RUN_TIME,
3 cc_report_work.report_name,
4 cc_report_work.line_sequence,
5 PURGE_DATE.PURGE_DATE,
6 NULL AS LAD_GROUP,
7 NULL AS NP_REASON,
8 SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
9 SUBSTR (cc_report_work.print_line, 21, 27) AS CLAIMANT,
10 SUBSTR (cc_report_work.print_line, 48, 10) AS LAD,
11 SUBSTR (cc_report_work.print_line, 62, 11) AS SSN
12 FROM claims.cc_report_work,
13 (SELECT report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
14 FROM claims.cc_report_work
15 WHERE report_name = 'CC2518B' AND line_sequence = 8) RUN_DATE,
16 (SELECT report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
17 FROM claims.cc_report_work
18 WHERE report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
19 (SELECT DISTINCT
20 report_name, SUBSTR (print_line, 66, 10) AS PURGE_DATE
21 FROM claims.cc_report_work
22 WHERE cc_report_work.report_name = 'CC2518B'
23 AND SUBSTR (cc_report_work.print_line, 54, 11) =
24 'Purged Thru') PURGE_DATE
25 WHERE cc_report_work.report_name = 'CC2518B'
26 AND SUBSTR (cc_report_work.print_line, 14, 1) = ' '
27 AND TRIM (cc_report_work.print_line) <>
28 'M A N U A L P U R G E L I S T I N G'
29 AND cc_report_work.report_name = RUN_DATE.report_name
30 AND cc_report_work.report_name = PURGE_DATE.report_name
31 UNION ALL
32 SELECT rownum, RUN_DATE.RUN_DATE,
33 RUN_TIME.RUN_TIME,
34 cc_report_work.report_name,
35 cc_report_work.line_sequence,
36 PURGE_DATE.PURGE_DATE,
37 LAD_GROUP.LAD_GROUP,
38 NP_REASON.NP_REASON,
39 SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
40 SUBSTR (cc_report_work.print_line, 21, 31) AS CLAIMANT,
41 SUBSTR (cc_report_work.print_line, 52, 10) AS LAD,
42 SUBSTR (cc_report_work.print_line, 70, 11) AS SSN
43 FROM claims.cc_report_work,
44 (SELECT DISTINCT
45 report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
46 FROM claims.cc_report_work
47 WHERE report_name = 'CC2518C'
48 AND SUBSTR (print_line, 7, 8) LIKE '%/%/%') RUN_DATE,
49 (SELECT report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
50 FROM claims.cc_report_work
51 WHERE report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
52 (SELECT DISTINCT
53 report_name, SUBSTR (print_line, 67, 10) AS PURGE_DATE
54 FROM claims.cc_report_work
55 WHERE report_name = 'CC2518C'
56 AND SUBSTR (print_line, 37, 29) =
57 'Claims with No Activity since') PURGE_DATE,
58 (SELECT TRIM (print_line) AS LAD_GROUP, page_advance
59 FROM claims.cc_report_work
60 WHERE report_name = 'CC2518C'
61 AND SUBSTR (print_line, 11, 13) = 'Last Activity')
62 LAD_GROUP,
63 (SELECT TRIM (print_line) AS NP_REASON,
64 page_advance,
65 line_sequence,
66 LEAD (page_advance, 1, NULL)
67 OVER (ORDER BY page_advance, line_sequence)
68 AS NEXT_PAGE,
69 LEAD (line_sequence, 1, NULL)
70 OVER (ORDER BY page_advance, line_sequence)
71 AS NEXT_LINE
72 FROM claims.cc_report_work
73 WHERE cc_report_work.report_name = 'CC2518C'
74 AND SUBSTR (cc_report_work.print_line, 11, 20) =
75 'Reason for Non-Purge') NP_REASON
76 WHERE cc_report_work.report_name = 'CC2518C'
77 AND cc_report_work.page_advance = LAD_GROUP.page_advance
78 AND cc_report_work.report_name = PURGE_DATE.report_name
79 AND cc_report_work.report_name = RUN_DATE.report_name
80 AND SUBSTR (cc_report_work.print_line, 14, 1) = '-'
81 AND ( (cc_report_work.page_advance = NP_REASON.page_advance
82 AND cc_report_work.line_sequence BETWEEN NP_REASON.line_sequence
83 AND NP_REASON.NEXT_LINE)
84 OR ( cc_report_work.page_advance = NP_REASON.page_advance
85 AND NP_REASON.NEXT_PAGE IS NULL
86 AND NP_REASON.NEXT_LINE IS NULL
87 AND cc_report_work.line_sequence > NP_REASON.line_sequence));
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 3197798840
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 2 | 609 | 42264 (61)| 00:08:28 |
| 1 | UNION-ALL | | | | | |
| 2 | COUNT | | | | | |
| 3 | MERGE JOIN CARTESIAN | | 1 | 206 | 16903 (2)| 00:03:23 |
|* 4 | HASH JOIN | | 1 | 192 | 12674 (2)| 00:02:33 |
| 5 | MERGE JOIN CARTESIAN | | 1 | 128 | 8445 (2)| 00:01:42 |
|* 6 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4222 (2)| 00:00:51 |
| 7 | BUFFER SORT | | 1 | 64 | 4222 (2)| 00:00:51 |
|* 8 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4222 (2)| 00:00:51 |
|* 9 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4229 (2)| 00:00:51 |
| 10 | BUFFER SORT | | 1 | 14 | 12675 (2)| 00:02:33 |
| 11 | VIEW | | 1 | 14 | 4230 (2)| 00:00:51 |
| 12 | SORT UNIQUE | | 1 | 62 | 4230 (2)| 00:00:51 |
|* 13 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 62 | 4229 (2)| 00:00:51 |
| 14 | COUNT | | | | | |
| 15 | NESTED LOOPS | | 1 | 403 | 25361 (2)| 00:05:05 |
| 16 | MERGE JOIN CARTESIAN | | 1 | 221 | 21131 (2)| 00:04:14 |
| 17 | MERGE JOIN CARTESIAN | | 1 | 207 | 16902 (2)| 00:03:23 |
|* 18 | HASH JOIN | | 1 | 194 | 12672 (2)| 00:02:33 |
| 19 | MERGE JOIN CARTESIAN| | 1 | 128 | 8447 (2)| 00:01:42 |
|* 20 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4222 (2)| 00:00:51 |
| 21 | BUFFER SORT | | 1 | 64 | 4225 (2)| 00:00:51 |
|* 22 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 64 | 4225 (2)| 00:00:51 |
|* 23 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 66 | 4225 (2)| 00:00:51 |
| 24 | BUFFER SORT | | 1 | 13 | 12677 (2)| 00:02:33 |
| 25 | VIEW | | 1 | 13 | 4230 (2)| 00:00:51 |
| 26 | SORT UNIQUE | | 1 | 62 | 4230 (2)| 00:00:51 |
|* 27 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 62 | 4229 (2)| 00:00:51 |
| 28 | BUFFER SORT | | 1 | 14 | 16902 (2)| 00:03:23 |
| 29 | VIEW | | 1 | 14 | 4230 (2)| 00:00:51 |
| 30 | SORT UNIQUE | | 1 | 62 | 4230 (2)| 00:00:51 |
|* 31 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 62 | 4229 (2)| 00:00:51 |
|* 32 | VIEW | | 1 | 182 | 4230 (2)| 00:00:51 |
| 33 | WINDOW SORT | | 1 | 66 | 4230 (2)| 00:00:51 |
|* 34 | TABLE ACCESS FULL | CC_REPORT_WORK | 1 | 66 | 4229 (2)| 00:00:51 |
Predicate Information (identified by operation id):
4 - access("CC_REPORT_WORK"."REPORT_NAME"="REPORT_NAME")
6 - filter("REPORT_NAME"='CC2518B' AND "LINE_SEQUENCE"=8)
8 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2) 9 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)=' ' AND
TRIM("CC_REPORT_WORK"."PRINT_LINE")<>'M A N U A L P U R G E LI S T I N G')
13 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",54,11)='Purged Thru')
18 - access("CC_REPORT_WORK"."PAGE_ADVANCE"="PAGE_ADVANCE")
20 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)
22 - filter("PAGE_ADVANCE" IS NOT NULL AND "REPORT_NAME"='CC2518C' AND
SUBSTR("PRINT_LINE",11,13)='Last Activity')
23 - filter("CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
"CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)='-')
27 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",7,8) LIKE '%/%/%')
31 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",37,29)='Claims with No
Activity since')
32 - filter("CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
"CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
"CC_REPORT_WORK"."LINE_SEQUENCE">="NP_REASON"."LINE_SEQUENCE" AND
"CC_REPORT_WORK"."LINE_SEQUENCE"<="NP_REASON"."NEXT_LINE" OR
"CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
"CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND "NP_REASON"."NEXT_PAGE" IS NULL AND
"NP_REASON"."NEXT_LINE" IS NULL AND "CC_REPORT_WORK"."LINE_SEQUENCE">"NP_REASON"."LINE_SEQUENCE")
34 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
SUBSTR("CC_REPORT_WORK"."PRINT_LINE",11,20)='Reason for Non-Purge')
73 rows selected.--=cf -
Multiple UNION ALL views within a view returning incorrect records?
Hi,
I have a view which selects from multiple views with UNION ALL joining them. If I just select from the larg UNION ALL query I return more records (correct amount) than If I create a view, and select from it.
e.g.
SELECT *
FROM vw_load_1
UNION ALL
SELECT *
FROM vw_load_2
UNION ALL
SELECT *
FROM vw_load_3
UNION ALL
SELECT *
FROM vw_load_4
UNION ALL
SELECT *
FROM vw_load_5
Returns 405 Records
but
CREATE VIEW vw_master_load
AS
SELECT *
FROM vw_load_1
UNION ALL
SELECT *
FROM vw_load_2
UNION ALL
SELECT *
FROM vw_load_3
UNION ALL
SELECT *
FROM vw_load_4
UNION ALL
SELECT *
FROM vw_load_5;
SELECT COUNT(*)
FROM vw_master_load
Returns 307 records
Can anyone explain why, or how to get around this?
Oracle version: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - ProductionHi,
Are you saying that you run:
select count(*) from (
SELECT *
FROM vw_load_1
UNION ALL
SELECT *
FROM vw_load_2
UNION ALL
SELECT *
FROM vw_load_3
UNION ALL
SELECT *
FROM vw_load_4
UNION ALL
SELECT *
FROM vw_load_5
result is: 307 And then you run
SELECT *
FROM vw_load_1
UNION ALL
SELECT *
FROM vw_load_2
UNION ALL
SELECT *
FROM vw_load_3
UNION ALL
SELECT *
FROM vw_load_4
UNION ALL
SELECT *
FROM vw_load_5
returns 405 rowsIf so, that is very strange.
Can you an example we can re-produce?
Regards,
Peter -
Help required on UNION ALL for select query
Hello all,
The execution plan for an SQL is impacted when another SELECT is concatenated with a UNION ALL. The two SELECTS are very efficient when run separately (< 100 buffer gets), but when run together (using a UNION ALL), the execution plan changes (for the first SELECT) and the buffer gets jumps to over 45000!
what customer says with the UNION ALL, Oracle instead of doing a Merge Scan (that allows the inner table to filter out the rows from the outer table), chooses to do a NL join. This results in a Unique Index scan for each one of the 15000 rows in the outer table, resulting in 46000 consistent gets.
Can you please suggest customer why plan changes when they use UNION ALL & also suggest better way of running query.
Please refer to below explain plan .
WITH THE UNIONS
===============
1 SELECT count(*)
2 FROM SOC_LIST SOC
3 WHERE
4 ( EXISTS( SELECT 1
5 FROM ELIGIBILITY_RELATION
6 WHERE SRC_CODE = 'SHDMM4215'
7 AND DEST_CODE = SOC.SOC
8 AND SRC_TYPE = 'P'
9 AND DEST_TYPE = 'S'))
10 UNION ALL
11 SELECT count(*)
12 FROM SOC_LIST SOC
13* WHERE ( = 'Y')
12:25:39 SQL> /
COUNT(*)
153
0
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=31 Card=2 Bytes=10)
1 0 UNION-ALL
2 1 SORT (AGGREGATE)
3 2 FILTER
4 3 TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=749
Bytes=7490)
5 3 PARTITION HASH (SINGLE)
6 5 INDEX (UNIQUE SCAN) OF 'ELIGIBILITY_RELATION_PK' (
UNIQUE) (Cost=2 Card=1 Bytes=24)
7 1 SORT (AGGREGATE)
8 7 FILTER
9 8 TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=1497
8)
Statistics
0 recursive calls
0 db block gets
46712 consistent gets <------large number
0 physical reads
0 redo size
215 bytes sent via SQL*Net to client
241 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
12:25:40 SQL> ed
Wrote file C:/PADDY/AFIEDT.BUF
PART 1 of the UNION ALL
========================
1 SELECT count(*)
2 FROM SOC_LIST SOC
3 WHERE
4 ( EXISTS( SELECT 1
5 FROM ELIGIBILITY_RELATION
6 WHERE SRC_CODE = 'SHDMM4215'
7 AND DEST_CODE = SOC.SOC
8 AND SRC_TYPE = 'P'
9* AND DEST_TYPE = 'S'))
12:25:54 SQL> /
COUNT(*)
153
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=1 Bytes=34)
1 0 SORT (AGGREGATE)
2 1 MERGE JOIN (SEMI) (Cost=4 Card=149 Bytes=5066)
3 2 INDEX (FULL SCAN) OF 'SOC_LIST_1IX' (NON-UNIQUE) (Cost
=41 Card=14978 Bytes=149780)
4 2 SORT (UNIQUE) (Cost=3 Card=149 Bytes=3576)
5 4 PARTITION HASH (ALL)
6 5 INDEX (RANGE SCAN) OF 'ELIGIBILITY_RELATION_PK' (U
NIQUE) (Cost=10 Card=149 Bytes=3576)
Statistics
0 recursive calls
0 db block gets
56 consistent gets
0 physical reads
0 redo size
218 bytes sent via SQL*Net to client
241 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
12:25:55 SQL> ed
Wrote file C:/PADDY/AFIEDT.BUF
PART 2 of the UNION ALL
========================
1 SELECT count(*)
2 FROM SOC_LIST SOC
3* WHERE ( = 'Y')
12:26:15 SQL> /
COUNT(*)
0
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=15 Card=1)
1 0 SORT (AGGREGATE)
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=14978)
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
215 bytes sent via SQL*Net to client
241 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
12:26:20 SQL> spool off
Same results but with theUNION ALL, the buffergets is massive ...
Thanks
Krishnai am also attaching 10043/10053 trace file .
/opt/oracle/adm/STCUST/udump/stcust_ora_7919_10046_10053_trace_file.trc
*** TRACE DUMP CONTINUED FROM FILE ***
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
ORACLE_HOME = /opt/oracle/product/9.2.0.8
System name: HP-UX
Node name: rcihp009
Release: B.11.23
Version: U
Machine: 9000/800
Instance name: STCUST
Redo thread mounted by this instance: 1
Oracle process number: 152
Unix process pid: 7919, image: oracle@rcihp009 (TNS V1-V3)
*** 2013-06-10 13:32:48.943
*** SESSION ID:(533.15875) 2013-06-10 13:32:48.943
APPNAME mod='SQL*Plus' mh=3669949024 act='' ah=4029777240
=====================
PARSING IN CURSOR #1 len=69 dep=0 uid=33 oct=42 lid=33 tim=3017585934213 hv=2004533713 ad='4aa33998'
alter session set events '10046 trace name context forever, level 12'
END OF STMT
EXEC #1:c=0,e=209,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017585933683
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:33:00.090
WAIT #1: nam='SQL*Net message from client' ela= 10884599 p1=1413697536 p2=1 p3=0
=====================
PARSING IN CURSOR #1 len=69 dep=0 uid=33 oct=42 lid=33 tim=3017596819944 hv=2030017677 ad='3af92970'
alter session set events '10053 trace name context forever, level 1'
END OF STMT
PARSE #1:c=0,e=484,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017596819933
BINDS #1:
EXEC #1:c=0,e=160,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017596820180
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:33:50.197
WAIT #1: nam='SQL*Net message from client' ela= 48932344 p1=1413697536 p2=1 p3=0
PARAMETERS USED BY THE OPTIMIZER
OPTIMIZER_FEATURES_ENABLE = 9.2.0
OPTIMIZER_MODE/GOAL = Choose
_OPTIMIZER_PERCENT_PARALLEL = 101
HASH_AREA_SIZE = 131072
HASH_JOIN_ENABLED = TRUE
HASH_MULTIBLOCK_IO_COUNT = 0
SORT_AREA_SIZE = 65536
OPTIMIZER_SEARCH_LIMIT = 5
PARTITION_VIEW_ENABLED = FALSE
_ALWAYS_STAR_TRANSFORMATION = FALSE
_B_TREE_BITMAP_PLANS = TRUE
STAR_TRANSFORMATION_ENABLED = FALSE
_COMPLEX_VIEW_MERGING = TRUE
_PUSH_JOIN_PREDICATE = TRUE
PARALLEL_BROADCAST_ENABLED = TRUE
OPTIMIZER_MAX_PERMUTATIONS = 2000
OPTIMIZER_INDEX_CACHING = 0
_SYSTEM_INDEX_CACHING = 0
OPTIMIZER_INDEX_COST_ADJ = 1
OPTIMIZER_DYNAMIC_SAMPLING = 1
_OPTIMIZER_DYN_SMP_BLKS = 32
QUERY_REWRITE_ENABLED = TRUE
QUERY_REWRITE_INTEGRITY = ENFORCED
_INDEX_JOIN_ENABLED = TRUE
_SORT_ELIMINATION_COST_RATIO = 0
_OR_EXPAND_NVL_PREDICATE = TRUE
_NEW_INITIAL_JOIN_ORDERS = TRUE
ALWAYS_ANTI_JOIN = CHOOSE
ALWAYS_SEMI_JOIN = CHOOSE
_OPTIMIZER_MODE_FORCE = TRUE
_OPTIMIZER_UNDO_CHANGES = FALSE
_UNNEST_SUBQUERY = TRUE
_PUSH_JOIN_UNION_VIEW = TRUE
_FAST_FULL_SCAN_ENABLED = TRUE
_OPTIM_ENHANCE_NNULL_DETECTION = TRUE
_ORDERED_NESTED_LOOP = TRUE
_NESTED_LOOP_FUDGE = 100
_NO_OR_EXPANSION = FALSE
_QUERY_COST_REWRITE = TRUE
QUERY_REWRITE_EXPRESSION = TRUE
_IMPROVED_ROW_LENGTH_ENABLED = TRUE
_USE_NOSEGMENT_INDEXES = FALSE
_ENABLE_TYPE_DEP_SELECTIVITY = TRUE
_IMPROVED_OUTERJOIN_CARD = TRUE
_OPTIMIZER_ADJUST_FOR_NULLS = TRUE
_OPTIMIZER_CHOOSE_PERMUTATION = 0
_USE_COLUMN_STATS_FOR_FUNCTION = TRUE
_SUBQUERY_PRUNING_ENABLED = TRUE
_SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
_SUBQUERY_PRUNING_COST_FACTOR = 20
_LIKE_WITH_BIND_AS_EQUALITY = FALSE
_TABLE_SCAN_COST_PLUS_ONE = TRUE
_SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
_DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
_ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
_OPTIMIZER_COST_MODEL = CHOOSE
_GSETS_ALWAYS_USE_TEMPTABLES = FALSE
DB_FILE_MULTIBLOCK_READ_COUNT = 128
_NEW_SORT_COST_ESTIMATE = TRUE
_GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
_CPU_TO_IO = 0
_PRED_MOVE_AROUND = TRUE
BASE STATISTICAL INFORMATION
Table stats Table: SOC_LIST Alias: SOC
TOTAL :: CDN: 17584 NBLKS: 653 AVG_ROW_LEN: 260
Column: SOC Col#: 3 Table: SOC_LIST Alias: SOC
NDV: 17584 NULLS: 0 DENS: 5.6870e-05
NO HISTOGRAM: #BKT: 1 #VAL: 2
-- Index stats
INDEX NAME: I_SNAP$_SOC_LIST COL#: 1
TOTAL :: LVLS: 1 #LB: 64 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 699
INDEX NAME: SOC_LIST_1IX COL#: 3
TOTAL :: LVLS: 1 #LB: 47 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 14065
Table stats Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
(Using composite stats)
TOTAL :: CDN: 11982220 NBLKS: 125493 AVG_ROW_LEN: 71
-- Index stats
INDEX NAME: ELIGIBILITY_RELATION_1IX COL#: 3 4 5
USING COMPOSITE STATS
TOTAL :: LVLS: 2 #LB: 38360 #DK: 4164 LB/K: 9 DB/K: 740 CLUF: 3081860
INDEX NAME: ELIGIBILITY_RELATION_PK COL#: 2 3 4 5
USING COMPOSITE STATS
TOTAL :: LVLS: 2 #LB: 50740 #DK: 11873160 LB/K: 1 DB/K: 1 CLUF: 9158280
INDEX NAME: I_SNAP$_ELIGIBILITY_RELATI COL#: 1
TOTAL :: LVLS: 2 #LB: 49600 #DK: 11953600 LB/K: 1 DB/K: 1 CLUF: 8833300
_OPTIMIZER_PERCENT_PARALLEL = 0
SINGLE TABLE ACCESS PATH
Column: SRC_CODE Col#: 2 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 22087 NULLS: 0 DENS: 4.5276e-05
NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: SRC_TYPE Col#: 3 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 2 NULLS: 0 DENS: 5.0000e-01
NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: DEST_TYPE Col#: 5 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 2 NULLS: 0 DENS: 5.0000e-01
NO HISTOGRAM: #BKT: 1 #VAL: 2
TABLE: ELIGIBILITY_RELATION ORIG CDN: 11982220 ROUNDED CDN: 136 CMPTD CDN: 136
Access path: tsc Resc: 3072 Resp: 3072
Access path: index (iff)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 1243
IX_SEL: 0.0000e+00 TB_SEL: 1.0000e+00
Access path: iff Resc: 1243 Resp: 1243
Skip scan: ss-sel 0 andv 11970
ss cost 119700
index io scan cost 19180
Access path: index (scan)
Index: ELIGIBILITY_RELATION_1IX
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 789653
IX_SEL: 5.0000e-01 TB_SEL: 2.5000e-01
Skip scan: ss-sel 0 andv 11970
ss cost 11970
index io scan cost 2
Access path: index (index-only)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 10
IX_SEL: 2.2638e-05 TB_SEL: 2.2638e-05
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
BEST_CST: 1.00 PATH: 4 Degree: 1
SINGLE TABLE ACCESS PATH
TABLE: SOC_LIST ORIG CDN: 17584 ROUNDED CDN: 17584 CMPTD CDN: 17584
Access path: tsc Resc: 18 Resp: 18
Access path: index (iff)
Index: SOC_LIST_1IX
TABLE: SOC_LIST
RSC_CPU: 0 RSC_IO: 3
IX_SEL: 0.0000e+00 TB_SEL: 1.0000e+00
Access path: iff Resc: 3 Resp: 3
Access path: index (no sta/stp keys)
Index: SOC_LIST_1IX
TABLE: SOC_LIST
RSC_CPU: 0 RSC_IO: 48
IX_SEL: 1.0000e+00 TB_SEL: 1.0000e+00
BEST_CST: 1.00 PATH: 4 Degree: 1
OPTIMIZER STATISTICS AND COMPUTATIONS
GENERAL PLANS
Join order[1]: SOC_LIST[SOC]#0 ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1
Now joining: ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1 *******
NL Join
Outer table: cost: 1 cdn: 17584 rcz: 10 resp: 1
Inner table: ELIGIBILITY_RELATION
Access path: tsc Resc: 768
Join: Resc: 13504513 Resp: 13504513
Access path: index (iff)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 1243
IX_SEL: 0.0000e+00 TB_SEL: 1.0000e+00
Inner table: ELIGIBILITY_RELATION
Access path: iff Resc: 311
Join: Resc: 5464229 Resp: 5464229
Access path: index (unique)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 8.3457e-08 TB_SEL: 8.3457e-08
Join: resc: 177 resp: 177
Access path: index (join index)
Index: ELIGIBILITY_RELATION_1IX
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 750
IX_SEL: 0.0000e+00 TB_SEL: 2.0886e-05
Join: resc: 131881 resp: 131881
Access path: index (eq-unique)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 0.0000e+00 TB_SEL: 0.0000e+00
Join: resc: 177 resp: 177
****** trying bitmap/domain indexes ******
Access path: index (join index)
Index: ELIGIBILITY_RELATION_1IX
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 10
IX_SEL: 1.4217e-05 TB_SEL: 2.0886e-05
Join: resc: 1759 resp: 1759
Access path: index (index-only)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 4
IX_SEL: 4.5276e-05 TB_SEL: 4.5276e-05
Join: resc: 704 resp: 704
SORT resource Sort statistics
Sort width: 11 Area size: 628736 Max Area size: 31457280 Degree: 1
Blocks to Sort: 2 Row size: 21 Rows: 543
Initial runs: 1 Merge passes: 1 IO Cost / pass: 3
Total IO sort cost: 2
Total CPU sort cost: 0
Total Temp space used: 0
****** finished trying bitmap/domain indexes ******
Best NL cost: 177 resp: 177
Semi-join cardinality: 135 = outer (17584) * sel (7.6774e-03) [flag=12]
SM Join
Outer table:
resc: 1 cdn: 17584 rcz: 10 deg: 1 resp: 1
Inner table: ELIGIBILITY_RELATION
resc: 1 cdn: 136 rcz: 24 deg: 1 resp: 1
using join:1 distribution:2 #groups:1
SORT resource Sort statistics
Sort width: 11 Area size: 628736 Max Area size: 31457280 Degree: 1
Blocks to Sort: 1 Row size: 37 Rows: 136
Initial runs: 1 Merge passes: 1 IO Cost / pass: 2
Total IO sort cost: 2
Total CPU sort cost: 0
Total Temp space used: 0
Merge join Cost: 4 Resp: 4
HA Join
Outer table:
resc: 1 cdn: 17584 rcz: 10 deg: 1 resp: 1
Inner table: ELIGIBILITY_RELATION
resc: 1 cdn: 136 rcz: 24 deg: 1 resp: 1
using join:8 distribution:2 #groups:1
Hash join one ptn Resc: 4 Deg: 1
hash_area: 154 (max=7680) buildfrag: 48 probefrag: 1 ppasses: 1
Hash join Resc: 6 Resp: 6
Join result: cost: 4 cdn: 135 rcz: 34
Best so far: TABLE#: 0 CST: 1 CDN: 17584 BYTES: 175840
Best so far: TABLE#: 1 CST: 4 CDN: 135 BYTES: 4590
Join order[2]: ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1 SOC_LIST[SOC]#0
SORT resource Sort statistics
Sort width: 11 Area size: 628736 Max Area size: 31457280 Degree: 1
Blocks to Sort: 1 Row size: 37 Rows: 136
Initial runs: 1 Merge passes: 1 IO Cost / pass: 2
Total IO sort cost: 2
Total CPU sort cost: 0
Total Temp space used: 0
Now joining: SOC_LIST[SOC]#0 *******
NL Join
Outer table: cost: 3 cdn: 136 rcz: 24 resp: 2
Inner table: SOC_LIST
Access path: tsc Resc: 18
Join: Resc: 2450 Resp: 2450
Access path: index (iff)
Index: SOC_LIST_1IX
TABLE: SOC_LIST
RSC_CPU: 0 RSC_IO: 3
IX_SEL: 0.0000e+00 TB_SEL: 1.0000e+00
Inner table: SOC_LIST
Access path: iff Resc: 3
Join: Resc: 410 Resp: 410
Access path: index (join index)
Index: SOC_LIST_1IX
TABLE: SOC_LIST
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 0.0000e+00 TB_SEL: 5.6870e-05
Join: resc: 4 resp: 4
Best NL cost: 4 resp: 4
Join cardinality: 136 = outer (136) * inner (17584) * sel (5.6870e-05) [flag=0]
SM Join
Outer table:
resc: 2 cdn: 136 rcz: 24 deg: 1 resp: 2
Inner table: SOC_LIST
resc: 1 cdn: 17584 rcz: 10 deg: 1 resp: 1
using join:1 distribution:2 #groups:1
SORT resource Sort statistics
Sort width: 11 Area size: 628736 Max Area size: 31457280 Degree: 1
Blocks to Sort: 1 Row size: 37 Rows: 136
Initial runs: 1 Merge passes: 1 IO Cost / pass: 2
Total IO sort cost: 2
Total CPU sort cost: 0
Total Temp space used: 0
SORT resource Sort statistics
Sort width: 11 Area size: 628736 Max Area size: 31457280 Degree: 1
Blocks to Sort: 46 Row size: 21 Rows: 17584
Initial runs: 1 Merge passes: 1 IO Cost / pass: 51
Total IO sort cost: 48
Total CPU sort cost: 0
Total Temp space used: 0
Merge join Cost: 54 Resp: 54
HA Join
Outer table:
resc: 2 cdn: 136 rcz: 24 deg: 1 resp: 2
Inner table: SOC_LIST
resc: 1 cdn: 17584 rcz: 10 deg: 1 resp: 1
using join:8 distribution:2 #groups:1
Hash join one ptn Resc: 1 Deg: 1
hash_area: 154 (max=7680) buildfrag: 1 probefrag: 48 ppasses: 1
Hash join Resc: 4 Resp: 4
Final - All Rows Plan:
JOIN ORDER: 1
CST: 4 CDN: 135 RSC: 4 RSP: 4 BYTES: 4590
IO-RSC: 4 IO-RSP: 4 CPU-RSC: 0 CPU-RSP: 0
QUERY
SELECT count(*)
FROM SOC_LIST SOC
WHERE
( EXISTS( SELECT 1
FROM ELIGIBILITY_RELATION
WHERE SRC_CODE = 'SHDMM4215'
AND DEST_CODE = SOC.SOC
AND SRC_TYPE = 'P'
AND DEST_TYPE = 'S'))
=====================
PARSING IN CURSOR #1 len=278 dep=0 uid=33 oct=3 lid=33 tim=3017645761269 hv=183981413 ad='492d5bb0'
SELECT count(*)
FROM SOC_LIST SOC
WHERE
( EXISTS( SELECT 1
FROM ELIGIBILITY_RELATION
WHERE SRC_CODE = 'SHDMM4215'
AND DEST_CODE = SOC.SOC
AND SRC_TYPE = 'P'
AND DEST_TYPE = 'S'))
END OF STMT
PARSE #1:c=10000,e=8343,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017645761258
BINDS #1:
EXEC #1:c=0,e=529,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017645761970
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
WAIT #1: nam='db file sequential read' ela= 9290 p1=2535 p2=142378 p3=1
WAIT #1: nam='db file sequential read' ela= 2098 p1=2535 p2=142379 p3=1
WAIT #1: nam='db file sequential read' ela= 11574 p1=2535 p2=33834 p3=1
WAIT #1: nam='db file sequential read' ela= 10290 p1=2536 p2=60958 p3=1
WAIT #1: nam='db file sequential read' ela= 11469 p1=2535 p2=61232 p3=1
WAIT #1: nam='db file sequential read' ela= 378 p1=2535 p2=61233 p3=1
WAIT #1: nam='db file sequential read' ela= 5493 p1=2535 p2=39498 p3=1
WAIT #1: nam='db file sequential read' ela= 7397 p1=2536 p2=68185 p3=1
WAIT #1: nam='db file sequential read' ela= 10037 p1=2536 p2=68520 p3=1
WAIT #1: nam='db file sequential read' ela= 16125 p1=2535 p2=68809 p3=1
WAIT #1: nam='db file sequential read' ela= 12426 p1=2535 p2=45162 p3=1
WAIT #1: nam='db file sequential read' ela= 12447 p1=2535 p2=178335 p3=1
WAIT #1: nam='db file sequential read' ela= 5974 p1=2535 p2=178798 p3=1
WAIT #1: nam='db file sequential read' ela= 1247 p1=2535 p2=178799 p3=1
WAIT #1: nam='db file sequential read' ela= 11010 p1=2535 p2=50826 p3=1
WAIT #1: nam='db file sequential read' ela= 5421 p1=2536 p2=260451 p3=1
WAIT #1: nam='db file sequential read' ela= 8230 p1=2536 p2=261538 p3=1
WAIT #1: nam='db file sequential read' ela= 350 p1=2535 p2=142380 p3=1
WAIT #1: nam='db file sequential read' ela= 346 p1=2535 p2=142381 p3=1
WAIT #1: nam='db file sequential read' ela= 343 p1=2535 p2=142382 p3=1
WAIT #1: nam='db file sequential read' ela= 480 p1=2535 p2=142383 p3=1
WAIT #1: nam='db file sequential read' ela= 10237 p1=2535 p2=142384 p3=1
WAIT #1: nam='db file sequential read' ela= 324 p1=2535 p2=142385 p3=1
WAIT #1: nam='db file sequential read' ela= 359 p1=2535 p2=142386 p3=1
WAIT #1: nam='db file sequential read' ela= 361 p1=2535 p2=142387 p3=1
WAIT #1: nam='db file sequential read' ela= 375 p1=2535 p2=142388 p3=1
WAIT #1: nam='db file sequential read' ela= 425 p1=2535 p2=142389 p3=1
WAIT #1: nam='db file sequential read' ela= 540 p1=2535 p2=142390 p3=1
WAIT #1: nam='db file sequential read' ela= 368 p1=2535 p2=142391 p3=1
WAIT #1: nam='db file sequential read' ela= 479 p1=2535 p2=142392 p3=1
WAIT #1: nam='db file sequential read' ela= 450 p1=2535 p2=142393 p3=1
WAIT #1: nam='db file sequential read' ela= 307 p1=2535 p2=142394 p3=1
WAIT #1: nam='db file sequential read' ela= 324 p1=2535 p2=142395 p3=1
WAIT #1: nam='db file sequential read' ela= 396 p1=2535 p2=142396 p3=1
WAIT #1: nam='db file sequential read' ela= 376 p1=2535 p2=142397 p3=1
WAIT #1: nam='db file sequential read' ela= 295 p1=2535 p2=142398 p3=1
WAIT #1: nam='db file sequential read' ela= 391 p1=2535 p2=142399 p3=1
WAIT #1: nam='db file sequential read' ela= 396 p1=2535 p2=142400 p3=1
WAIT #1: nam='db file sequential read' ela= 344 p1=2535 p2=142401 p3=1
WAIT #1: nam='db file sequential read' ela= 337 p1=2535 p2=142402 p3=1
WAIT #1: nam='db file sequential read' ela= 360 p1=2535 p2=142403 p3=1
WAIT #1: nam='db file sequential read' ela= 402 p1=2535 p2=142404 p3=1
WAIT #1: nam='db file sequential read' ela= 343 p1=2535 p2=142405 p3=1
WAIT #1: nam='db file sequential read' ela= 408 p1=2535 p2=142406 p3=1
WAIT #1: nam='db file sequential read' ela= 388 p1=2535 p2=142407 p3=1
WAIT #1: nam='db file sequential read' ela= 400 p1=2535 p2=142408 p3=1
WAIT #1: nam='db file sequential read' ela= 7999 p1=2536 p2=617 p3=1
WAIT #1: nam='db file sequential read' ela= 520 p1=2536 p2=618 p3=1
WAIT #1: nam='db file sequential read' ela= 294 p1=2536 p2=619 p3=1
WAIT #1: nam='db file sequential read' ela= 311 p1=2536 p2=620 p3=1
WAIT #1: nam='db file sequential read' ela= 316 p1=2536 p2=621 p3=1
WAIT #1: nam='db file sequential read' ela= 306 p1=2536 p2=622 p3=1
WAIT #1: nam='db file sequential read' ela= 303 p1=2536 p2=623 p3=1
WAIT #1: nam='db file sequential read' ela= 1776 p1=2536 p2=624 p3=1
FETCH #1:c=50000,e=216800,p=54,cr=54,cu=0,mis=0,r=1,dep=0,og=4,tim=3017645978865
WAIT #1: nam='SQL*Net message from client' ela= 2802 p1=1413697536 p2=1 p3=0
FETCH #1:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017645981803
WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:34:28.160
WAIT #1: nam='SQL*Net message from client' ela= 36844121 p1=1413697536 p2=1 p3=0
STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=54 r=54 w=0 time=216788 us)'
STAT #1 id=2 cnt=157 pid=1 pos=1 obj=0 op='MERGE JOIN SEMI (cr=54 r=54 w=0 time=216734 us)'
STAT #1 id=3 cnt=14296 pid=2 pos=1 obj=5769123 op='INDEX FULL SCAN SOC_LIST_1IX (cr=39 r=39 w=0 time=55399 us)'
STAT #1 id=4 cnt=157 pid=2 pos=2 obj=0 op='SORT UNIQUE (cr=15 r=15 w=0 time=141933 us)'
STAT #1 id=5 cnt=286 pid=4 pos=1 obj=0 op='PARTITION HASH ALL PARTITION: 1 4 (cr=15 r=15 w=0 time=130847 us)'
STAT #1 id=6 cnt=286 pid=5 pos=1 obj=5401812 op='INDEX RANGE SCAN ELIGIBILITY_RELATION_PK PARTITION: 1 4 (cr=15 r=15 w=0 time=130716 us)'
QUERY
BEGIN := 'N'; END;
=====================
PARSING IN CURSOR #1 len=23 dep=0 uid=33 oct=47 lid=33 tim=3017682828223 hv=16287806 ad='464edb18'
BEGIN := 'N'; END;
END OF STMT
PARSE #1:c=0,e=1569,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017682828214
BINDS #1:
bind 0: dty=96 mxl=01(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=200071100000000 size=8 offset=0
bfp=800003ffefe9f748 bln=01 avl=00 flg=05
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
EXEC #1:c=0,e=5494,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017682833795
*** 2013-06-10 13:34:44.174
WAIT #1: nam='SQL*Net message from client' ela= 15630899 p1=1413697536 p2=1 p3=0
QUERY
SELECT count(*)
FROM SOC_LIST SOC
WHERE ( = 'Y')
=====================
PARSING IN CURSOR #1 len=65 dep=0 uid=33 oct=3 lid=33 tim=3017698466665 hv=900106749 ad='43145458'
SELECT count(*)
FROM SOC_LIST SOC
WHERE ( = 'Y')
END OF STMT
PARSE #1:c=0,e=1409,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017698466654
PARAMETERS USED BY THE OPTIMIZER
OPTIMIZER_FEATURES_ENABLE = 9.2.0
OPTIMIZER_MODE/GOAL = Choose
_OPTIMIZER_PERCENT_PARALLEL = 101
HASH_AREA_SIZE = 131072
HASH_JOIN_ENABLED = TRUE
HASH_MULTIBLOCK_IO_COUNT = 0
SORT_AREA_SIZE = 65536
OPTIMIZER_SEARCH_LIMIT = 5
PARTITION_VIEW_ENABLED = FALSE
_ALWAYS_STAR_TRANSFORMATION = FALSE
_B_TREE_BITMAP_PLANS = TRUE
STAR_TRANSFORMATION_ENABLED = FALSE
_COMPLEX_VIEW_MERGING = TRUE
_PUSH_JOIN_PREDICATE = TRUE
PARALLEL_BROADCAST_ENABLED = TRUE
OPTIMIZER_MAX_PERMUTATIONS = 2000
OPTIMIZER_INDEX_CACHING = 0
_SYSTEM_INDEX_CACHING = 0
OPTIMIZER_INDEX_COST_ADJ = 1
OPTIMIZER_DYNAMIC_SAMPLING = 1
_OPTIMIZER_DYN_SMP_BLKS = 32
QUERY_REWRITE_ENABLED = TRUE
QUERY_REWRITE_INTEGRITY = ENFORCED
_INDEX_JOIN_ENABLED = TRUE
_SORT_ELIMINATION_COST_RATIO = 0
_OR_EXPAND_NVL_PREDICATE = TRUE
_NEW_INITIAL_JOIN_ORDERS = TRUE
ALWAYS_ANTI_JOIN = CHOOSE
ALWAYS_SEMI_JOIN = CHOOSE
_OPTIMIZER_MODE_FORCE = TRUE
_OPTIMIZER_UNDO_CHANGES = FALSE
_UNNEST_SUBQUERY = TRUE
_PUSH_JOIN_UNION_VIEW = TRUE
_FAST_FULL_SCAN_ENABLED = TRUE
_OPTIM_ENHANCE_NNULL_DETECTION = TRUE
_ORDERED_NESTED_LOOP = TRUE
_NESTED_LOOP_FUDGE = 100
_NO_OR_EXPANSION = FALSE
_QUERY_COST_REWRITE = TRUE
QUERY_REWRITE_EXPRESSION = TRUE
_IMPROVED_ROW_LENGTH_ENABLED = TRUE
_USE_NOSEGMENT_INDEXES = FALSE
_ENABLE_TYPE_DEP_SELECTIVITY = TRUE
_IMPROVED_OUTERJOIN_CARD = TRUE
_OPTIMIZER_ADJUST_FOR_NULLS = TRUE
_OPTIMIZER_CHOOSE_PERMUTATION = 0
_USE_COLUMN_STATS_FOR_FUNCTION = TRUE
_SUBQUERY_PRUNING_ENABLED = TRUE
_SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
_SUBQUERY_PRUNING_COST_FACTOR = 20
_LIKE_WITH_BIND_AS_EQUALITY = FALSE
_TABLE_SCAN_COST_PLUS_ONE = TRUE
_SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
_DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
_ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
_OPTIMIZER_COST_MODEL = CHOOSE
_GSETS_ALWAYS_USE_TEMPTABLES = FALSE
DB_FILE_MULTIBLOCK_READ_COUNT = 128
_NEW_SORT_COST_ESTIMATE = TRUE
_GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
_CPU_TO_IO = 0
_PRED_MOVE_AROUND = TRUE
BASE STATISTICAL INFORMATION
Table stats Table: SOC_LIST Alias: SOC
TOTAL :: CDN: 17584 NBLKS: 653 AVG_ROW_LEN: 260
-- Index stats
INDEX NAME: I_SNAP$_SOC_LIST COL#: 1
TOTAL :: LVLS: 1 #LB: 64 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 699
INDEX NAME: SOC_LIST_1IX COL#: 3
TOTAL :: LVLS: 1 #LB: 47 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 14065
_OPTIMIZER_PERCENT_PARALLEL = 0
SINGLE TABLE ACCESS PATH
TABLE: SOC_LIST ORIG CDN: 17584 ROUNDED CDN: 17584 CMPTD CDN: 17584
Access path: tsc Resc: 18 Resp: 18
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
BEST_CST: 18.00 PATH: 2 Degree: 1
OPTIMIZER STATISTICS AND COMPUTATIONS
GENERAL PLANS
Join order[1]: SOC_LIST[SOC]#0
Best so far: TABLE#: 0 CST: 18 CDN: 17584 BYTES: 0
Final - All Rows Plan:
JOIN ORDER: 1
CST: 18 CDN: 17584 RSC: 18 RSP: 18 BYTES: 0
IO-RSC: 18 IO-RSP: 18 CPU-RSC: 0 CPU-RSP: 0
BINDS #1:
bind 0: dty=96 mxl=32(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=32 offset=0
bfp=800003ffefea9490 bln=32 avl=01 flg=05
value="N"
EXEC #1:c=0,e=152,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017698469481
WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
FETCH #1:c=10000,e=1506,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017698471536
WAIT #1: nam='SQL*Net message from client' ela= 2607 p1=1413697536 p2=1 p3=0
FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017698474268
WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:35:07.656
WAIT #1: nam='SQL*Net message from client' ela= 22922584 p1=1413697536 p2=1 p3=0
STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=0 r=0 w=0 time=93 us)'
STAT #1 id=2 cnt=0 pid=1 pos=1 obj=0 op='FILTER (cr=0 r=0 w=0 time=29 us)'
STAT #1 id=3 cnt=0 pid=2 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST '
=====================
PARSE ERROR #1:len=369 dep=0 uid=33 oct=0 lid=33 tim=3017721397730 err=900
exec := 'N'
SELEC ...
WAIT #1: nam='SQL*Net break/reset to client' ela= 2 p1=1413697536 p2=1 p3=0
WAIT #1: nam='SQL*Net break/reset to client' ela= 2403 p1=1413697536 p2=0 p3=0
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:35:24.017
WAIT #1: nam='SQL*Net message from client' ela= 15973854 p1=1413697536 p2=1 p3=0
QUERY
SELECT count(*)
FROM SOC_LIST SOC
WHERE
( EXISTS( SELECT 1
FROM ELIGIBILITY_RELATION
WHERE SRC_CODE = 'SHDMM4215'
AND DEST_CODE = SOC.SOC
AND SRC_TYPE = 'P'
AND DEST_TYPE = 'S'))
UNION ALL
SELECT count(*)
FROM SOC_LIST SOC
WHERE ( = 'Y')
=====================
PARSING IN CURSOR #1 len=353 dep=0 uid=33 oct=3 lid=33 tim=3017737377655 hv=4202798596 ad='45639568'
SELECT count(*)
FROM SOC_LIST SOC
WHERE
( EXISTS( SELECT 1
FROM ELIGIBILITY_RELATION
WHERE SRC_CODE = 'SHDMM4215'
AND DEST_CODE = SOC.SOC
AND SRC_TYPE = 'P'
AND DEST_TYPE = 'S'))
UNION ALL
SELECT count(*)
FROM SOC_LIST SOC
WHERE ( = 'Y')
END OF STMT
PARSE #1:c=0,e=2624,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017737377644
PARAMETERS USED BY THE OPTIMIZER
OPTIMIZER_FEATURES_ENABLE = 9.2.0
OPTIMIZER_MODE/GOAL = Choose
_OPTIMIZER_PERCENT_PARALLEL = 101
HASH_AREA_SIZE = 131072
HASH_JOIN_ENABLED = TRUE
HASH_MULTIBLOCK_IO_COUNT = 0
SORT_AREA_SIZE = 65536
OPTIMIZER_SEARCH_LIMIT = 5
PARTITION_VIEW_ENABLED = FALSE
_ALWAYS_STAR_TRANSFORMATION = FALSE
_B_TREE_BITMAP_PLANS = TRUE
STAR_TRANSFORMATION_ENABLED = FALSE
_COMPLEX_VIEW_MERGING = TRUE
_PUSH_JOIN_PREDICATE = TRUE
PARALLEL_BROADCAST_ENABLED = TRUE
OPTIMIZER_MAX_PERMUTATIONS = 2000
OPTIMIZER_INDEX_CACHING = 0
_SYSTEM_INDEX_CACHING = 0
OPTIMIZER_INDEX_COST_ADJ = 1
OPTIMIZER_DYNAMIC_SAMPLING = 1
_OPTIMIZER_DYN_SMP_BLKS = 32
QUERY_REWRITE_ENABLED = TRUE
QUERY_REWRITE_INTEGRITY = ENFORCED
_INDEX_JOIN_ENABLED = TRUE
_SORT_ELIMINATION_COST_RATIO = 0
_OR_EXPAND_NVL_PREDICATE = TRUE
_NEW_INITIAL_JOIN_ORDERS = TRUE
ALWAYS_ANTI_JOIN = CHOOSE
ALWAYS_SEMI_JOIN = CHOOSE
_OPTIMIZER_MODE_FORCE = TRUE
_OPTIMIZER_UNDO_CHANGES = FALSE
_UNNEST_SUBQUERY = TRUE
_PUSH_JOIN_UNION_VIEW = TRUE
_FAST_FULL_SCAN_ENABLED = TRUE
_OPTIM_ENHANCE_NNULL_DETECTION = TRUE
_ORDERED_NESTED_LOOP = TRUE
_NESTED_LOOP_FUDGE = 100
_NO_OR_EXPANSION = FALSE
_QUERY_COST_REWRITE = TRUE
QUERY_REWRITE_EXPRESSION = TRUE
_IMPROVED_ROW_LENGTH_ENABLED = TRUE
_USE_NOSEGMENT_INDEXES = FALSE
_ENABLE_TYPE_DEP_SELECTIVITY = TRUE
_IMPROVED_OUTERJOIN_CARD = TRUE
_OPTIMIZER_ADJUST_FOR_NULLS = TRUE
_OPTIMIZER_CHOOSE_PERMUTATION = 0
_USE_COLUMN_STATS_FOR_FUNCTION = TRUE
_SUBQUERY_PRUNING_ENABLED = TRUE
_SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
_SUBQUERY_PRUNING_COST_FACTOR = 20
_LIKE_WITH_BIND_AS_EQUALITY = FALSE
_TABLE_SCAN_COST_PLUS_ONE = TRUE
_SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
_DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
_ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
_OPTIMIZER_COST_MODEL = CHOOSE
_GSETS_ALWAYS_USE_TEMPTABLES = FALSE
DB_FILE_MULTIBLOCK_READ_COUNT = 128
_NEW_SORT_COST_ESTIMATE = TRUE
_GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
_CPU_TO_IO = 0
_PRED_MOVE_AROUND = TRUE
BASE STATISTICAL INFORMATION
Table stats Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
(Using composite stats)
(adjusted for partition skews)
ORIG STATS:: CDN: 11982220 NBLKS: 125493 AVG_ROW_LEN: 71
PARTCNT::
PRUNED: 4 ANALYZED: 4 UNANALYZED: 0
TOTAL :: CDN: 11982220 NBLKS: 125493 AVG_ROW_LEN: 71
-- Index stats
INDEX NAME: ELIGIBILITY_RELATION_1IX COL#: 3 4 5
USING COMPOSITE STATS
TOTAL :: LVLS: 2 #LB: 38360 #DK: 4164 LB/K: 9 DB/K: 740 CLUF: 3081860
INDEX NAME: ELIGIBILITY_RELATION_PK COL#: 2 3 4 5
USING COMPOSITE STATS
TOTAL :: LVLS: 2 #LB: 50740 #DK: 11873160 LB/K: 1 DB/K: 1 CLUF: 9158280
INDEX NAME: I_SNAP$_ELIGIBILITY_RELATI COL#: 1
TOTAL :: LVLS: 2 #LB: 49600 #DK: 11953600 LB/K: 1 DB/K: 1 CLUF: 8833300
_OPTIMIZER_PERCENT_PARALLEL = 0
SINGLE TABLE ACCESS PATH
Column: SRC_CODE Col#: 2 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 22087 NULLS: 0 DENS: 4.5276e-05
NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: DEST_CODE Col#: 4 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 11970 NULLS: 0 DENS: 8.3542e-05
NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: SRC_TYPE Col#: 3 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 2 NULLS: 0 DENS: 5.0000e-01
NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: DEST_TYPE Col#: 5 Table: ELIGIBILITY_RELATION Alias: ELIGIBILITY_RELATION
NDV: 2 NULLS: 0 DENS: 5.0000e-01
NO HISTOGRAM: #BKT: 1 #VAL: 2
TABLE: ELIGIBILITY_RELATION ORIG CDN: 11982220 ROUNDED CDN: 1 CMPTD CDN: 0
Access path: tsc Resc: 3072 Resp: 3072
Access path: index (iff)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 1243
IX_SEL: 0.0000e+00 TB_SEL: 1.0000e+00
Access path: iff Resc: 1243 Resp: 1243
Access path: index (unique)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 2
IX_SEL: 8.3457e-08 TB_SEL: 8.3457e-08
Access path: index (equal)
Index: ELIGIBILITY_RELATION_1IX
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 68
IX_SEL: 0.0000e+00 TB_SEL: 2.0886e-05
Access path: index (eq-unique)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 2
IX_SEL: 0.0000e+00 TB_SEL: 0.0000e+00
****** trying bitmap/domain indexes ******
Access path: index (equal)
Index: ELIGIBILITY_RELATION_1IX
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 3
IX_SEL: 2.0886e-05 TB_SEL: 2.0886e-05
Access path: index (index-only)
Index: ELIGIBILITY_RELATION_PK
TABLE: ELIGIBILITY_RELATION
RSC_CPU: 0 RSC_IO: 5
IX_SEL: 4.5276e-05 TB_SEL: 4.5276e-05
SORT resource Sort statistics
Sort width: 11 Area size: 628736 Max Area size: 31457280 Degree: 1
Blocks to Sort: 2 Row size: 21 Rows: 543
Initial runs: 1 Merge passes: 1 IO Cost / pass: 3
Total IO sort cost: 2
Total CPU sort cost: 0
Total Temp space used: 0
****** finished trying bitmap/domain indexes ******
One row CDN: 1
BEST_CST: 1.00 PATH: 3 Degree: 1
OPTIMIZER STATISTICS AND COMPUTATIONS
GENERAL PLANS
Join order[1]: ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#0
Best so far: TABLE#: 0 CST: 1 CDN: 1 BYTES: 24
Final - First Rows Plan:
JOIN ORDER: 1
CST: 1 CDN: 1 RSC: 1 RSP: 1 BYTES: 24
IO-RSC: 1 IO-RSP: 1 CPU-RSC: 0 CPU-RSP: 0
First Rows Plan
PARAMETERS USED BY THE OPTIMIZER
OPTIMIZER_FEATURES_ENABLE = 9.2.0
OPTIMIZER_MODE/GOAL = Choose
_OPTIMIZER_PERCENT_PARALLEL = 101
HASH_AREA_SIZE = 131072
HASH_JOIN_ENABLED = TRUE
HASH_MULTIBLOCK_IO_COUNT = 0
SORT_AREA_SIZE = 65536
OPTIMIZER_SEARCH_LIMIT = 5
PARTITION_VIEW_ENABLED = FALSE
_ALWAYS_STAR_TRANSFORMATION = FALSE
_B_TREE_BITMAP_PLANS = TRUE
STAR_TRANSFORMATION_ENABLED = FALSE
_COMPLEX_VIEW_MERGING = TRUE
_PUSH_JOIN_PREDICATE = TRUE
PARALLEL_BROADCAST_ENABLED = TRUE
OPTIMIZER_MAX_PERMUTATIONS = 2000
OPTIMIZER_INDEX_CACHING = 0
_SYSTEM_INDEX_CACHING = 0
OPTIMIZER_INDEX_COST_ADJ = 1
OPTIMIZER_DYNAMIC_SAMPLING = 1
_OPTIMIZER_DYN_SMP_BLKS = 32
QUERY_REWRITE_ENABLED = TRUE
QUERY_REWRITE_INTEGRITY = ENFORCED
_INDEX_JOIN_ENABLED = TRUE
_SORT_ELIMINATION_COST_RATIO = 0
_OR_EXPAND_NVL_PREDICATE = TRUE
_NEW_INITIAL_JOIN_ORDERS = TRUE
ALWAYS_ANTI_JOIN = CHOOSE
ALWAYS_SEMI_JOIN = CHOOSE
_OPTIMIZER_MODE_FORCE = TRUE
_OPTIMIZER_UNDO_CHANGES = FALSE
_UNNEST_SUBQUERY = TRUE
_PUSH_JOIN_UNION_VIEW = TRUE
_FAST_FULL_SCAN_ENABLED = TRUE
_OPTIM_ENHANCE_NNULL_DETECTION = TRUE
_ORDERED_NESTED_LOOP = TRUE
_NESTED_LOOP_FUDGE = 100
_NO_OR_EXPANSION = FALSE
_QUERY_COST_REWRITE = TRUE
QUERY_REWRITE_EXPRESSION = TRUE
_IMPROVED_ROW_LENGTH_ENABLED = TRUE
_USE_NOSEGMENT_INDEXES = FALSE
_ENABLE_TYPE_DEP_SELECTIVITY = TRUE
_IMPROVED_OUTERJOIN_CARD = TRUE
_OPTIMIZER_ADJUST_FOR_NULLS = TRUE
_OPTIMIZER_CHOOSE_PERMUTATION = 0
_USE_COLUMN_STATS_FOR_FUNCTION = TRUE
_SUBQUERY_PRUNING_ENABLED = TRUE
_SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
_SUBQUERY_PRUNING_COST_FACTOR = 20
_LIKE_WITH_BIND_AS_EQUALITY = FALSE
_TABLE_SCAN_COST_PLUS_ONE = TRUE
_SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
_DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
_ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
_OPTIMIZER_COST_MODEL = CHOOSE
_GSETS_ALWAYS_USE_TEMPTABLES = FALSE
DB_FILE_MULTIBLOCK_READ_COUNT = 128
_NEW_SORT_COST_ESTIMATE = TRUE
_GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
_CPU_TO_IO = 0
_PRED_MOVE_AROUND = TRUE
BASE STATISTICAL INFORMATION
Table stats Table: SOC_LIST Alias: SYS_ALIAS_1
TOTAL :: CDN: 17584 NBLKS: 653 AVG_ROW_LEN: 260
-- Index stats
INDEX NAME: I_SNAP$_SOC_LIST COL#: 1
TOTAL :: LVLS: 1 #LB: 64 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 699
INDEX NAME: SOC_LIST_1IX COL#: 3
TOTAL :: LVLS: 1 #LB: 47 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 14065
_OPTIMIZER_PERCENT_PARALLEL = 0
SINGLE TABLE ACCESS PATH
TABLE: SOC_LIST ORIG CDN: 17584 ROUNDED CDN: 879 CMPTD CDN: 879
Access path: tsc Resc: 18 Resp: 18
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
BEST_CST: 18.00 PATH: 2 Degree: 1
OPTIMIZER STATISTICS AND COMPUTATIONS
GENERAL PLANS
Join order[1]: SOC_LIST[SYS_ALIAS_1]#0
Best so far: TABLE#: 0 CST: 18 CDN: 879 BYTES: 8790
Final - All Rows Plan:
JOIN ORDER: 1
CST: 18 CDN: 879 RSC: 18 RSP: 18 BYTES: 8790
IO-RSC: 18 IO-RSP: 18 CPU-RSC: 0 CPU-RSP: 0
PARAMETERS USED BY THE OPTIMIZER
OPTIMIZER_FEATURES_ENABLE = 9.2.0
OPTIMIZER_MODE/GOAL = Choose
_OPTIMIZER_PERCENT_PARALLEL = 101
HASH_AREA_SIZE = 131072
HASH_JOIN_ENABLED = TRUE
HASH_MULTIBLOCK_IO_COUNT = 0
SORT_AREA_SIZE = 65536
OPTIMIZER_SEARCH_LIMIT = 5
PARTITION_VIEW_ENABLED = FALSE
_ALWAYS_STAR_TRANSFORMATION = FALSE
_B_TREE_BITMAP_PLANS = TRUE
STAR_TRANSFORMATION_ENABLED = FALSE
_COMPLEX_VIEW_MERGING = TRUE
_PUSH_JOIN_PREDICATE = TRUE
PARALLEL_BROADCAST_ENABLED = TRUE
OPTIMIZER_MAX_PERMUTATIONS = 2000
OPTIMIZER_INDEX_CACHING = 0
_SYSTEM_INDEX_CACHING = 0
OPTIMIZER_INDEX_COST_ADJ = 1
OPTIMIZER_DYNAMIC_SAMPLING = 1
_OPTIMIZER_DYN_SMP_BLKS = 32
QUERY_REWRITE_ENABLED = TRUE
QUERY_REWRITE_INTEGRITY = ENFORCED
_INDEX_JOIN_ENABLED = TRUE
_SORT_ELIMINATION_COST_RATIO = 0
_OR_EXPAND_NVL_PREDICATE = TRUE
_NEW_INITIAL_JOIN_ORDERS = TRUE
ALWAYS_ANTI_JOIN = CHOOSE
ALWAYS_SEMI_JOIN = CHOOSE
_OPTIMIZER_MODE_FORCE = TRUE
_OPTIMIZER_UNDO_CHANGES = FALSE
_UNNEST_SUBQUERY = TRUE
_PUSH_JOIN_UNION_VIEW = TRUE
_FAST_FULL_SCAN_ENABLED = TRUE
_OPTIM_ENHANCE_NNULL_DETECTION = TRUE
_ORDERED_NESTED_LOOP = TRUE
_NESTED_LOOP_FUDGE = 100
_NO_OR_EXPANSION = FALSE
_QUERY_COST_REWRITE = TRUE
QUERY_REWRITE_EXPRESSION = TRUE
_IMPROVED_ROW_LENGTH_ENABLED = TRUE
_USE_NOSEGMENT_INDEXES = FALSE
_ENABLE_TYPE_DEP_SELECTIVITY = TRUE
_IMPROVED_OUTERJOIN_CARD = TRUE
_OPTIMIZER_ADJUST_FOR_NULLS = TRUE
_OPTIMIZER_CHOOSE_PERMUTATION = 0
_USE_COLUMN_STATS_FOR_FUNCTION = TRUE
_SUBQUERY_PRUNING_ENABLED = TRUE
_SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
_SUBQUERY_PRUNING_COST_FACTOR = 20
_LIKE_WITH_BIND_AS_EQUALITY = FALSE
_TABLE_SCAN_COST_PLUS_ONE = TRUE
_SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
_DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
_ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
_OPTIMIZER_COST_MODEL = CHOOSE
_GSETS_ALWAYS_USE_TEMPTABLES = FALSE
DB_FILE_MULTIBLOCK_READ_COUNT = 128
_NEW_SORT_COST_ESTIMATE = TRUE
_GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
_CPU_TO_IO = 0
_PRED_MOVE_AROUND = TRUE
BASE STATISTICAL INFORMATION
Table stats Table: SOC_LIST Alias: SOC
TOTAL :: CDN: 17584 NBLKS: 653 AVG_ROW_LEN: 260
-- Index stats
INDEX NAME: I_SNAP$_SOC_LIST COL#: 1
TOTAL :: LVLS: 1 #LB: 64 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 699
INDEX NAME: SOC_LIST_1IX COL#: 3
TOTAL :: LVLS: 1 #LB: 47 #DK: 17487 LB/K: 1 DB/K: 1 CLUF: 14065
_OPTIMIZER_PERCENT_PARALLEL = 0
SINGLE TABLE ACCESS PATH
TABLE: SOC_LIST ORIG CDN: 17584 ROUNDED CDN: 17584 CMPTD CDN: 17584
Access path: tsc Resc: 18 Resp: 18
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
BEST_CST: 18.00 PATH: 2 Degree: 1
OPTIMIZER STATISTICS AND COMPUTATIONS
GENERAL PLANS
Join order[1]: SOC_LIST[SOC]#0
Best so far: TABLE#: 0 CST: 18 CDN: 17584 BYTES: 0
Final - All Rows Plan:
JOIN ORDER: 1
CST: 18 CDN: 17584 RSC: 18 RSP: 18 BYTES: 0
IO-RSC: 18 IO-RSP: 18 CPU-RSC: 0 CPU-RSP: 0
BINDS #1:
bind 0: dty=96 mxl=32(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=32 offset=0
bfp=800003ffefea9490 bln=32 avl=01 flg=05
value="N"
EXEC #1:c=0,e=159,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017737385286
WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1413697536 p2=1 p3=0
WAIT #1: nam='db file sequential read' ela= 9958 p1=586 p2=128001 p3=1
WAIT #1: nam='db file scattered read' ela= 619 p1=586 p2=128002 p3=4
WAIT #1: nam='db file sequential read' ela= 12880 p1=2535 p2=39498 p3=1
WAIT #1: nam='db file sequential read' ela= 39878 p1=2536 p2=68185 p3=1
WAIT #1: nam='db file sequential read' ela= 10240 p1=2536 p2=68520 p3=1
WAIT #1: nam='db file sequential read' ela= 15805 p1=2535 p2=45162 p3=1
WAIT #1: nam='db file sequential read' ela= 11733 p1=2535 p2=178335 p3=1
WAIT #1: nam='db file sequential read' ela= 11863 p1=2535 p2=178798 p3=1
WAIT #1: nam='db file sequential read' ela= 4886 p1=2535 p2=33834 p3=1
WAIT #1: nam='db file sequential read' ela= 12067 p1=2536 p2=60958 p3=1
WAIT #1: nam='db file sequential read' ela= 16496 p1=2535 p2=61232 p3=1
WAIT #1: nam='db file sequential read' ela= 8970 p1=2535 p2=50826 p3=1
WAIT #1: nam='db file sequential read' ela= 10940 p1=2536 p2=260451 p3=1
WAIT #1: nam='db file sequential read' ela= 8508 p1=2536 p2=261538 p3=1
WAIT #1: nam='db file scattered read' ela= 32000 p1=1613 p2=4622 p3=35
WAIT #1: nam='db file sequential read' ela= 1762 p1=2535 p2=178799 p3=1
WAIT #1: nam='db file sequential read' ela= 341 p1=2535 p2=61233 p3=1
WAIT #1: nam='db file scattered read' ela= 50494 p1=957 p2=230324 p3=35
WAIT #1: nam='db file scattered read' ela= 36716 p1=5 p2=588169 p3=35
WAIT #1: nam='db file scattered read' ela= 45241 p1=2326 p2=227427 p3=35
WAIT #1: nam='db file sequential read' ela= 11783 p1=2535 p2=68809 p3=1
WAIT #1: nam='db file scattered read' ela= 26720 p1=471 p2=102809 p3=35
WAIT #1: nam='db file scattered read' ela= 31074 p1=1496 p2=97015 p3=35
WAIT #1: nam='db file scattered read' ela= 39750 p1=586 p2=69452 p3=35
WAIT #1: nam='db file scattered read' ela= 30923 p1=1613 p2=8636 p3=35
WAIT #1: nam='db file scattered read' ela= 46328 p1=957 p2=67050 p3=35
WAIT #1: nam='db file scattered read' ela= 34570 p1=5 p2=362823 p3=35
WAIT #1: nam='db file scattered read' ela= 43343 p1=2326 p2=240311 p3=35
WAIT #1: nam='db file scattered read' ela= 30818 p1=471 p2=76417 p3=35
WAIT #1: nam='db file scattered read' ela= 19167 p1=1496 p2=480612 p3=35
WAIT #1: nam='db file scattered read' ela= 26405 p1=586 p2=193036 p3=35
WAIT #1: nam='db file scattered read' ela= 35374 p1=1613 p2=201565 p3=35
WAIT #1: nam='db file scattered read' ela= 14275 p1=957 p2=15804 p3=7
FETCH #1:c=190000,e=926019,p=552,cr=43429,cu=0,mis=0,r=1,dep=0,og=4,tim=3017738311433
WAIT #1: nam='SQL*Net message from client' ela= 2749 p1=1413697536 p2=1 p3=0
WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1413697536 p2=1 p3=0
FETCH #1:c=0,e=79,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017738314443
*** 2013-06-10 13:35:44.078
WAIT #1: nam='SQL*Net message from client' ela= 18650883 p1=1413697536 p2=1 p3=0
STAT #1 id=1 cnt=2 pid=0 pos=1 obj=0 op='UNION-ALL (cr=43429 r=552 w=0 time=926047 us)'
STAT #1 id=2 cnt=1 pid=1 pos=1 obj=0 op='SORT AGGREGATE (cr=43429 r=552 w=0 time=925989 us)'
STAT #1 id=3 cnt=157 pid=2 pos=1 obj=0 op='FILTER (cr=43429 r=552 w=0 time=925909 us)'
STAT #1 id=4 cnt=14296 pid=3 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST (cr=541 r=537 w=0 time=579577 us)'
STAT #1 id=5 cnt=157 pid=3 pos=2 obj=0 op='PARTITION HASH SINGLE PARTITION: KEY KEY (cr=42888 r=15 w=0 time=285564 us)'
STAT #1 id=6 cnt=157 pid=5 pos=1 obj=5401812 op='INDEX UNIQUE SCAN ELIGIBILITY_RELATION_PK PARTITION: KEY KEY (cr=42888 r=15 w=0 time=265355 us)'
STAT #1 id=7 cnt=1 pid=1 pos=2 obj=0 op='SORT AGGREGATE (cr=0 r=0 w=0 time=4 us)'
STAT #1 id=8 cnt=0 pid=7 pos=1 obj=0 op='FILTER (cr=0 r=0 w=0 time=1 us)'
STAT #1 id=9 cnt=0 pid=8 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST '
QUERY
select 'close cursor' from dual
=====================
PARSING IN CURSOR #1 len=31 dep=0 uid=33 oct=3 lid=33 tim=3017756967074 hv=3487944275 ad='48de6a60'
select 'close cursor' from dual
END OF STMT
PARSE #1:c=0,e=986,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017756967063
BINDS #1:
EXEC #1:c=0,e=47,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017756967278
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
FETCH #1:c=0,e=134,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=4,tim=3017756967515
WAIT #1: nam='SQL*Net message from client' ela= 2682 p1=1413697536 p2=1 p3=0
FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017756970325
WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:35:57.804
WAIT #1: nam='SQL*Net message from client' ela= 13399621 p1=1413697536 p2=1 p3=0
=====================
PARSING IN CURSOR #3 len=116 dep=1 uid=0 oct=3 lid=0 tim=3017770371839 hv=431456802 ad='39fbad80'
select o.owner#,o.name,o.namespace,o.remoteowner,o.linkname,o.subname,o.dataobj#,o.flags from obj$ o where o.obj#=:1
END OF STMT
PARSE #3:c=0,e=1249,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=3017770371828
BINDS #3:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0
bfp=800003ffefea7a90 bln=22 avl=03 flg=05
value=172
EXEC #3:c=0,e=666,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=3017770372725
WAIT #3: nam='db file sequential read' ela= 10318 p1=1 p2=978 p3=1
WAIT #3: nam='db file sequential read' ela= 10292 p1=1 p2=318 p3=1
FETCH #3:c=10000,e=21071,p=2,cr=3,cu=0,mis=0,r=1,dep=1,og=4,tim=3017770393830
STAT #1 id=1 cnt=1 pid=0 pos=1 obj=172 op='TABLE ACCESS FULL DUAL (cr=3 r=0 w=0 time=121 us)'
QUERY
ALTER SESSION SET EVENTS '10053 trace name context off'
=====================
PARSING IN CURSOR #1 len=55 dep=0 uid=33 oct=42 lid=33 tim=3017770394351 hv=3500836485 ad='3bed84c8'
ALTER SESSION SET EVENTS '10053 trace name context off'
END OF STMT
PARSE #1:c=0,e=227,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017770394344
BINDS #1:
EXEC #1:c=0,e=177,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017770394624
WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:36:13.139
WAIT #1: nam='SQL*Net message from client' ela= 14951473 p1=1413697536 p2=1 p3=0
=====================
PARSE ERROR #1:len=55 dep=0 uid=33 oct=42 lid=33 tim=3017785346905 err=911
ALTER SESSION SET EVENT=¿10046 trace name context off¿
WAIT #1: nam='SQL*Net break/reset to client' ela= 2 p1=1413697536 p2=1 p3=0
WAIT #1: nam='SQL*Net break/reset to client' ela= 2358 p1=1413697536 p2=0 p3=0
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:36:53.497
WAIT #1: nam='SQL*Net message from client' ela= 39408861 p1=1413697536 p2=1 p3=0
=====================
PARSE ERROR #1:len=56 dep=0 uid=33 oct=42 lid=33 tim=3017824759339 err=911
ALTER SESSION SET EVENTS ¿10046 trace name context off¿
WAIT #1: nam='SQL*Net break/reset to client' ela= 4 p1=1413697536 p2=1 p3=0
WAIT #1: nam='SQL*Net break/reset to client' ela= 2342 p1=1413697536 p2=0 p3=0
WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:37:17.528
WAIT #1: nam='SQL*Net message from client' ela= 23463963 p1=1413697536 p2=1 p3=0
=====================
PARSE ERROR #1:len=57 dep=0 uid=33 oct=42 lid=33 tim=3017848226738 err=911
ALTER SESSION SET EVENTS '10043 trace name context off';
WAIT #1: nam='SQL*Net break/reset to client' ela= 1 p1=1413697536 p2=1 p3=0
WAIT #1: nam='SQL*Net break/reset to client' ela= 2305 p1=1413697536 p2=0 p3=0
WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
WAIT #1: nam='SQL*Net message from client' ela= 9416071 p1=1413697536 p2=1 p3=0
=====================
PARSING IN CURSOR #1 len=55 dep=0 uid=33 oct=42 lid=33 tim=3017857646552 hv=2635134026 ad='4b92b7e8'
ALTER SESSION SET EVENTS '10043 trace name context off'
END OF STMT
PARSE #1:c=0,e=616,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017857646541
BINDS #1:
EXEC #1:c=0,e=285,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017857647009
WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
*** 2013-06-10 13:58:46.112
WAIT #1: nam='SQL*Net message from client' ela= 1248974802 p1=1413697536 p2=1 p3=0
XCTEND rlbk=0, rd_only=1 -
Need sql query to remove duplicates using UNION ALL clause
Hi,
I have a sql query which has UNION clause.But the UNION clause is causing some performance issues.
To overcome that I have used UNION ALL to improve performance but its returning duplicates.
Kindly anyone send a sample SQL query where my primary objective is used to use UNION ALL clause and to consider unique rows (elimating duplicate
ones)
Any help will be needful for me
Thanks and Regardswhy not UNION? :(
another way also use MINUS
SQL>
SQL> with t as
2 (
3 select 1 if from dual union all
4 select 2 if from dual union all
5 select 1 if from dual union all
6 select 3 if from dual union all
7 select 3 if from dual
8 )
9 ,t2 as
10 (
11 select 1 if from dual union all
12 select 2 if from dual union all
13 select 3 if from dual union all
14 select 4 if from dual union all
15 select 5 if from dual
16 )
17 (select if from t
18 union all
19 select if from t2)
20 /
IF
1
2
1
3
3
1
2
3
4
5
10 rows selected
SQL> so
SQL>
SQL> with t as
2 (
3 select 1 if from dual union all
4 select 2 if from dual union all
5 select 1 if from dual union all
6 select 3 if from dual union all
7 select 3 if from dual
8 )
9 ,t2 as
10 (
11 select 1 if from dual union all
12 select 2 if from dual union all
13 select 3 if from dual union all
14 select 4 if from dual union all
15 select 5 if from dual
16 )
17 (select if from t
18 union all
19 select if from t2)
20 minus
21 select -99 from dual
22 /
IF
1
2
3
4
5
SQL> -
How can we avoid union all in this query.....
Dear All,
I have a query which has union all.I want a query with the same result without using union all.Can anyone help me?Here is my query.............
SELECT DID,
DM.DISTRICT_DESCRIPTION "DISTRICT_NAME",
MID,
DM.DISTRICT_DESCRIPTION || '(D)' "MANDAL_NAME",
200706,
'SD_OB' "EXP_CAT",
SUM(NVL(AMOUNT,0))-SUM(NVL(AMOUNT1,0)) "AMOUNT" FROM
(SELECT SUBSTR(AC.PCC_INFO_CODE,3,2) "DID", SUBSTR(AC.TRANSACTION_ID,6,2) "MID",NVL(SUM(AMOUNT),0) "AMOUNT", 0 "AMOUNT1"
FROM ACCTD_CLAIMS AC
WHERE TO_CHAR(AC.CLAIM_DATE,'YYYYMM') <= PREV_MONTH(200706)
AND AC.HOA_ID='18 '
AND SUBSTR(AC.TRANSACTION_ID,1,3) <> 'CRR'
GROUP BY SUBSTR(AC.PCC_INFO_CODE,3,2),SUBSTR(AC.TRANSACTION_ID,6,2)
union all
SELECT SUBSTR(AC.PCC_INFO_CODE,3,2) "DID", SUBSTR(AC.TRANSACTION_ID,6,2) "MID",0 "AMOUNT" , NVL(SUM(AMOUNT),0) "AMOUNT1"
FROM ACCTD_CLAIMS AC
WHERE
TO_CHAR(AC.PAY_DATE,'YYYYMM') <= PREV_MONTH(200706)
AND AC.HOA_ID='18'
GROUP BY SUBSTR(AC.PCC_INFO_CODE,3,2), SUBSTR(AC.TRANSACTION_ID,6,2)), DISTRICT_MASTER DM
WHERE DM.DISTRICT_ID=DID
GROUP BY DID, MID, DM.DISTRICT_DESCRIPTION;
Regards,
Krishnadeep.<I want a query with the same result without using union all>
You can write a pipelined function, which will be about ten times the work. Its best to use the simples tools; why don't you want to use UNION ALL since its probably the best answer?
Maybe you are looking for
-
How can I acquire data in a PCI DAQ board using a SCXI rack?
Hello. I have an acquisition system that consists in: · 3 PCI DAQ boards: - PCI-MIO-16-E-1 - PCI-6052-E - PCI-6034-E · 3 cables to connect PCI boards and SCXI modules · 1 SCXI chassis: - SCXI-1001 · SCXI modules + terminal blocks: - 4x SCXI_1121 + SC
-
Hi all. i'm having real trouble trying to set up my pay as you go with o2 on the ipad. its the o2 3g card for £10 a month but the o2 wensite is no use to me of explaining how i set this account up as it would be nice to leave my house and browse the
-
How to set a change pointer for a perticular table?
Hi, Please let me know how to set a change pointer for a perticular table.
-
I need help/tutor with layout/design/construction for a small publication. Looking for someone who knows ID3 and Word. If you know Illustrator & PS, all the better. Email - [email protected] with hourly rate. Most everything can be done via email/pho
-
Camera Raw for Canon EOS 6D? I use PSE 9.
Where can I download a Camera Raw version wich supports Canon EOS 6D? I use PSE9. Peter.