with ObjectHistory as (
select temp.OBJECT_KEY, MAX(temp.SOURCE_EVENT_DATE) as MAXSED, temp.USER_NAME, temp.EVENT_DATE FROM (
SELECT max(OBJECT_KEY) as OBJECT_KEY, USER_NAME, EVENT_DATE, SOURCE_EVENT_DATE
FROM V_AAA GROUP BY OBJECT_HISTORY_KEY, USER_NAME, EVENT_DATE, SOURCE_EVENT_DATE ) temp, BBB SKM
WHERE SKM.OBJECT_KEY = temp.OBJECT_KEY and SKM.ULT_PARENT_OBJECT_KEY = 2 GROUP BY temp.OBJECT_KEY, temp.SOURCE_EVENT_DATE, temp.USER_NAME, temp.EVENT_DATE
)
SELECT H.OBJECT_KEY, H.USER_NAME, H.EVENT_DATE FROM ObjectHistory H ;
以下
V_AAA
:这是一个视图和
BBB
:这是1100万条记录表
执行此查询需要很长时间才能完成。
Windows资源监视器:
Disk I/O : Reads (1 million Bytes/sec) ,
Write (55,000 Bytes/Sec) : 100% Highest Active Time
Physical Memory (16 GB) : 82% Used
CPU (4 core, 2.24 GHz) : 12% Used
我也关注了这个博客:BotFramework docs。没有任何查询被阻止。
来自dba_objects
表的条目为object_name
:BBB
和锁定模式:3
查询计划如下
Plan hash value: 3833081753
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2844 | 166K| | 1186K (2)| 03:57:17 |
| 1 | HASH GROUP BY | | 2844 | 166K| | 1186K (2)| 03:57:17 |
|* 2 | HASH JOIN | | 2844 | 166K| | 1186K (2)| 03:57:17 |
| 3 | TABLE ACCESS BY INDEX ROWID | BBB | 3384 | 33840 | | 492 (0)| 00:00:06 |
|* 4 | INDEX RANGE SCAN | IK_BBB3 | 3593 | | | 14 (0)| 00:00:01 |
| 5 | VIEW | | 4858K| 231M| | 1185K (2)| 03:57:11 |
| 6 | HASH GROUP BY | | 4858K| 264M| 335M| 1185K (2)| 03:57:11 |
| 7 | VIEW | V_AAA | 4858K| 264M| | 1118K (2)| 03:43:43 |
| 8 | UNION-ALL | | | | | | |
| 9 | NESTED LOOPS | | 1 | 193 | | 119K (3)| 00:23:50 |
| 10 | NESTED LOOPS | | 1 | 153 | | 119K (3)| 00:23:50 |
| 11 | NESTED LOOPS | | 1 | 133 | | 119K (3)| 00:23:50 |
| 12 | NESTED LOOPS | | 1 | 90 | | 119K (3)| 00:23:50 |
| 13 | NESTED LOOPS | | 1 | 78 | | 119K (3)| 00:23:50 |
| 14 | NESTED LOOPS | | 1 | 57 | | 119K (3)| 00:23:50 |
| 15 | NESTED LOOPS | | 1 | 49 | | 119K (3)| 00:23:50 |
|* 16 | HASH JOIN | | 1 | 46 | | 119K (3)| 00:23:50 |
| 17 | INDEX FULL SCAN | PK276_1 | 1 | 13 | | 0 (0)| 00:00:01 |
| 18 | TABLE ACCESS FULL | AAA | 79M| 2492M| | 118K (2)| 00:23:43 |
|* 19 | INDEX UNIQUE SCAN | PK84 | 1 | 3 | | 0 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID| UOM | 1 | 8 | | 1 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | PK3 | 1 | | | 0 (0)| 00:00:01 |
| 22 | TABLE ACCESS BY INDEX ROWID | RU | 1 | 21 | | 1 (0)| 00:00:01 |
|* 23 | INDEX UNIQUE SCAN | PK1 | 1 | | | 0 (0)| 00:00:01 |
| 24 | TABLE ACCESS BY INDEX ROWID | CTL_O_VER | 1 | 12 | | 2 (0)| 00:00:01 |
|* 25 | INDEX UNIQUE SCAN | PK6 | 1 | | | 1 (0)| 00:00:01 |
| 26 | TABLE ACCESS BY INDEX ROWID | CTL_O | 1 | 43 | | 2 (0)| 00:00:01 |
|* 27 | INDEX UNIQUE SCAN | PK240 | 1 | | | 1 (0)| 00:00:01 |
|* 28 | TABLE ACCESS BY INDEX ROWID | OBJECT_TYPE | 1 | 20 | | 1 (0)| 00:00:01 |
|* 29 | INDEX UNIQUE SCAN | PK10 | 1 | | | 0 (0)| 00:00:01 |
|* 30 | INDEX RANGE SCAN | IX1_BBB | 1 | 40 | | 2 (0)| 00:00:01 |
|* 31 | HASH JOIN | | 2100K| 368M| | 503K (1)| 01:40:38 |
| 32 | TABLE ACCESS FULL | RU | 450 | 9450 | | 5 (0)| 00:00:01 |
|* 33 | HASH JOIN | | 2100K| 326M| | 503K (1)| 01:40:38 |
| 34 | TABLE ACCESS FULL | UOM | 691 | 5528 | | 3 (0)| 00:00:01 |
|* 35 | HASH JOIN | | 2100K| 310M| | 503K (1)| 01:40:38 |
| 36 | INDEX FULL SCAN | PK84 | 35 | 105 | | 1 (0)| 00:00:01 |
|* 37 | HASH JOIN | | 2100K| 304M| | 503K (1)| 01:40:38 |
| 38 | INDEX FAST FULL SCAN | PK11 | 1197 | 4788 | | 3 (0)| 00:00:01 |
|* 39 | HASH JOIN | | 2936K| 414M| 133M| 503K (1)| 01:40:37 |
|* 40 | HASH JOIN | | 1105K| 121M| 84M| 208K (1)| 00:41:40 |
|* 41 | HASH JOIN | | 770K| 75M| 198M| 88103 (1)| 00:17:38 |
|* 42 | HASH JOIN | | 2772K| 166M| | 50385 (2)| 00:10:05 |
|* 43 | TABLE ACCESS FULL | OBJECT_TYPE | 12 | 240 | | 3 (0)| 00:00:01 |
| 44 | TABLE ACCESS FULL | CTL_O | 20M| 852M| | 50235 (1)| 00:10:03 |
| 45 | INDEX FAST FULL SCAN | IX1_BBB | 5781K| 220M| | 13557 (1)| 00:02:43 |
| 46 | TABLE ACCESS FULL | CTL_O_VER | 29M| 341M| | 81689 (1)| 00:16:21 |
| 47 | TABLE ACCESS FULL | AAA | 79M| 2492M| | 118K (2)| 00:23:43 |
|* 48 | HASH JOIN | | 2757K| 512M| | 496K (2)| 01:39:16 |
| 49 | INDEX FAST FULL SCAN | PK11 | 1197 | 4788 | | 3 (0)| 00:00:01 |
|* 50 | HASH JOIN | | 2757K| 502M| | 496K (1)| 01:39:15 |
|* 51 | TABLE ACCESS FULL | DIGD | 2357 | 25927 | | 6 (0)| 00:00:01 |
|* 52 | HASH JOIN | | 1957K| 336M| | 496K (1)| 01:39:15 |
| 53 | TABLE ACCESS FULL | RU | 450 | 9450 | | 5 (0)| 00:00:01 |
|* 54 | HASH JOIN | | 1957K| 296M| | 496K (1)| 01:39:15 |
| 55 | TABLE ACCESS FULL | UOM | 691 | 5528 | | 3 (0)| 00:00:01 |
|* 56 | HASH JOIN | | 1957K| 281M| | 496K (1)| 01:39:15 |
| 57 | INDEX FULL SCAN | PK84 | 35 | 105 | | 1 (0)| 00:00:01 |
|* 58 | HASH JOIN | | 1957K| 276M| 89M| 496K (1)| 01:39:15 |
|* 59 | HASH JOIN | | 736K| 80M| 56M| 203K (1)| 00:40:43 |
|* 60 | HASH JOIN | | 513K| 50M| 132M| 84815 (1)| 00:16:58 |
|* 61 | HASH JOIN | | 1848K| 111M| | 50385 (2)| 00:10:05 |
|* 62 | TABLE ACCESS FULL | OBJECT_TYPE | 8 | 160 | | 3 (0)| 00:00:01 |
| 63 | TABLE ACCESS FULL | CTL_O | 20M| 852M| | 50235 (1)| 00:10:03 |
| 64 | INDEX FAST FULL SCAN | IX1_BBB | 5781K| 220M| | 13557 (1)| 00:02:43 |
| 65 | TABLE ACCESS FULL | CTL_O_VER | 29M| 341M| | 81689 (1)| 00:16:21 |
| 66 | TABLE ACCESS FULL | AAA | 79M| 2492M| | 118K (2)| 00:23:43 |
----------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("SKM"."OBJECT_KEY"="TEMP"."OBJECT_KEY")
4 - access("SKM"."ULT_PARENT_OBJECT_KEY"=2)
16 - access("W"."EAWORKSPACE_ID"="OB"."CTL_DIAGRAM_ID")
19 - access("RO"."REPO_OPERATION_ID"="OB"."REPO_OPERATION_ID")
21 - access("OB"."UOM_ID"="UON"."UOM_ID")
23 - access("RU"."RU_ID"="UON"."RU_ID")
25 - access("OB"."CTL_O_VER_ID"="COV"."CTL_O_VER_ID")
27 - access("COV"."CTL_O_ID"="CO"."CTL_O_ID")
28 - filter("OT"."NAME"='EADIAGRAM' OR "OT"."NAME"='EAPROJECT' OR "OT"."NAME"='EAWORKSPACE')
29 - access("OT"."OBJECT_TYPE_ID"="CO"."OBJECT_TYPE_ID")
30 - access("SKM"."SOURCE_GUID"="CO"."OBJECT_GUID")
31 - access("RU"."RU_ID"="UON"."RU_ID")
33 - access("OB"."UOM_ID"="UON"."UOM_ID")
35 - access("RO"."REPO_OPERATION_ID"="OB"."REPO_OPERATION_ID")
37 - access("D"."DIAGRAM_ID"="OB"."CTL_DIAGRAM_ID")
39 - access("OB"."CTL_O_VER_ID"="COV"."CTL_O_VER_ID")
40 - access("COV"."CTL_O_ID"="CO"."CTL_O_ID")
41 - access("SKM"."SOURCE_GUID"="CO"."OBJECT_GUID")
42 - access("OT"."OBJECT_TYPE_ID"="CO"."OBJECT_TYPE_ID")
43 - filter("OT"."NAME"='ATTRIBUTE' OR "OT"."NAME"='CHECK_CONSTRAINT' OR "OT"."NAME"='DB_VIEW' OR
"OT"."NAME"='DIAGRAM' OR "OT"."NAME"='ENTITY' OR "OT"."NAME"='ENTITY_DISPLAY' OR "OT"."NAME"='MODEL' OR
"OT"."NAME"='RELATIONSHIP' OR "OT"."NAME"='RELATIONSHIP_DISPLAY' OR "OT"."NAME"='SUBMODEL' OR
"OT"."NAME"='VIEW_DISPLAY' OR "OT"."NAME"='VIEW_FIELD')
48 - access("D"."DIAGRAM_ID"="DD"."DIAGRAM_ID")
50 - access("DD"."ENTERPRISE_DD_ID"="OB"."CTL_DIAGRAM_ID")
51 - filter("DD"."FLAGS"=0 OR "DD"."FLAGS"=1)
52 - access("RU"."RU_ID"="UON"."RU_ID")
54 - access("OB"."UOM_ID"="UON"."UOM_ID")
56 - access("RO"."REPO_OPERATION_ID"="OB"."REPO_OPERATION_ID")
58 - access("OB"."CTL_O_VER_ID"="COV"."CTL_O_VER_ID")
59 - access("COV"."CTL_O_ID"="CO"."CTL_O_ID")
60 - access("SKM"."SOURCE_GUID"="CO"."OBJECT_GUID")
61 - access("OT"."OBJECT_TYPE_ID"="CO"."OBJECT_TYPE_ID")
62 - filter("OT"."NAME"='ATTACHMENT' OR "OT"."NAME"='ATTACHMENT_TYPE' OR "OT"."NAME"='DATA_DICTIONARY' OR
"OT"."NAME"='DEFAULT' OR "OT"."NAME"='DOMAIN' OR "OT"."NAME"='REFERENCE_VALUE' OR "OT"."NAME"='RULE' OR
"OT"."NAME"='USER_DATATYPE')
查看脚本:V_AAA
CREATE OR REPLACE FORCE VIEW "V_AAA" ("AAA_KEY", "OBJECT_KEY", "OPERATION", "EVENT_DATE", "SOURCE_EVENT_DATE", "USER_NAME", "USER_COMMENT", "SYNC_DATE", "SOURCE_GUID", "DIAG_GUID", "OBJECT_TYPE", "SOURCE_SYSTEM") AS
SELECT
OB.Object_History_ID AAA_KEY,
SKM.OBJECT_KEY OBJECT_KEY,
RO.Name OPERATION,
(TIMESTAMP '1970-01-01 00:00:00.0' + NUMTODSINTERVAL(OB.Event_Date, 'second')) EVENT_DATE, -- now it is the GMT time
OB.Event_Date SOURCE_EVENT_DATE,
RU.Name USER_NAME,
RC.String USER_COMMENT,
OB.Event_Date*1000 SYNC_DATE,
CO.Object_GUID SOURCE_GUID,
W.Object_GUID DIAG_GUID,
OT.Name OBJECT_TYPE,
'EASTUDIO' as SOURCE_SYSTEM
FROM Object_History OB
INNER JOIN ctl_obj_Ver COV on OB.ctl_obj_Ver_ID = COV.ctl_obj_Ver_ID
INNER JOIN ctl_obj CO on COV.ctl_obj_ID = CO.ctl_obj_ID
INNER JOIN sk_map SKM on SKM.SOURCE_GUID = CO.Object_GUID
LEFT OUTER JOIN Repo_Comment RC on OB.Repo_Comment_ID = RC.Repo_Comment_ID
INNER JOIN repo_oper RO on RO.repo_oper_ID = OB.repo_oper_ID
INNER JOIN User_On_Machine UON on OB.User_On_Machine_ID = UON.User_On_Machine_ID
INNER JOIN Repo_User RU on RU.Repo_User_ID = UON.Repo_User_ID
INNER JOIN EAWorkspace W on W.EAWorkspace_ID = OB.Ctl_Diag_ID
INNER JOIN Object_Type OT on OT.Object_Type_ID = CO.Object_Type_ID
WHERE
OT.Name in ('EAWORKS','EADIAG','EAPROJ')
UNION ALL
SELECT
OB.Object_History_ID as AAA_KEY,
SKM.OBJECT_KEY OBJECT_KEY,
RO.Name as OPERATION,
(TIMESTAMP '1970-01-01 00:00:00.0' + NUMTODSINTERVAL(OB.Event_Date, 'second')) EVENT_DATE, -- now it is the GMT time
OB.Event_Date as SOURCE_EVENT_DATE,
RU.Name as USER_NAME,
RC.String as USER_COMMENT,
OB.Event_Date*1000 SYNC_DATE,
CO.Object_GUID as SOURCE_GUID,
D.Object_GUID as DIAG_GUID,
OT.Name as OBJECT_TYPE,
'ERStudio' as SOURCE_SYSTEM
FROM Object_History OB
INNER JOIN ctl_obj_Ver COV on OB.ctl_obj_Ver_ID = COV.ctl_obj_Ver_ID
INNER JOIN ctl_obj CO on COV.ctl_obj_ID = CO.ctl_obj_ID
INNER JOIN sk_map SKM on SKM.SOURCE_GUID = CO.Object_GUID
LEFT OUTER JOIN Repo_Comment RC on OB.Repo_Comment_ID = RC.Repo_Comment_ID
INNER JOIN repo_oper RO on RO.repo_oper_ID = OB.repo_oper_ID
INNER JOIN User_On_Machine UON on OB.User_On_Machine_ID = UON.User_On_Machine_ID
INNER JOIN Repo_User RU on RU.Repo_User_ID = UON.Repo_User_ID
INNER JOIN Diag D on D.Diag_ID = OB.Ctl_Diag_ID
INNER JOIN Object_Type OT on OT.Object_Type_ID = CO.Object_Type_ID
WHERE
OT.Name in ('DIAG','MODEL','ENTITY','ATTRIBUTE','ENTITY_DISPLAY',
'RELATIONSHIP','RELATIONSHIP_DISPLAY','SUBMODEL','CHECK_CONSTRAINT',
'DB_VIEW','VIEW_FIELD','VIEW_DISPLAY')
UNION ALL
SELECT
OB.Object_History_ID as AAA_KEY,
SKM.OBJECT_KEY OBJECT_KEY,
RO.Name as OPERATION,
(TIMESTAMP '1970-01-01 00:00:00.0' + NUMTODSINTERVAL(OB.Event_Date, 'second')) EVENT_DATE, -- now it is the GMT time
OB.Event_Date as SOURCE_EVENT_DATE,
RU.Name as USER_NAME,
RC.String as USER_COMMENT,
OB.Event_Date*1000 SYNC_DATE,
CO.Object_GUID as SOURCE_GUID,
D.Object_GUID as DIAG_GUID,
OT.Name as OBJECT_TYPE,
'ERStudio' as SOURCE_SYSTEM
FROM Object_History OB
INNER JOIN ctl_obj_Ver COV on OB.ctl_obj_Ver_ID = COV.ctl_obj_Ver_ID
INNER JOIN ctl_obj CO on COV.ctl_obj_ID = CO.ctl_obj_ID
INNER JOIN sk_map SKM on SKM.SOURCE_GUID = CO.Object_GUID
LEFT OUTER JOIN Repo_Comment RC on OB.Repo_Comment_ID = RC.Repo_Comment_ID
INNER JOIN repo_oper RO on RO.repo_oper_ID = OB.repo_oper_ID
INNER JOIN User_On_Machine UON on OB.User_On_Machine_ID = UON.User_On_Machine_ID
INNER JOIN Repo_User RU on RU.Repo_User_ID = UON.Repo_User_ID
INNER JOIN Diag_DD DD on DD.Enterprise_DD_ID = OB.Ctl_Diag_ID
INNER JOIN Diag D on D.Diag_ID = DD.Diag_ID
INNER JOIN Object_Type OT on OT.Object_Type_ID = CO.Object_Type_ID
WHERE
OT.Name in ('DATA_DIC','DOMAIN', 'REFE_VAL','DEFAULT',
'RULE','USER_DATATYPE','ATT_TYPE','ATTACH')
AND DD.Flags in (0,1);