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,
Patrick
Attached 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
Similar Messages
-
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 -
Slow while going from one screen to another screen
Hi,
I have installed SAP 4.7 version. The hardware of system is 3GHz processor and 1 GB RAM. It is taking more time while going one screen to another. So after entering XD01 or any tcode , I have to wait for seconds some times 10 second to a get a screen and getting a screen form another screen.
Can any one tell me reason for this and how can be this issue resolved.
Thanks,
ManasWhen using system for the first time, a lot of compiling still has to be done which takes time, but also the fact that your system 'only' has 1 GB RAM, could cause these problems as well. According to requirements, 1GB should be enough, but I would recommend at least 2GB.
-
IS there any way to copy all your old buddies from and old screen name
to a new screen name?
thanks!
using ichat on leopardIn case you're want to use an old AIM screen name you've not been using for a while I think it is better to just refresh your complete buddy list by sending your contacts an email with your new screen name and have them update this in their data base.
Ask them to respond with their recent contact info and add their active screen name to your buddy list. Every now and then this can be very useful cause contact info tends to change when people move, get a new job or switch to another computer.
Free Aim screen names that have been inactive for a certain period will become invalid, understandable because their database needs to be up to date as well. -
Improve performance with union all
Hello there,
Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
SQL> show parameter optimizer
ORA-00942: Tabel of view bestaat niet. (Does not exist)I have the following query using the following input variables
- id
- startdate
- enddate
The query has the following format
- assume that the number of columns are the same
- t1 != t3 and t2 != t4
select ct.*
from
select t1.*
from tabel1 t1
join tabel2 t2
on t2.key = t1.key
union all
select t3.*
from tabel3 t3
join tabel4 t4
on t4.key = t3.key
where ct.id = :id
and ct.date >= :startdate
and ct.date < :enddate
order by ct.dateIt is performing really slow, after the first read it performs fast.
I tried the following thing, which was actually even slower!
with t1c as
select t1.*
from tabel1 t1
join tabel2 t2
on t2.key = t1.key
where t1.id = :id
and t1.date >= :startdate
and t1.date < :enddate
t2c as
select t3.*
from tabel3 t3
join tabel4 t4
on t4.key = t3.key
where t3.id = :id
and t3.date >= :startdate
and t3.date < :enddate
select ct.*
from
select *
from t1c
union all
select *
from t2c
order by ct.dateSo in words, I have an 'union all' construction reading from different tables with matching columns 'id' and 'date'.
How can I improve this? Can it be improved? If you do not know the answer, but maybe a suggestion, I will be happy aswell!!!
Thanks in advance!
Kind regards,
Metroickha>
So in words, I have an 'union all' construction reading from different tables with matching columns 'id' and 'date'.
How can I improve this? Can it be improved? If you do not know the answer, but maybe a suggestion, I will be happy aswell!!!
>
If you want to improve on what Oracle is doing you first need to know 'what Oracle is doing'.
Post the execution plans for the query that show what Oracle is doing.
Also post the DDL for the tables and indexes and the record counts for the tables and ID/DATE predicates. -
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> -
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 -
Remove all non-number characters from a string
hi
How i can remove all non-number characters from a column ? for example , i have a column that contains data like
'sd3456'
'gfg87s989'
'45/45fgfg'
'4354-df4456'
and i want to convert it to
'3456'
'87989'
'4545'
'43544456'
thx in advOr in 9i,
Something like this ->
satyaki>
satyaki>with vat
2 as
3 (
4 select 'sd3456' cola from dual
5 union all
6 select 'gfg87s989' from dual
7 union all
8 select '45/45fgfg' from dual
9 union all
10 select '4354-df4456' from dual
11 )
12 select translate(cola,'abcdefghijklmnopqrstuvwxyz-/*#$%^&@()/?,<>;:{}[]|\`"',' ') res
13 from vat;
RES
3456
87989
4545
43544456
Elapsed: 00:00:00.00
satyaki>
{code}
I checked this with minimum test cases. It will be better if you checked it with other cases.
Regards.
Satyaki De. -
Report which concatenates 13 views with union all running slowly
Oracle 8.1.7 windows 2000 server
I am trying to improve the performance of a report which is comprised of 13 views.
When I run each of the views individually, the total run time for the views is less than 5 minutes. When I run the report, it takes 28 minutes.
Can anyone suggest why the extra time is being taken?
To reiterate:
select a,b from c; (executes in 10 seconds)
select d, e from f (executes in 3 seconds)
select x, y from z (executes in 1 minute)
total runs time = 5 minutes
However,
select a,b from c
union all
select d, e from f
union all
select x, y from z (executes in 28 minutes)
The execution plans do not change between the report and the indiividual views. Views are being concatenated with union all so no sorting is taking place
Many thanks,
Jason Parker.
Edited by: jclparker on Feb 18, 2009 4:26 AM
Edited by: jclparker on Feb 18, 2009 4:30 AMCould you post the execution plan? Please use formatting tags to save the white space while posting the plan.
-
I have a strange bug with Oracle 11g. I was trying tu use Microsoft Entity Framework; the queries produced are a bit special and some of them are using UNION ALL in a way that produces an error.
Let us create this very very simple table (I used SQL Developer and let the default) :
CREATE TABLE "USER"."TABLE1"
( "COLUMN1" VARCHAR2(4000 BYTE),
"COLUMN2" NUMBER
Try this query, even without data :
SELECT * FROM(
SELECT NULL AS C1 FROM USER.TABLE1
UNION ALL
SELECT NULL AS C1 FROM USER.TABLE1
UNION ALL
SELECT COLUMN2 FROM USER.TABLE1
this produces a "*Expression must have same datatype as corresponding expression*" error !
Now if you do the same on COLUM1 of type VARCHAR2 :
SELECT * FROM(
SELECT NULL AS C1 FROM USER.TABLE1
UNION ALL
SELECT NULL AS C1 FROM USER.TABLE1
UNION ALL
SELECT COLUMN1 FROM USER.TABLE1
No error is raised, the query is executed normally.
Note that if you do :
SELECT * FROM(
SELECT NULL AS C1 FROM USER.TABLE1
UNION ALL
SELECT COLUMN2 FROM USER.TABLE1
no error is raised.
What's happening ??!!
Edited by: user5485007 on 12 sept. 2008 04:34In 10.2.0.4:
SQL> CREATE TABLE t1
2 ( "COLUMN1" VARCHAR2(4000 BYTE)
3 , "COLUMN2" NUMBER
4 )
5 /
Table created.
SQL> SELECT * FROM(
2 SELECT NULL AS C1 FROM t1
3 UNION ALL
4 SELECT NULL AS C1 FROM t1
5 )
6 UNION ALL
7 SELECT COLUMN2 FROM t1
8 /
SELECT * FROM(
ERROR at line 1:
ORA-01790: expression must have same datatype as corresponding expression
SQL> SELECT * FROM(
2 SELECT NULL AS C1 FROM t1
3 UNION ALL
4 SELECT NULL AS C1 FROM t1
5 )
6 UNION ALL
7 SELECT COLUMN1 FROM t1
8 /
no rows selected
SQL> SELECT * FROM(
2 SELECT NULL AS C1 FROM t1
3 )
4 UNION ALL
5 SELECT COLUMN2 FROM t1
6 /
no rows selectedThe same as the original poster on 11g ...
Regards,
Rob. -
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> -
Hi Guys,
I require order by to be applied on both queries separatly.
select a1,a2 from a
union all
select b1,b2 from b;
in above scenerio, i want to sort query 1 by first column ie.a1 and query 2 by sencond column i.e. b2.
Please suggest pointers on it.
-pmThis might do it:
select c1,c2
from
select 1 as i, a1 as c1, a2 as c2 from a
union all
select 2 as i, b1 as c1, b2 as c2 from b
order by
i,
case i
when 1 then c1
when 2 then c2
end;Edited by: Toon Koppelaars on Mar 21, 2011 6:39 AM -
Help with a union all statement
Hello
I am pulling a query much like this:
(select ID, Created_timestamp from snapshot1
where created_timestamp >= to_date ('8/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM')
and created_timestamp < to_date('8/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'))
UNION ALL
(select ID, created_timestamp from snapshot2
where created_timestamp >= to_date ('8/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM')
and created_timestamp < to_date('8/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'))
UNION ALL
(select ID, created_timestamp from data_history
where created_timestamp >= to_date ('8/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM')
and created_timestamp < to_date('8/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'))
Is there an easier way to handle created_timestamp?
I would like to put it at the beginning so I only have to change it in one place.I 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. -
Select query-using Union All display duplicate records.
Hello All Gurus-
I am using Oracle 9.i
When i use the following query to fetch the records based on BUILDNUMBERNAME and ASSIGNED_BUILD then i am getting duplicate records -
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
How can i use the order by on T1.ID ? When i use the Order by T1.ID then it throws some error.
Kindly help me in this :(
Thanks in advance.Sorry for not providing all of the details -
I am using Toad tool to run the query.
1-When i use the following query -
Select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6' order by T1.ID
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6' order by T1.ID
ORA-00933: SQL command not properly ended.
2-If i am not using the T1.ID and run the following query
Select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
Then it is running fine but it is displaying the duplicate values like -
00089646
00087780
00089148
00090118
00090410
00088503
00080985
00084526
00087108
00087109
00087117
00088778
00086714
00079518
00087780
00089148
00090392
00090393
00090395
00090398
00090401
00090402
00090403
00090406
00090408
00088503
00080985
00084526
00087108
00087109
00087117
00088778
00086714
00079518
Maybe you are looking for
-
Changing color of a field after changing the data using OOPS ALV.
Hi Experts, I have displayed three fields (price, no. of products and total amount) in my ALV grid using OOPS. Then am changing the data in either price or no. of products fields. When I click ENTER key the value in total amount changes corresponding
-
How to add a customer field or extn coll in the tab1&2&3..of a UDO doc?
Hi Experts, Does anybody know how to add a customer field or extn collection in the unused tabs like tab1&2...in a UDO document? Thanks for your reply in advance. Thanks & Regards, David
-
Installing New IDE Hard Drive.
I can not get my G3 to find and IDE hard drives. I can start up from a 10.2 cd and into os 9.2 but can not fid the added hard drive. Can anyone help
-
Is or When Dev 6.0.5.2xx be made avaliable on OTN (Urgent)
To Oracle Developent Team/anyone The Dewloper Server avaliable for OTN memebrs is 6.0.5.1 on the web to be downloaded it has lot of bugs in it. As per the patch1 made avaliable by Oracle is for 6.0.5.29.xx. My question is that when or is Developer 6.
-
Limit on Cell Definition entries
Hi all, I am facing a strange problem working with cell definitions. I have a time structure(Columns) with 13 elements( one elements is for previous year and remaining 12 are for all the months in current year). I am having a text variable displ