Excluding slow table access in a UNION ALL view
Hi,
I have a view which unions three tables together.
One component of the view requires a table scan, as 90% of the records are required.
This view is then used in another outer select where these records are actually not required.
So I tagged each component with a code and excluded that in the outer select. However it still appears to access the table.
Is there any way I can exclude a component of the UNION ALL or do I need to explicitly split them?
example:
SELECT * FROM (
SELECT 'A' Q, JANUARY F FROM ENORMOUS.TABLE WHERE KEY = 'Non Selective Key' UNION ALL
SELECT 'B' Q, 1 F FROM DUAL UNION ALL
SELECT 'C' Q, 1 F FROM DUAL
) A
WHERE Q = 'B'
When I run the query plan without the WHERE it performs the table scan
When I include the WHERE it still performs the table scan but with a FILTER NULL IS NOT NULL afterwards.
So it appears that it is doing the table scan regardless and then throwing the records away - is that correct?
Any thoughts appreciated. I would prefer not the split this view out if possible as it is used everywhere.
In summary my question is: is The Oracle query planner smart enough to exclude a component from a load of stacked UNION ALL queries?
given this query:
CREATE VIEW TEST AS
SELECT Q, F
FROM
SELECT 'A' Q, JANUARY F FROM ENORMOUS.TABLE WHERE KEY = 'Non Selective Key' UNION ALL
SELECT 'B' Q, 1 F FROM DUAL UNION ALL
SELECT 'C' Q, 1 F FROM DUAL
) A;
-- 1. This one selects from all tables, including a table scan on the enormous table
SELECT * FROM TEST;
-- 2. This one selects from all tables, including a table scan on the enormous table
-- However the query plan has a FILTER after the table scan. Does it exclude this work?
SELECT * FROM TEST WHERE Q = 'B';When I run the query plan without the WHERE it performs the table scan
When I include the WHERE the query plan indicates it's doing the table scan but with a FILTER NULL IS NOT NULL afterwards.
So it appears that it is doing the table scan regardless and then throwing the records away - is that correct?
Any thoughts appreciated. I would prefer not the split this view out if possible as it is used everywhere.
Oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Plan output for 1:
SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=7166 Card=2 M Bytes=41 M)
1 VIEW (Cost=7166 Card=2 M Bytes=41 M)
2 1 UNION-ALL
3 2 TABLE ACCESS FULL PLANNING.BF_GEN_STATS_TRAN (Cost=7162 Card=2 M Bytes=72 M)
4 2 FAST DUAL (Cost=2 Card=1)
5 2 FAST DUAL (Cost=2 Card=1)
Plan output for 2:
SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=2 Card=3 Bytes=48)
1 VIEW (Cost=2 Card=3 Bytes=48)
2 1 UNION-ALL
3 2 FILTER
4 3 TABLE ACCESS FULL PLANNING.BF_GEN_STATS_TRAN (Cost=7162 Card=2 M Bytes=72 M)
5 2 FAST DUAL (Cost=2 Card=1)
6 2 FILTER
7 6 FAST DUAL (Cost=2 Card=1)
Similar Messages
-
Why do i get ORA-03113 when doing a spatial query against union all view?
Hi, i created the following view
CREATE OR REPLACE FORCE VIEW cola_markets_v
AS
(SELECT mkt_id, NAME, shape shape_a, NULL shape_b, NULL shape_c,
NULL shape_d
FROM COLA_MARKETS
WHERE NAME = 'cola_a')
UNION ALL
(SELECT mkt_id, NAME, NULL shape_a, shape shape_b, NULL shape_c,
NULL shape_d
FROM COLA_MARKETS
WHERE NAME = 'cola_b')
UNION ALL
(SELECT mkt_id, NAME, NULL shape_a, NULL shape_b, shape shape_c,
NULL shape_d
FROM COLA_MARKETS
WHERE NAME = 'cola_c')
UNION ALL
(SELECT mkt_id, NAME, NULL shape_a, NULL shape_b, NULL shape_c,
shape shape_d
FROM COLA_MARKETS
WHERE NAME = 'cola_d');added the necessary entries in USER_SDO_GEOM_METADATA and created a spatial index on COLA_MARKETS (SHAPE). However, when i do a spatial query against this view, i get ORA-03113. A spatial query against the base table works fine. Any ideas why this happens? (This is Oracle 10.2.0.3.0)
Thanks in advance, Markus
PS: This is my spatial query
SELECT *
FROM cola_markets_v t
WHERE sdo_filter (t.shape_a,
SDO_GEOMETRY (2003,
NULL,
NULL,
sdo_elem_info_array (1, 1003, 3),
sdo_ordinate_array (1, 1, 2, 2)
'querytype=window'
) = 'TRUE';Thank you for your reply. I have tried it with 11.1.0.6.0 today and it works. This might be an issue with 10.2.0.3.0.
-
Using timestamp in union all view
I am having a silly problem with one of my views. It is a union all with two select statements. There is a timestamp(6) in one select but not in the other so I have a to_timestamp(null) to match up the columns.
The problem is that no matter how I code the to_timestamp(null,fmt) the structure of the view is always timestamp(0). I even changed the 2nd select so that it uses a timestamp(6) column. If I create 2 views from both selects they have the correct syntax but as soon as I use a union the timestamp loses it precision.
When I acutally do a select from the view I can still see the milliseconds precision. My real problem occurs in that I have a ref cursor that is of type view_row%rowtype. When I select into the cursor I lose the precision.
Any ideas?
thxUse the cast function to cast the timestamp to timestamp(6)
SQL> create table t
2 ( id number
3 , ts timestamp(6)
4 );
Table created.
SQL> create view v
2 as
3 select id, ts
4 from t
5 union all
6 select 0, cast(to_timestamp(null) as timestamp(6))
7 from dual;
View created.
SQL> desc v
Name Null? Type
ID NUMBER
TS TIMESTAMP(6)
SQL> insert into t
2 values (1,systimestamp);
1 row created.
SQL> select * from v;
ID
TS
1
31-AUG-04 02.28.38.342412 PM
0 -
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 -
Hola everyboy,
I want that one user who hasn`t permiss for edit sql, can do a select with UNION ALL when he want.
Sometimes he want do selects with UNION, only UNION:
Select adress FROM TABLE WHERE Column='PEPE'
UNION
Select adress FROM TABLE2 WHERE Column='PEPE'
and sometimes he want do selects with UNION ALL:
Select adress FROM TABLE WHERE Column='PEPE'
UNION ALL
Select adress FROM TABLE2 WHERE Column='PEPE'
I have seen that if I edit the parameter <Parameter Name="UNION">UNION</Parameter> in sqlsrv.prm in local machine I could use UNION ALL but this is for ALL selects that I do.
Is there any other way that I can use?
Thanks!!Hello Cesar,
please post in what product you are working that we can point youi to teh right forum.
Crystal Reports Designer ? Universe Designer ?
Thanks
Falk -
Union All Command 2: filtering data
I have my Union All command working, and it pulls the 4+ million records quickly.
But as soon as I add a link to the table that has the fields I need to filter by, well, mud flows uphill faster.
So how do I filter the data when the filter information is in a table not in the union all command.
My Successful (to this point) Union All Command
SELECT 'LABOR_1' AS SourseTable,
h1."HISTKEY",
h1."CHRGDTTM",
h1."USAGE",
h1."TOTCOST",
h1."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTLABR AS h1
UNION ALL
SELECT 'EQUIP_2' AS SourseTable,
h2."HISTKEY",
h2."CHRGDTTM",
h2."USAGE",
h2."TOTCOST",
h2."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTPEQ AS h2
UNION ALL
SELECT 'PART_3' AS SourseTable,
h3."HISTKEY",
h3."CHRGDTTM",
h3."USAGE",
h3."TOTCOST",
h3."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTPART AS h3
UNION ALL
SELECT 'CONT_4' AS SourseTable,
h4."HISTKEY",
h4."CHRGDTTM",
h4."USAGE",
h4."TOTCOST",
h4."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTCONT AS h4
UNION ALL
SELECT 'XTRA_5' AS SourseTable,
h5."HISTKEY",
h5."CHRGDTTM",
h5."USAGE",
h5."TOTCOST",
h5."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTXTRA AS h5Debi,
Well the next step is to make sure this works then...
SELECT u.SourseTable, u.HISTKEY, u.CHRGDTTM, u.USAGE, u.TOTCOST, u.DSTBGTKEY
FROM (
SELECT 'LABOR_1' AS SourseTable,
h1."HISTKEY", h1."CHRGDTTM", h1."USAGE", h1."TOTCOST", h1."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTLABR AS h1
UNION ALL
SELECT 'EQUIP_2' AS SourseTable,
h2."HISTKEY", h2."CHRGDTTM", h2."USAGE", h2."TOTCOST", h2."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTPEQ AS h2
UNION ALL
SELECT 'PART_3' AS SourseTable,
h3."HISTKEY", h3."CHRGDTTM", h3."USAGE", h3."TOTCOST", h3."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTPART AS h3
UNION ALL
SELECT 'CONT_4' AS SourseTable,
h4."HISTKEY", h4."CHRGDTTM", h4."USAGE", h4."TOTCOST", h4."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTCONT AS h4
UNION ALL
SELECT 'XTRA_5' AS SourseTable,
h5."HISTKEY", h5."CHRGDTTM", h5."USAGE", h5."TOTCOST", h5."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTXTRA AS h5
) AS u
Also, for readability, let clean up the 2nd query as well...
SELECT
h.HISTKEY,
h.ACTKEY,
h.INITDTTM,
h.COMPDTTM,
a.ACTCODE,
a.ACTDESC
FROM
WORKMANAGEMENT.HISTORY AS h
INNER JOIN WORKMANAGEMENT.ACTDEFN AS a ON h.ACTKEY = a.ACTKEY
Now... assuming that both of these continue to work as they are written above... It's time to tie it all together. Try this...
SELECT
u.SourseTable, u.HISTKEY, u.CHRGDTTM, u.USAGE, u.TOTCOST, u.DSTBGTKEY,
h.ACTKEY, h.INITDTTM, h.COMPDTTM, a.ACTCODE, a.ACTDESC
FROM (
SELECT 'LABOR_1' AS SourseTable,
h1."HISTKEY", h1."CHRGDTTM", h1."USAGE", h1."TOTCOST", h1."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTLABR AS h1
UNION ALL
SELECT 'EQUIP_2' AS SourseTable,
h2."HISTKEY", h2."CHRGDTTM", h2."USAGE", h2."TOTCOST", h2."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTPEQ AS h2
UNION ALL
SELECT 'PART_3' AS SourseTable,
h3."HISTKEY", h3."CHRGDTTM", h3."USAGE", h3."TOTCOST", h3."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTPART AS h3
UNION ALL
SELECT 'CONT_4' AS SourseTable,
h4."HISTKEY", h4."CHRGDTTM", h4."USAGE", h4."TOTCOST", h4."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTCONT AS h4
UNION ALL
SELECT 'XTRA_5' AS SourseTable,
h5."HISTKEY", h5."CHRGDTTM", h5."USAGE", h5."TOTCOST", h5."DSTBGTKEY"
FROM WORKMANAGEMENT.COSTXTRA AS h5
) AS u
LEFT OUTER JOIN WORKMANAGEMENT.HISTORY AS h ON u.HISTKEY = h.HISTKEY
INNER JOIN WORKMANAGEMENT.ACTDEFN AS a ON h.ACTKEY = a.ACTKEY
Let me know how that works for you,
Jason -
I have 2 queries that I do an "union all" and then an order by after the "union all" This seems to be extremely slow. But when I run the queries individually, they are really fast. Could some help me out with this please.
SELECT *
FROM (SELECT a.*, ROWNUM rnum
FROM (SELECT COLS......
FROM (((SELECT from tables with joins)
UNION ALL
(SELECT from tables and view with joins))
order by colname)
) a
WHERE ROWNUM <= 500)
WHERE rnum >= 1
PLAN_TABLE_OUTPUT
Plan hash value: 3988534528
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 500 | 1600K| | 3634M (1)|999:59:59 | | |
|* 1 | VIEW | | 500 | 1600K| | 3634M (1)|999:59:59 | | |
|* 2 | COUNT STOPKEY | | | | | | | | |
| 3 | VIEW | | 4277K| 13G| | 3634M (1)|999:59:59 | | |
|* 4 | SORT ORDER BY STOPKEY | | 4277K| 311M| 1095M| 3634M (1)|999:59:59 | | |
| 5 | UNION-ALL | | | | | | | | |
PLAN_TABLE_OUTPUT
|* 6 | FILTER | | | | | | | | |
|* 7 | HASH JOIN | | 212K| 15M| | 153K (1)| 00:03:37 | | |
|* 8 | HASH JOIN RIGHT OUTER | | 507 | 22308 | | 6 (17)| 00:00:01 | | |
| 9 | TABLE ACCESS FULL | DIR | 143 | 3861 | | 2 (0)| 00:00:01 | | |
| 10 | TABLE ACCESS FULL | USER | 507 | 8619 | | 3 (0)| 00:00:01 | | |
| 11 | PARTITION RANGE ITERATOR | | 212K| 6645K| | 153K (1)| 00:03:37 | KEY | KEY |
| 12 | TABLE ACCESS BY LOCAL INDEX ROWID | FL | 212K| 6645K| | 153K (1)| 00:03:37 | KEY | KEY |
|* 13 | INDEX RANGE SCAN | I_FL_ID | 382K| | | 38943 (2)| 00:00:56 | KEY | KEY |
|* 14 | COUNT STOPKEY | | | | | | | | |
|* 15 | FILTER | | | | | | | | |
| 16 | PARTITION RANGE ITERATOR | | 1 | 22 | | 856 (1)| 00:00:02 | KEY | KEY |
PLAN_TABLE_OUTPUT
|* 17 | TABLE ACCESS BY LOCAL INDEX ROWID| PAY | 1 | 22 | | 856 (1)| 00:00:02 | KEY | KEY |
|* 18 | INDEX RANGE SCAN | I_PAY_FLID | 1 | | | 855 (1)| 00:00:02 | KEY | KEY |
|* 19 | FILTER | | | | | | | | |
|* 20 | HASH JOIN RIGHT OUTER | | 25019 | 3029K| | 138K (1)| 00:03:17 | | |
| 21 | TABLE ACCESS FULL | DIR | 143 | 3861 | | 2 (0)| 00:00:01 | | |
|* 22 | HASH JOIN | | 25019 | 2369K| | 138K (1)| 00:03:17 | | |
| 23 | TABLE ACCESS FULL | USER | 507 | 8619 | | 3 (0)| 00:00:01 | | |
|* 24 | HASH JOIN | | 25019 | 1954K| | 138K (1)| 00:03:17 | | |
| 25 | INDEX FULL SCAN | PK_HO | 278 | 1112 | | 1 (0)| 00:00:01 | | |
|* 26 | HASH JOIN | | 25019 | 1856K| | 138K (1)| 00:03:17 | | |
| 27 | INDEX FULL SCAN | PK_HO | 278 | 1112 | | 1 (0)| 00:00:01 | | |
PLAN_TABLE_OUTPUT
| 28 | NESTED LOOPS | | 25019 | 1759K| | 138K (1)| 00:03:17 | | |
| 29 | PARTITION RANGE ITERATOR | | 25018 | 830K| | 63575 (1)| 00:01:30 | KEY | KEY |
|* 30 | TABLE ACCESS BY LOCAL INDEX ROWID | PAY | 25018 | 830K| | 63575 (1)| 00:01:30 | KEY | KEY |
|* 31 | INDEX RANGE SCAN | I_PAY_TIME_ID | 1493K| | | 9052 (2)| 00:00:13 | KEY | KEY |
|* 32 | TABLE ACCESS BY GLOBAL INDEX ROWID | FL | 1 | 38 | | 3 (0)| 00:00:01 | ROWID | ROWID |
|* 33 | INDEX UNIQUE SCAN | PK_FL | 1 | | | 2 (0)| 00:00:01 | | |
SELECT *
FROM (SELECT a.*, ROWNUM rnum
FROM ( SELECT from tables with joins order by colname) a
WHERE ROWNUM <= 500)
WHERE rnum >= 1
PLAN_TABLE_OUTPUT
Plan hash value: 3503998222
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 500 | 1228K| 222K (1)| 00:05:15 | | |
|* 1 | VIEW | | 500 | 1228K| 222K (1)| 00:05:15 | | |
|* 2 | COUNT STOPKEY | | | | | | | |
| 3 | VIEW | | 520 | 1271K| 222K (1)| 00:05:15 | | |
|* 4 | FILTER | | | | | | | |
| 5 | NESTED LOOPS OUTER | | 26 | 1976 | 54 (0)| 00:00:01 | | |
PLAN_TABLE_OUTPUT
| 6 | NESTED LOOPS | | 26 | 1274 | 48 (0)| 00:00:01 | | |
| 7 | PARTITION RANGE ITERATOR | | 212K| 6645K| 22 (0)| 00:00:01 | KEY | KEY |
| 8 | TABLE ACCESS BY LOCAL INDEX ROWID | FL | 212K| 6645K| 22 (0)| 00:00:01 | KEY | KEY |
|* 9 | INDEX RANGE SCAN | I_FL_START_ID | 47 | | 8 (0)| 00:00:01 | KEY | KEY |
|* 10 | COUNT STOPKEY | | | | | | | |
|* 11 | FILTER | | | | | | | |
| 12 | PARTITION RANGE ITERATOR | | 1 | 22 | 856 (1)| 00:00:02 | KEY | KEY |
|* 13 | TABLE ACCESS BY LOCAL INDEX ROWID| PAY | 1 | 22 | 856 (1)| 00:00:02 | KEY | KEY |
|* 14 | INDEX RANGE SCAN | I_PAY_ID | 1 | | 855 (1)| 00:00:02 | KEY | KEY |
| 15 | TABLE ACCESS BY INDEX ROWID | USER | 1 | 17 | 1 (0)| 00:00:01 | | |
|* 16 | INDEX UNIQUE SCAN | PK_USER | 1 | | 0 (0)| 00:00:01 | | |
PLAN_TABLE_OUTPUT
| 17 | TABLE ACCESS BY INDEX ROWID | DIR | 1 | 27 | 1 (0)| 00:00:01 | | |
|* 18 | INDEX UNIQUE SCAN | PK_DIR | 1 | | 0 (0)| 00:00:01 | | |
SELECT *
FROM (SELECT a.*, ROWNUM rnum
FROM ( SELECT from tables and view with joins order by colname) a
WHERE ROWNUM <= 500)
WHERE rnum >= 1
PLAN_TABLE_OUTPUT
Plan hash value: 1786470271
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 500 | 1600K| 1696 (1)| 00:00:03 | | |
|* 1 | VIEW | | 500 | 1600K| 1696 (1)| 00:00:03 | | |
|* 2 | COUNT STOPKEY | | | | | | | |
| 3 | VIEW | | 501 | 1596K| 1696 (1)| 00:00:03 | | |
|* 4 | FILTER | | | | | | | |
| 5 | NESTED LOOPS | | 501 | 60120 | 1696 (1)| 00:00:03 | | |
PLAN_TABLE_OUTPUT
| 6 | NESTED LOOPS | | 501 | 58116 | 1696 (1)| 00:00:03 | | |
| 7 | NESTED LOOPS OUTER | | 501 | 56112 | 1695 (1)| 00:00:03 | | |
| 8 | NESTED LOOPS | | 501 | 42585 | 1689 (1)| 00:00:03 | | |
| 9 | NESTED LOOPS | | 501 | 34068 | 1550 (1)| 00:00:03 | | |
| 10 | PARTITION RANGE ITERATOR | | 829K| 23M| 42 (0)| 00:00:01 | KEY | KEY |
| 11 | TABLE ACCESS BY LOCAL INDEX ROWID| PAY | 829K| 23M| 42 (0)| 00:00:01 | KEY | KEY |
|* 12 | INDEX RANGE SCAN | I_PAY_TIME_ID | 902 | | 9 (0)| 00:00:01 | KEY | KEY |
|* 13 | TABLE ACCESS BY GLOBAL INDEX ROWID| FL | 1 | 38 | 3 (0)| 00:00:01 | ROWID | ROWID |
|* 14 | INDEX UNIQUE SCAN | PK_FL | 1 | | 2 (0)| 00:00:01 | | |
| 15 | TABLE ACCESS BY INDEX ROWID | USER | 1 | 17 | 1 (0)| 00:00:01 | | |
|* 16 | INDEX UNIQUE SCAN | PK_USER | 1 | | 0 (0)| 00:00:01 | | |
PLAN_TABLE_OUTPUT
| 17 | TABLE ACCESS BY INDEX ROWID | DIR | 1 | 27 | 1 (0)| 00:00:01 | | |
|* 18 | INDEX UNIQUE SCAN | PK_DIR | 1 | | 0 (0)| 00:00:01 | | |
|* 19 | INDEX UNIQUE SCAN | PK_HO | 1 | 4 | 0 (0)| 00:00:01 | | |
|* 20 | INDEX UNIQUE SCAN | PK_HO | 1 | 4 | 0 (0)| 00:00:01 | | |
---------------------------------------------------------------------------------------------------------------------------------------------Can you limit the number of rows coming out of each part of the UNION ALL before limiting the number of rows you're trying to return? So that you end up with something like
SELECT *
FROM (<<Get first 500 rows from first query>>
UNION ALL
<<Get first 500 rows from second query>>)
WHERE rownum <= 500It appears from the query plan that your problem is that Oracle is sorting the entire result of the UNION ALL before finding the first 500 rows. That's obviously rather time consuming since the two queries return 10's of GB of data. Individually, the two queries are fast because you're limiting each of them to 500 rows, so Oracle can do a quick index scan (presumably on the sort column) that would find those rows.
And depending on what's behind the queries, I'd look to see whether you can put some additional filter conditions in place to look for data with dates in the past day or two in order to at least limit the worst case if Oracle does have to sort everything.
Justin -
UNION ALL slow (cost goes from 75 and 173 to 450,789!)
Hi,
I have two Selects (lots of joins - big tables)
Select A) has an explain plan cost of 75
Select B) has an explain plan cost of 173
If I union (or union all) the cost goes up to 450,789!
I can paste in the queries, plans etc - but if anyone has any quick ideas that'd be great.
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
What I'd like is to force the optomiser to run each query sequentially - but not really sure how.
Any help would be really appreciated - I have few hairs left and am just about to tear the last one out!
Cheers,
PatrickAttached are the queries and the explain plan.
I have simply tried UNION and UNION ALL to see if there's a difference (expecting UNION ALL to be faster).. but (distinct) UNION Is what I want.
Queries
explain plan for
(SELECT ety_entity_identifier "a" ,
ety_current_name "b" ,
gment.ety_discriminant "c" ,
upper(ind_first_name)
|| ' '
|| upper(ind_last_name) "d" ,
CASE
WHEN ind_last_name = NULL
then null
END e
FROM gv_emr_entity_master m
INNER JOIN gv_ety_entities gv_ety
ON gv_ety.ety_entity_identifier = m.mtr_identifier
AND gv_ety.ety_ety_version = m.mtr_current_version
AND gv_ety.ety_reg_code = m.mtr_reg_code
INNER JOIN gm_ety_entities gment
ON gment.ety_id = gv_ety.ety_id
INNER JOIN gv_erl_entity_roles gve
ON m.mtr_identifier = gve.erl_entity_identifier
AND m.mtr_current_version = gve.erl_ety_version
INNER JOIN gm_erl_entity_roles gme
ON gve.erl_id = gme.erl_id
INNER JOIN gv_imr_individual_master gvm
ON gme.erl_ind_individual_identifier = gvm.mtr_identifier
AND gme.erl_ind_version = gvm.mtr_current_version
INNER JOIN gv_ind_individuals gvi
ON gvm.mtr_identifier = gvi.ind_individual_identifier
AND gvm.mtr_current_version = gvi.ind_ind_version
INNER JOIN gm_ind_individuals gmn
ON gvi.ind_id = gmn.ind_id
INNER JOIN gv_ias_individual_addresses gvad
ON gvi.ind_reg_code = gvad.ias_reg_code
AND gvi.ind_individual_identifier = gvad.ias_individual_identifier
AND gvi.ind_ind_version = gvad.ias_ind_version
INNER JOIN gm_rfr_repository_folder gmrfr
ON gmrfr.rfr_entity_identifier = gv_ety.ety_entity_identifier
INNER JOIN gm_rdt_repository_documents gmrdt
ON gmrdt.rdt_rfr_id = gmrfr.rfr_id
INNER JOIN rdi_repository_documents_info rdire
ON rdire.rdi_rdt_id = gmrdt.rdt_id
WHERE
gmrdt.rdt_dte_code IN ('OPD','PD')
AND TO_CHAR(rdire.rdi_submission_date, 'YYYY-MM-DD') >= TO_CHAR('2007-11-01')
and to_char(rdire.rdi_submission_date, 'YYYY-MM-DD') <= to_char('2009-01-05')
and rownum > 0
and rownum < 10
union all
SELECT ety_entity_identifier a ,
ety_current_name "b" ,
gment.ety_discriminant "c" ,
gment.ety_current_name "d" ,
gment.ety_entity_identifier "e"
FROM gv_emr_entity_master m
INNER JOIN gv_ety_entities gv_ety
ON gv_ety.ety_entity_identifier = m.mtr_identifier
AND gv_ety.ety_ety_version = m.mtr_current_version
AND gv_ety.ety_reg_code = m.mtr_reg_code
INNER JOIN gm_ety_entities gment
ON gment.ety_id = gv_ety.ety_id
INNER JOIN gv_erl_entity_roles gve
ON m.mtr_identifier = gve.erl_entity_identifier
AND m.mtr_current_version = gve.erl_ety_version
INNER JOIN gm_erl_entity_roles gm_erl
ON gve.erl_id = gm_erl.erl_id
INNER JOIN gv_ety_entities gv_ety_temp
ON gm_erl.erl_entity_identifier_assoc = gv_ety_temp.ety_entity_identifier
INNER JOIN gv_emr_entity_master gv_emr_master
ON gv_ety_temp.ety_entity_identifier = gv_emr_master.mtr_identifier
AND gv_ety_temp.ety_ety_version = gv_emr_master.mtr_current_version
INNER JOIN gm_ety_entities gm_ety_temp
ON gm_ety_temp.ety_id = gv_ety_temp.ety_id
INNER JOIN gv_eas_entity_addresses gva
ON gv_ety_temp.ety_reg_code = gva.eas_reg_code
AND gv_ety_temp.ety_entity_identifier = gva.eas_entity_identifier
AND gv_ety_temp.ety_ety_version = gva.eas_ety_version
INNER JOIN gm_rfr_repository_folder gmrfr
ON gmrfr.rfr_entity_identifier = gv_ety.ety_entity_identifier
INNER JOIN gm_rdt_repository_documents gmrdt
ON gmrdt.rdt_rfr_id = gmrfr.rfr_id
INNER JOIN rdi_repository_documents_info rdire
on rdire.rdi_rdt_id = gmrdt.rdt_id
WHERE
gmrdt.rdt_dte_code IN ('OPD','PD')
AND gm_erl.erl_rre_name = 'SHR'
AND TO_CHAR(rdire.rdi_submission_date, 'YYYY-MM-DD') >= TO_CHAR('2007-11-01')
and to_char(rdire.rdi_submission_date, 'YYYY-MM-DD') <= to_char('2009-01-05')
and rownum > 0
and rownum < 10
Plan hash value: 91542951
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 18 | 4905 | | 450K (46)| 01:30:10 |
| 1 | UNION-ALL | | | | | | |
|* 2 | COUNT STOPKEY | | | | | | |
|* 3 | FILTER | | | | | | |
|* 4 | HASH JOIN | | 173K| 47M| 38M| 249K (1)| 00:49:54 |
|* 5 | HASH JOIN | | 151K| 36M| 36M| 231K (1)| 00:46:24 |
|* 6 | HASH JOIN | | 151K| 34M| 30M| 203K (1)| 00:40:43 |
|* 7 | HASH JOIN | | 151K| 28M| 27M| 182K (1)| 00:36:35 |
|* 8 | HASH JOIN | | 151K| 25M| 23M| 170K (1)| 00:34:06 |
|* 9 | HASH JOIN | | 151K| 21M| 4840K| 140K (1)| 00:28:05 |
|* 10 | HASH JOIN | | 34132 | 4433K| 3464K| 127K (1)| 00:25:35 |
|* 11 | HASH JOIN | | 34419 | 3058K| 2776K| 120K (1)| 00:24:03 |
|* 12 | HASH JOIN | | 34229 | 2373K| 1912K| 117K (1)| 00:23:35 |
|* 13 | HASH JOIN | | 34229 | 1504K| 1440K| 114K (1)| 00:22:49 |
| 14 | NESTED LOOPS | | 34229 | 1036K| | 99509 (1)| 00:19:55 |
|* 15 | TABLE ACCESS FULL | RDI_REPOSITORY_DOCUMENTS_INFO | 34205 | 467K| | 31522 (2)| 00:06:19 |
|* 16 | TABLE ACCESS BY INDEX ROWID| GM_RDT_REPOSITORY_DOCUMENTS | 1 | 17 | | 2 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | SYS_C0082075 | 1 | | | 1 (0)| 00:00:01 |
| 18 | TABLE ACCESS FULL | GM_RFR_REPOSITORY_FOLDER | 2125K| 28M| | 11843 (1)| 00:02:23 |
| 19 | TABLE ACCESS FULL | GV_ETY_ENTITIES | 953K| 23M| | 1958 (1)| 00:00:24 |
| 20 | TABLE ACCESS FULL | GV_EMR_ENTITY_MASTER | 951K| 18M| | 758 (2)| 00:00:10 |
| 21 | TABLE ACCESS FULL | GM_ETY_ENTITIES | 945K| 37M| | 5120 (1)| 00:01:02 |
| 22 | TABLE ACCESS FULL | GV_ERL_ENTITY_ROLES | 4233K| 68M| | 6413 (1)| 00:01:17 |
|* 23 | TABLE ACCESS FULL | GM_ERL_ENTITY_ROLES | 3611K| 92M| | 22218 (1)| 00:04:27 |
| 24 | TABLE ACCESS FULL | GV_IMR_INDIVIDUAL_MASTER | 3994K| 83M| | 4547 (2)| 00:00:55 |
| 25 | TABLE ACCESS FULL | GV_IND_INDIVIDUALS | 3994K| 144M| | 9720 (1)| 00:01:57 |
| 26 | TABLE ACCESS FULL | GM_IND_INDIVIDUALS | 4008K| 68M| | 20842 (1)| 00:04:11 |
| 27 | INDEX FAST FULL SCAN | FKGV_IAS_IND592213_IDX | 4564K| 139M| | 6062 (1)| 00:01:13 |
|* 28 | COUNT STOPKEY | | | | | | |
|* 29 | FILTER | | | | | | |
|* 30 | HASH JOIN | | 1163K| 286M| 35M| 201K (1)| 00:40:16 |
|* 31 | HASH JOIN | | 150K| 33M| 30M| 180K (1)| 00:36:11 |
|* 32 | HASH JOIN | | 151K| 28M| 20M| 172K (1)| 00:34:25 |
| 33 | TABLE ACCESS FULL | GV_EMR_ENTITY_MASTER | 951K| 9M| | 758 (2)| 00:00:10 |
|* 34 | HASH JOIN | | 151K| 27M| 25M| 168K (1)| 00:33:46 |
|* 35 | HASH JOIN | | 151K| 23M| 2328K| 163K (1)| 00:32:47 |
|* 36 | TABLE ACCESS FULL | GM_ERL_ENTITY_ROLES | 99240 | 1162K| | 22205 (1)| 00:04:27 |
|* 37 | HASH JOIN | | 151K| 21M| 4840K| 140K (1)| 00:28:05 |
|* 38 | HASH JOIN | | 34132 | 4433K| 3464K| 127K (1)| 00:25:35 |
|* 39 | HASH JOIN | | 34419 | 3058K| 2776K| 120K (1)| 00:24:03 |
|* 40 | HASH JOIN | | 34229 | 2373K| 1912K| 117K (1)| 00:23:35 |
|* 41 | HASH JOIN | | 34229 | 1504K| 1440K| 114K (1)| 00:22:49 |
| 42 | NESTED LOOPS | | 34229 | 1036K| | 99509 (1)| 00:19:55 |
|* 43 | TABLE ACCESS FULL | RDI_REPOSITORY_DOCUMENTS_INFO | 34205 | 467K| | 31522 (2)| 00:06:19 |
|* 44 | TABLE ACCESS BY INDEX ROWID| GM_RDT_REPOSITORY_DOCUMENTS | 1 | 17 | | 2 (0)| 00:00:01 |
|* 45 | INDEX UNIQUE SCAN | SYS_C0082075 | 1 | | | 1 (0)| 00:00:01 |
| 46 | TABLE ACCESS FULL | GM_RFR_REPOSITORY_FOLDER | 2125K| 28M| | 11843 (1)| 00:02:23 |
| 47 | TABLE ACCESS FULL | GV_ETY_ENTITIES | 953K| 23M| | 1958 (1)| 00:00:24 |
| 48 | TABLE ACCESS FULL | GV_EMR_ENTITY_MASTER | 951K| 18M| | 758 (2)| 00:00:10 |
| 49 | TABLE ACCESS FULL | GM_ETY_ENTITIES | 945K| 37M| | 5120 (1)| 00:01:02 |
| 50 | TABLE ACCESS FULL | GV_ERL_ENTITY_ROLES | 4233K| 68M| | 6413 (1)| 00:01:17 |
| 51 | TABLE ACCESS FULL | GV_ETY_ENTITIES | 953K| 23M| | 1958 (1)| 00:00:24 |
| 52 | TABLE ACCESS FULL | GM_ETY_ENTITIES | 945K| 34M| | 5102 (1)| 00:01:02 |
| 53 | INDEX FAST FULL SCAN | FKGV_EAS_ENT111959_IDX | 7325K| 146M| | 7127 (1)| 00:01:26 |
Query Block Name / Object Alias (identified by operation id):
1 - SET$1
2 - SEL$B4C8BCFD
15 - SEL$B4C8BCFD / RDIRE@SEL$11
16 - SEL$B4C8BCFD / GMRDT@SEL$10
17 - SEL$B4C8BCFD / GMRDT@SEL$10
18 - SEL$B4C8BCFD / GMRFR@SEL$9
19 - SEL$B4C8BCFD / GV_ETY@SEL$1
20 - SEL$B4C8BCFD / M@SEL$1
21 - SEL$B4C8BCFD / GMENT@SEL$2
22 - SEL$B4C8BCFD / GVE@SEL$3
23 - SEL$B4C8BCFD / GME@SEL$4
24 - SEL$B4C8BCFD / GVM@SEL$5
25 - SEL$B4C8BCFD / GVI@SEL$6
26 - SEL$B4C8BCFD / GMN@SEL$7
27 - SEL$B4C8BCFD / GVAD@SEL$8
28 - SEL$5ECD7CF3
33 - SEL$5ECD7CF3 / GV_EMR_MASTER@SEL$17
36 - SEL$5ECD7CF3 / GM_ERL@SEL$15
43 - SEL$5ECD7CF3 / RDIRE@SEL$22
44 - SEL$5ECD7CF3 / GMRDT@SEL$21
45 - SEL$5ECD7CF3 / GMRDT@SEL$21
46 - SEL$5ECD7CF3 / GMRFR@SEL$20
47 - SEL$5ECD7CF3 / GV_ETY@SEL$12
48 - SEL$5ECD7CF3 / M@SEL$12
49 - SEL$5ECD7CF3 / GMENT@SEL$13
50 - SEL$5ECD7CF3 / GVE@SEL$14
51 - SEL$5ECD7CF3 / GV_ETY_TEMP@SEL$16
52 - SEL$5ECD7CF3 / GM_ETY_TEMP@SEL$18
53 - SEL$5ECD7CF3 / GVA@SEL$19
Predicate Information (identified by operation id):
2 - filter(ROWNUM<10)
3 - filter(ROWNUM>0)
4 - access("GVI"."IND_REG_CODE"="GVAD"."IAS_REG_CODE" AND "GVI"."IND_INDIVIDUAL_IDENTIFIER"="GVAD"."IAS_INDIVIDUAL_IDENT
IFIER" AND "GVI"."IND_IND_VERSION"="GVAD"."IAS_IND_VERSION")
5 - access("GVI"."IND_ID"="GMN"."IND_ID")
6 - access("GVM"."MTR_IDENTIFIER"="GVI"."IND_INDIVIDUAL_IDENTIFIER" AND
"GVM"."MTR_CURRENT_VERSION"="GVI"."IND_IND_VERSION")
7 - access("GME"."ERL_IND_INDIVIDUAL_IDENTIFIER"="GVM"."MTR_IDENTIFIER" AND
"GME"."ERL_IND_VERSION"="GVM"."MTR_CURRENT_VERSION")
8 - access("GVE"."ERL_ID"="GME"."ERL_ID")
9 - access("M"."MTR_IDENTIFIER"="GVE"."ERL_ENTITY_IDENTIFIER" AND "M"."MTR_CURRENT_VERSION"="GVE"."ERL_ETY_VERSION")
10 - access("GMENT"."ETY_ID"="GV_ETY"."ETY_ID")
11 - access("GV_ETY"."ETY_ENTITY_IDENTIFIER"="M"."MTR_IDENTIFIER" AND
"GV_ETY"."ETY_ETY_VERSION"="M"."MTR_CURRENT_VERSION" AND "GV_ETY"."ETY_REG_CODE"="M"."MTR_REG_CODE")
12 - access("GMRFR"."RFR_ENTITY_IDENTIFIER"="GV_ETY"."ETY_ENTITY_IDENTIFIER")
13 - access("GMRDT"."RDT_RFR_ID"="GMRFR"."RFR_ID")
15 - filter(TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')>='2007-11-01' AND
TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')<='2009-01-05')
16 - filter("GMRDT"."RDT_DTE_CODE"='OPD' OR "GMRDT"."RDT_DTE_CODE"='PD')
17 - access("RDIRE"."RDI_RDT_ID"="GMRDT"."RDT_ID")
23 - filter("GME"."ERL_IND_INDIVIDUAL_IDENTIFIER" IS NOT NULL AND "GME"."ERL_IND_VERSION" IS NOT NULL)
28 - filter(ROWNUM<10)
29 - filter(ROWNUM>0)
30 - access("GV_ETY_TEMP"."ETY_REG_CODE"="GVA"."EAS_REG_CODE" AND
"GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"="GVA"."EAS_ENTITY_IDENTIFIER" AND
"GV_ETY_TEMP"."ETY_ETY_VERSION"="GVA"."EAS_ETY_VERSION")
31 - access("GM_ETY_TEMP"."ETY_ID"="GV_ETY_TEMP"."ETY_ID")
32 - access("GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"="GV_EMR_MASTER"."MTR_IDENTIFIER" AND
"GV_ETY_TEMP"."ETY_ETY_VERSION"="GV_EMR_MASTER"."MTR_CURRENT_VERSION")
34 - access("GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC"="GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER")
35 - access("GVE"."ERL_ID"="GM_ERL"."ERL_ID")
36 - filter("GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC" IS NOT NULL AND "GM_ERL"."ERL_RRE_NAME"='SHR')
37 - access("M"."MTR_IDENTIFIER"="GVE"."ERL_ENTITY_IDENTIFIER" AND "M"."MTR_CURRENT_VERSION"="GVE"."ERL_ETY_VERSION")
38 - access("GMENT"."ETY_ID"="GV_ETY"."ETY_ID")
39 - access("GV_ETY"."ETY_ENTITY_IDENTIFIER"="M"."MTR_IDENTIFIER" AND
"GV_ETY"."ETY_ETY_VERSION"="M"."MTR_CURRENT_VERSION" AND "GV_ETY"."ETY_REG_CODE"="M"."MTR_REG_CODE")
40 - access("GMRFR"."RFR_ENTITY_IDENTIFIER"="GV_ETY"."ETY_ENTITY_IDENTIFIER")
41 - access("GMRDT"."RDT_RFR_ID"="GMRFR"."RFR_ID")
43 - filter(TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')>='2007-11-01' AND
TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')<='2009-01-05')
44 - filter("GMRDT"."RDT_DTE_CODE"='OPD' OR "GMRDT"."RDT_DTE_CODE"='PD')
45 - access("RDIRE"."RDI_RDT_ID"="GMRDT"."RDT_ID")
Column Projection Information (identified by operation id):
1 - STRDEF[200], STRDEF[4000], STRDEF[400], STRDEF[4000], STRDEF[200]
2 - "GMN"."IND_LAST_NAME"[VARCHAR2,400], "GMN"."IND_FIRST_NAME"[VARCHAR2,400],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
3 - "GMN"."IND_LAST_NAME"[VARCHAR2,400], "GMN"."IND_FIRST_NAME"[VARCHAR2,400],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
4 - (#keys=3) "GMN"."IND_LAST_NAME"[VARCHAR2,400], "GMN"."IND_FIRST_NAME"[VARCHAR2,400],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
5 - (#keys=1) "GVI"."IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_IND_VERSION"[NUMBER,22],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_REG_CODE"[VARCHAR2,200], "GMN"."IND_LAST_NAME"[VARCHAR2,400],
"GMN"."IND_FIRST_NAME"[VARCHAR2,400]
6 - (#keys=2) "GVI"."IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_IND_VERSION"[NUMBER,22],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_REG_CODE"[VARCHAR2,200], "GVI"."IND_ID"[NUMBER,22]
7 - (#keys=2) "GVM"."MTR_IDENTIFIER"[VARCHAR2,200], "GVM"."MTR_CURRENT_VERSION"[NUMBER,22],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
8 - (#keys=1) "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GME"."ERL_IND_VERSION"[NUMBER,22],
"GME"."ERL_IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200]
9 - (#keys=2) "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GVE"."ERL_ID"[NUMBER,22]
10 - (#keys=1) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000]
11 - (#keys=3) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
12 - (#keys=1) "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200],
"GV_ETY"."ETY_ID"[NUMBER,22], "GV_ETY"."ETY_ETY_VERSION"[NUMBER,22]
13 - (#keys=1) "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
14 - (#keys=0) "GMRDT"."RDT_RFR_ID"[NUMBER,22]
15 - "RDIRE"."RDI_RDT_ID"[NUMBER,22]
16 - "GMRDT"."RDT_RFR_ID"[NUMBER,22]
17 - "GMRDT".ROWID[ROWID,10]
18 - "GMRFR"."RFR_ID"[NUMBER,22], "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
19 - "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GV_ETY"."ETY_ETY_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
20 - "M"."MTR_REG_CODE"[VARCHAR2,200], "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22]
21 - "GMENT"."ETY_ID"[NUMBER,22], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
22 - "GVE"."ERL_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVE"."ERL_ETY_VERSION"[NUMBER,22], "GVE"."ERL_ID"[NUMBER,22]
23 - "GME"."ERL_ID"[NUMBER,22], "GME"."ERL_IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200], "GME"."ERL_IND_VERSION"[NUMBER,22]
24 - "GVM"."MTR_IDENTIFIER"[VARCHAR2,200], "GVM"."MTR_CURRENT_VERSION"[NUMBER,22]
25 - "GVI"."IND_REG_CODE"[VARCHAR2,200], "GVI"."IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200],
"GVI"."IND_IND_VERSION"[NUMBER,22], "GVI"."IND_ID"[NUMBER,22]
26 - "GMN"."IND_ID"[NUMBER,22], "GMN"."IND_FIRST_NAME"[VARCHAR2,400], "GMN"."IND_LAST_NAME"[VARCHAR2,400]
27 - "GVAD"."IAS_REG_CODE"[VARCHAR2,200], "GVAD"."IAS_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200],
"GVAD"."IAS_IND_VERSION"[NUMBER,22]
28 - "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
29 - "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
30 - (#keys=3) "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
31 - (#keys=1) "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22],
"GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
32 - (#keys=2) "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22],
"GV_ETY_TEMP"."ETY_ID"[NUMBER,22], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200]
33 - "GV_EMR_MASTER"."MTR_IDENTIFIER"[VARCHAR2,200], "GV_EMR_MASTER"."MTR_CURRENT_VERSION"[NUMBER,22]
34 - (#keys=1) "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ID"[NUMBER,22], "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22]
35 - (#keys=1) "GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC"[VARCHAR2,200], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
"GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
36 - "GM_ERL"."ERL_ID"[NUMBER,22], "GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC"[VARCHAR2,200]
37 - (#keys=2) "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GVE"."ERL_ID"[NUMBER,22]
38 - (#keys=1) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22],
"GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000]
39 - (#keys=3) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
40 - (#keys=1) "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200],
"GV_ETY"."ETY_ID"[NUMBER,22], "GV_ETY"."ETY_ETY_VERSION"[NUMBER,22]
41 - (#keys=1) "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
42 - (#keys=0) "GMRDT"."RDT_RFR_ID"[NUMBER,22]
43 - "RDIRE"."RDI_RDT_ID"[NUMBER,22]
44 - "GMRDT"."RDT_RFR_ID"[NUMBER,22]
45 - "GMRDT".ROWID[ROWID,10]
46 - "GMRFR"."RFR_ID"[NUMBER,22], "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
47 - "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GV_ETY"."ETY_ETY_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
48 - "M"."MTR_REG_CODE"[VARCHAR2,200], "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22]
49 - "GMENT"."ETY_ID"[NUMBER,22], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
50 - "GVE"."ERL_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVE"."ERL_ETY_VERSION"[NUMBER,22], "GVE"."ERL_ID"[NUMBER,22]
51 - "GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22], "GV_ETY_TEMP"."ETY_ID"[NUMBER,22]
52 - "GM_ETY_TEMP"."ETY_ID"[NUMBER,22], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
"GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000]
53 - "GVA"."EAS_REG_CODE"[VARCHAR2,200], "GVA"."EAS_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVA"."EAS_ETY_VERSION"[NUMBER,22]Edited by: user12839343 on Jun 14, 2010 6:43 PM -
Hi
The problem Im having is that I had a query on sales order tables that used to take a couple of minutes to run. The user wanted contract orders to be added to the query and these were stored in different tables to the sales orders. I carried out union all joins in views and then applied the query to the views. Unfortunately it now takes 30 minutes to run.
I apologise for the large post, I am just trying to provide enough information for someone to help me out.
Any help will be greatly appreciated.
Thanks
Stephen
The original query was:
SELECT
C_STD_COST.MAT, C_STD_COST.LAB, C_STD_COST.OHD, ITEM.PC, BILL_HDR.RATE,
BILL_SO.SO_SHIP_QTY, BILL_SO.SO_SHIP_EXT_AMT, AR_DOC.CUSTOMER,
BILL_SO.AR_DOC,
CUS_LOC.NAME, AR_DOC.CREATED_DATE, MEMO.TOT_ORD_QTY, MEMO.UNIT_PRICE,
MEMO.BOOK_RATE, AR_DOC.AR_DOC_TYPE, MEMO.MEMO_TYPE, BILL_SO.ITEM
FROM
AR_DOC, BILL_HDR, CUS_LOC, BILL_SO, ITEM, MEMO, C_STD_COST
WHERE
AR_DOC.AR_CCN=BILL_HDR.AR_CCN AND
AR_DOC.AR_DOC_TYPE=BILL_HDR.AR_DOC_TYPE AND
AR_DOC.AR_DOC=BILL_HDR.AR_DOC AND
AR_DOC.CUSTOMER=CUS_LOC.CUSTOMER AND
AR_DOC.CUS_AR_LOC=CUS_LOC.CUS_LOC AND
BILL_HDR.AR_CCN=BILL_SO.AR_CCN AND
BILL_HDR.AR_DOC_TYPE=BILL_SO.AR_DOC_TYPE AND
BILL_HDR.AR_DOC=BILL_SO.AR_DOC AND
BILL_SO.ITEM=ITEM.ITEM (+) AND
BILL_SO.REVISION=ITEM.REVISION (+) AND
BILL_SO.AR_DOC=MEMO.AR_DOC (+) AND
BILL_SO.AR_DOC_LINE=MEMO.MEMO_LINE (+) AND
BILL_SO.AR_CCN=MEMO.SALES_CCN (+) AND
BILL_SO.AR_DOC_TYPE=MEMO.MEMO_TYPE (+) AND
ITEM.ITEM=C_STD_COST.ITEM (+) AND
ITEM.REVISION=C_STD_COST.REVISION (+) AND
AR_DOC.CREATED_DATE>=TO_DATE ('30-05-2006 00:00:00', 'DD-MM-YYYY
HH24:MI:SS') AND
AR_DOC.CREATED_DATE<TO_DATE ('14-06-2006 00:00:00', 'DD-MM-YYYY
HH24:MI:SS')
ORDER BY
AR_DOC.CUSTOMER, ITEM.PCThe explain plan showed:
SELECT STATEMENT
SORT ORDER BY
MERGE JOIN OUTER
SORT JOIN
NESTED LOOPS OUTER
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS OUTER
TABLE ACCESS FULL BILL_SO 4
TABLE ACCESS BY INDEX ROWID ITEM 5
INDEX UNIQUE SCAN PK_ITEM UNIQUE
TABLE ACCESS BY INDEX ROWID BILL_HDR 2
INDEX UNIQUE SCAN PK_BILL_HDR UNIQUE
TABLE ACCESS BY INDEX ROWID AR_DOC 1
INDEX UNIQUE SCAN PK_AR_DOC UNIQUE
TABLE ACCESS BY INDEX ROWID CUS_LOC 3
INDEX UNIQUE SCAN PK_CUS_LOC UNIQUE
TABLE ACCESS BY INDEX ROWID MEMO 6
INDEX RANGE SCAN PK_MEMO UNIQUE
SORT JOIN
TABLE ACCESS FULL COST_ITM 8The views I created were:
CREATE VIEW C_BILL_DET AS
SELECT
AR_CCN, AR_DOC_TYPE, AR_DOC, AR_DOC_LINE, ITEM,
REVISION, SO_SHIP_QTY, SO_SHIP_EXT_AMT, COST1
FROM
BILL_SO
UNION ALL
SELECT
AR_CCN, AR_DOC_TYPE, AR_DOC, AR_DOC_LINE, ITEM,
REVISION, SHIP_QTY, SHIP_EXT_AMT, COST1
FROM
CR_BLSH;
CREATE VIEW C_BILL_HDR AS
SELECT
AR_CCN, AR_DOC_TYPE, AR_DOC, RATE
FROM
BILL_HDR
UNION ALL
SELECT
AR_CCN, AR_DOC_TYPE, AR_DOC, RATE
FROM
CR_BLHD;The new query is:
SELECT
C_STD_COST.MAT, C_STD_COST.LAB, C_STD_COST.OHD, ITEM.PC, C_BILL_HDR.RATE,
C_BILL_DET.SO_SHIP_QTY, C_BILL_DET.SO_SHIP_EXT_AMT, AR_DOC.CUSTOMER,
C_BILL_DET.AR_DOC,
CUS_LOC.NAME, AR_DOC.CREATED_DATE, MEMO.TOT_ORD_QTY, MEMO.UNIT_PRICE,
MEMO.BOOK_RATE, AR_DOC.AR_DOC_TYPE, MEMO.MEMO_TYPE, C_BILL_DET.ITEM
FROM
AR_DOC, C_BILL_HDR, CUS_LOC, C_BILL_DET, ITEM, MEMO, C_STD_COST
WHERE
AR_DOC.AR_CCN=C_BILL_HDR.AR_CCN AND
AR_DOC.AR_DOC_TYPE=C_BILL_HDR.AR_DOC_TYPE AND
AR_DOC.AR_DOC=C_BILL_HDR.AR_DOC AND
AR_DOC.CUSTOMER=CUS_LOC.CUSTOMER AND
AR_DOC.CUS_AR_LOC=CUS_LOC.CUS_LOC AND
C_BILL_HDR.AR_CCN=C_BILL_DET.AR_CCN AND
C_BILL_HDR.AR_DOC_TYPE=C_BILL_DET.AR_DOC_TYPE AND
C_BILL_HDR.AR_DOC=C_BILL_DET.AR_DOC AND
C_BILL_DET.ITEM=ITEM.ITEM (+) AND
C_BILL_DET.REVISION=ITEM.REVISION (+) AND
C_BILL_DET.AR_DOC=MEMO.AR_DOC (+) AND
C_BILL_DET.AR_DOC_LINE=MEMO.MEMO_LINE (+) AND
C_BILL_DET.AR_CCN=MEMO.SALES_CCN (+) AND
C_BILL_DET.AR_DOC_TYPE=MEMO.MEMO_TYPE (+) AND
ITEM.ITEM=C_STD_COST.ITEM (+) AND
ITEM.REVISION=C_STD_COST.REVISION (+) AND
AR_DOC.CREATED_DATE>=TO_DATE ('30-05-2006 00:00:00', 'DD-MM-YYYY
HH24:MI:SS') AND
AR_DOC.CREATED_DATE<TO_DATE ('14-06-2006 00:00:00', 'DD-MM-YYYY
HH24:MI:SS')
ORDER BY
AR_DOC.CUSTOMER, ITEM.PCThe explain plan is:
SELECT STATEMENT
SORT ORDER BY
MERGE JOIN OUTER
SORT JOIN
NESTED LOOPS
NESTED LOOPS
MERGE JOIN
SORT JOIN
NESTED LOOPS OUTER
NESTED LOOPS OUTER
VIEW C_BILL_DET 4
UNION-ALL
TABLE ACCESS FULL BILL_SO 9
TABLE ACCESS FULL CR_BLSH 10
TABLE ACCESS BY INDEX ROWID ITEM 5
INDEX UNIQUE SCAN PK_ITEM UNIQUE
TABLE ACCESS BY INDEX ROWID MEMO 6
INDEX RANGE SCAN PK_MEMO UNIQUE
SORT JOIN
VIEW C_BILL_HDR 2
UNION-ALL
TABLE ACCESS FULL BILL_HDR 11
TABLE ACCESS FULL CR_BLHD 12
TABLE ACCESS BY INDEX ROWID AR_DOC 1
INDEX UNIQUE SCAN PK_AR_DOC UNIQUE
TABLE ACCESS BY INDEX ROWID CUS_LOC 3
INDEX UNIQUE SCAN PK_CUS_LOC UNIQUE
SORT JOIN
TABLE ACCESS FULL COST_ITM 8I don't understand.
I try your with statement and get: "end_date" invalid identifier as an error
I start my query out:
WITH start_date as
(select to_date ('08/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM') from dual),
end_date as (select to_date ('08/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM) from dual)
select sales.id, start_date as callstart, end_date as callend
where sales.created_timestamp >= start_date
and sales.created_timestamp < end_date
UNION ALL
<<<<<<<here is where you take the last select statement and replace sales with manufacturing>>>>>>>>>>>>>
UNION ALL
<<<<<<<here is where you take the last select statement and replace sales with engineering>>>>>>>>>>>>>
and it still fails. -
Hi All,
I am looking at an Technical solution for Restricting the direct access some specific tables in my data base to all the users(Except admins and few Service accounts). However views created on top of these tables would be exposed to all Users.
Could any one help me with the best solution.
Thanks in advance,
Regards,
Raja SuriHello,
You can try to create a new role "Client_User" in the database and deny access to the new role on the specify tables. And then add all user which you want to restricting the direct access the specific tables to the database role.
For example:
Use Database
CREATE ROLE [Client_User] AUTHORIZATION db_securityadmin;
DENY SELECT ON OBJECT::schema.table TO [Client_User] ;
EXEC sp_addrolemember 'Client_User', 'username';
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
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 -
Strange behaviour of view based on several tables join with union all
Dear fellows we r facing a strange problem we have a view based on several tables joined by union all ,when we issue an ordered query on date,rows returned are unusually different than they should be .
Is oracle has some special behaviour for view based on union all ?
I m using oracle 8.1.6 on windows 2000
Kashif SohailDid you ever solve this problem? I have two select statements based on 4 tables and 3 views using about 5 more tables. When I execute each select individually I get exactly what is expected. When I UNION ALL both selects together, I get "no rows returned", however when I UNION them I get exactly what is expected. I should get the same answer for both UNION ALL and UNION. The two select statements are identical, except for one column where I changed the constant to be different. Any thoughts?
-
Inconsistent SQL results when using View with UNION-ALL and table function
Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
Database version: 11.2.0.3 Enterprise Edition, Single node
Thank you.
CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
CREATE OR REPLACE VIEW TEMP_T1T2_V AS
SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
SET SERVEROUTPUT ON;
DECLARE
TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
BEGIN
TEMP_OBJ_TAB.EXTEND;
TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
END;
BEGIN
ADD_TO_TEMP_OBJ_TAB(100);
ADD_TO_TEMP_OBJ_TAB(116);
ADD_TO_TEMP_OBJ_TAB(279);
ADD_TO_TEMP_OBJ_TAB(364);
DBMS_OUTPUT.PUT_LINE('=====================');
FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
END LOOP;
DBMS_OUTPUT.PUT_LINE('---------------------');
SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
FROM TEMP_T1T2_V VW
WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
END LOOP;
DBMS_OUTPUT.PUT_LINE('---------------------');
IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
END IF;
DBMS_OUTPUT.PUT_LINE('---------------------');
END;
/I can reproduce it:
SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter user-name: scott
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select *
2 from v$version
3 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL>
SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL>
SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
72883 rows updated.
SQL>
SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
Index created.
SQL>
SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
Index created.
SQL>
SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
2 SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
View created.
SQL>
SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
2 /
Type created.
SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
2 /
Type created.
SQL> SET SERVEROUTPUT ON;
SQL>
SQL> DECLARE
2 TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
3 TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
4 TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
5 PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
6 BEGIN
7 TEMP_OBJ_TAB.EXTEND;
8 TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
9 END;
10 BEGIN
11 ADD_TO_TEMP_OBJ_TAB(100);
12 ADD_TO_TEMP_OBJ_TAB(116);
13 ADD_TO_TEMP_OBJ_TAB(279);
14 ADD_TO_TEMP_OBJ_TAB(364);
15 DBMS_OUTPUT.PUT_LINE('=====================');
16 FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
17 LOOP
18 DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
19 END LOOP;
20 DBMS_OUTPUT.PUT_LINE('---------------------');
21 SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
22 FROM TEMP_T1T2_V VW
23 WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
24 FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
25 FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
26 LOOP
27 DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
28 END LOOP;
29 DBMS_OUTPUT.PUT_LINE('---------------------');
30 IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
31 FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
32 LOOP
33 DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
34 END LOOP;
35 ELSE
36 DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
37 END IF;
38 DBMS_OUTPUT.PUT_LINE('---------------------');
39 END;
40 /
=====================
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
364 : I_AUDIT
364 : I_AUDIT
364 : I_AUDIT
364 : I_AUDIT
PL/SQL procedure successfully completed.
SQL> column object_name format a30
SQL> select object_id,
2 object_name
3 from dba_objects
4 where object_id in (100,116,279,364)
5 /
OBJECT_ID OBJECT_NAME
100 ORA$BASE
116 DUAL
279 MAP_OBJECT
364 I_AUDIT
SQL> Works fine in:
=====================
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
100 : ORA$BASE
116 : DUAL
364 : SYSTEM_PRIVILEGE_MAP
279 : MAP_OBJECT
PL/SQL procedure successfully completed.
SQL> select object_id,
2 object_name
3 from dba_objects
4 where object_id in (100,116,279,364)
5 /
OBJECT_ID OBJECT_NAME
100 ORA$BASE
116 DUAL
364 SYSTEM_PRIVILEGE_MAP
279 MAP_OBJECT
SQL> select *
2 from v$version
3 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL>SY.
Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM -
Union all for 3 tables on repository
Hello, could anybody help me to find best way for my case?
i have 3 physical tables - Objects, Facts and Calendar table.
On repository, i make this scheme:
OBJECTS left join FACTS right join DATES
I creating analysis based on pivot table, i need all Dates (from period) and all Objects, it must look like this:
_______| Month Day 1 | ... | Month Last Day |
object 1 | fact X______| ... | fact XX _______|
..._____|..._________| ... | ... ___________|
object N | fact Z_____ | ... | fact ZZ _______|
So, physical query must be like this:
all facts (with filter by choosen period)
UNION ALL
all dates (with filter by choosen period)
UNION ALL
all objects
I don't like to make 3 unions on analysis criteria, don't like to use one view on physical level.
How i can make this on repository?yes, i found solution, really thanks to Nico :)
[Possibilities to densify the data|http://gerardnico.com/wiki/dat/obiee/densification]
You have two possibilities in OBIEE to densify the data :
by designing the repository : OBIEE - Densification with the fact-based fragmentation capabilities
or with the OBIEE logical Sql : OBIEE - Densification with the logical 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.
Maybe you are looking for
-
Dear All, I am using my own MenuItemUI to render the disabled foreground for html text present in the Menu Item. So, in my CustomMenuUI, i am overriding the paint() method to obtain the disabled foreground when the Menu Item is disabled. But every th
-
Retriving Localization Data Italy
Hi, i need to build a map like this http://elocation.oracle.com/elocation/ajax/ with the same information about street park etc. Can you tell mi where i find the table data with the sdo_geometry info ? Thank you very much! Have a nice day !
-
Can not download Dreamweaver CC 2014 through Creative Cloud, takes me through Signed Out
Hello, I can not able to download Dreamweaver CC through "Creative Cloud", it is always saying "You have been signed out" , how to resolve this error? Even if I was trying to signed in through different email address , but no luck Please feel free to
-
Skype keeps logging me out automatically
The following is the error that shows and I've already unintalled and reinstalled Skype. Still showing the same error. "Process: Skype [649] Path: /Applications/Skype.app/Contents/MacOS/Skype Identifier: com.skype.skype Version: 7.5 (7.5.0.73 Code Ty
-
Cust_Acct_Site_id populated in Hz_cust_account_role
I have two records in HZ_CUST_ACCOUNT_ROLES for a single CUST_ACCOUNT_ID, one with CUST_ACCT_SITE_ID populated another not. e.g Role_ID party_id Account_id Cust_acct_site_id 1 300 284 900 2 301 284 But when I query in Customr screen for this account