看一眼数据库负载 11.2.0.4 rac,居然是监控系统占用资源最多,首当其冲的就是以下语句
select count(*) from v$lock where type = 'tx' and request = 6;
很简单,检查当前有几个请求独占的锁
查询时间很长,其中出现了之前提到过的“合并连接卡迪森”
看看访问路径,过滤条件
-
sql_id b1na79hpa7k3p, child number 0
-
-------------------------------------
-
select count(*) from v$lock where type = 'tx' and request = 6;
-
-
plan hash value: 2384831130
-
-
---------------------------------------------------------------------------
-
| id | operation | name | rows | bytes | cost (%cpu)|
-
---------------------------------------------------------------------------
-
| 0 | select statement | | | | 1 (100)|
-
| 1 | sort aggregate | | 1 | 53 | |
-
|* 2 | hash join | | 1 | 53 | 0 (0)|
-
| 3 | merge join cartesian | | 1 | 41 | 0 (0)|
-
|* 4 | fixed table full | x$ksuse | 1 | 19 | 0 (0)|
-
| 5 | buffer sort | | 1 | 22 | 0 (0)|
-
|* 6 | fixed table full | x$ksqrs | 1 | 22 | 0 (0)|
-
| 7 | view | gv$_lock | 10 | 120 | 0 (0)|
-
| 8 | union-all | | | | |
-
|* 9 | filter | | | | |
-
| 10 | view | gv$_lock1 | 2 | 24 | 0 (0)|
-
| 11 | union-all | | | | |
-
|* 12 | fixed table full| x$kdnssf | 1 | 64 | 0 (0)|
-
|* 13 | fixed table full| x$ksqeq | 1 | 64 | 0 (0)|
-
|* 14 | fixed table full | x$ktadm | 1 | 64 | 0 (0)|
-
|* 15 | fixed table full | x$ktatrfil | 1 | 64 | 0 (0)|
-
|* 16 | fixed table full | x$ktatrfsl | 1 | 64 | 0 (0)|
-
|* 17 | fixed table full | x$ktatl | 1 | 64 | 0 (0)|
-
|* 18 | fixed table full | x$ktstusc | 1 | 64 | 0 (0)|
-
|* 19 | fixed table full | x$ktstuss | 1 | 64 | 0 (0)|
-
|* 20 | fixed table full | x$ktstusg | 1 | 64 | 0 (0)|
-
|* 21 | fixed table full | x$ktcxb | 1 | 64 | 0 (0)|
-
---------------------------------------------------------------------------
-
-
query block name / object alias (identified by operation id):
-
-------------------------------------------------------------
-
-
1 - sel$af73c875
-
4 - sel$af73c875 / s@sel$4
-
6 - sel$af73c875 / r@sel$4
-
7 - set$1 / gv$_lock@sel$5
-
8 - set$1
-
9 - sel$68b588a0
-
10 - set$2 / gv$_lock1@sel$7
-
11 - set$2
-
12 - sel$8 / x$kdnssf@sel$8
-
13 - sel$9 / x$ksqeq@sel$9
-
14 - sel$10 / x$ktadm@sel$10
-
15 - sel$11 / x$ktatrfil@sel$11
-
16 - sel$12 / x$ktatrfsl@sel$12
-
17 - sel$13 / x$ktatl@sel$13
-
18 - sel$14 / x$ktstusc@sel$14
-
19 - sel$15 / x$ktstuss@sel$15
-
20 - sel$16 / x$ktstusg@sel$16
-
21 - sel$17 / x$ktcxb@sel$17
-
-
outline data
-
-------------
-
-
/*
-
begin_outline_data
-
ignore_optim_embedded_hints
-
optimizer_features_enable('11.2.0.4')
-
db_version('11.2.0.4')
-
opt_param('_optim_peek_user_binds' 'false')
-
opt_param('_optimizer_extended_cursor_sharing' 'none')
-
opt_param('_gby_hash_aggregation_enabled' 'false')
-
opt_param('_optimizer_extended_cursor_sharing_rel' 'none')
-
opt_param('_optimizer_adaptive_cursor_sharing' 'false')
-
opt_param('_optimizer_use_feedback' 'false')
-
all_rows
-
outline_leaf(@"sel$8")
-
outline_leaf(@"sel$9")
-
outline_leaf(@"set$2")
-
outline_leaf(@"sel$68b588a0")
-
merge(@"sel$7")
-
outline_leaf(@"sel$10")
-
outline_leaf(@"sel$11")
-
outline_leaf(@"sel$12")
-
outline_leaf(@"sel$13")
-
outline_leaf(@"sel$14")
-
outline_leaf(@"sel$15")
-
outline_leaf(@"sel$16")
-
outline_leaf(@"sel$17")
-
outline_leaf(@"set$1")
-
outline_leaf(@"sel$af73c875")
-
merge(@"sel$71d7a081")
-
outline(@"sel$6")
-
outline(@"sel$7")
-
outline(@"sel$1")
-
outline(@"sel$71d7a081")
-
merge(@"sel$c8360722")
-
outline(@"sel$2")
-
outline(@"sel$c8360722")
-
merge(@"sel$7286615e")
-
outline(@"sel$3")
-
outline(@"sel$7286615e")
-
merge(@"sel$5")
-
outline(@"sel$4")
-
outline(@"sel$5")
-
full(@"sel$af73c875" "s"@"sel$4")
-
full(@"sel$af73c875" "r"@"sel$4")
-
no_access(@"sel$af73c875" "gv$_lock"@"sel$5")
-
leading(@"sel$af73c875" "s"@"sel$4" "r"@"sel$4" "gv$_lock"@"sel$5")
-
use_merge_cartesian(@"sel$af73c875" "r"@"sel$4")
-
use_hash(@"sel$af73c875" "gv$_lock"@"sel$5")
-
full(@"sel$17" "x$ktcxb"@"sel$17")
-
full(@"sel$16" "x$ktstusg"@"sel$16")
-
full(@"sel$15" "x$ktstuss"@"sel$15")
-
full(@"sel$14" "x$ktstusc"@"sel$14")
-
full(@"sel$13" "x$ktatl"@"sel$13")
-
full(@"sel$12" "x$ktatrfsl"@"sel$12")
-
full(@"sel$11" "x$ktatrfil"@"sel$11")
-
full(@"sel$10" "x$ktadm"@"sel$10")
-
no_access(@"sel$68b588a0" "gv$_lock1"@"sel$7")
-
full(@"sel$9" "x$ksqeq"@"sel$9")
-
full(@"sel$8" "x$kdnssf"@"sel$8")
-
end_outline_data
-
*/
-
-
predicate information (identified by operation id):
-
---------------------------------------------------
-
-
2 - access("saddr"="s"."addr" and
-
to_char(userenv('instance'))||rawtohex("raddr")=to_char("r"."inst_id")||
-
rawtohex("r"."addr"))
-
4 - filter("s"."inst_id"=userenv('instance'))
-
6 - filter("r"."ksqrsidt"='tx')
-
9 - filter(userenv('instance') is not null)
-
12 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
13 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
14 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
15 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
16 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
17 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
18 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
19 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
20 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0))
-
21 - filter(("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("ksspaflg",1)<>0))
-
-
column projection information (identified by operation id):
-
-----------------------------------------------------------
-
-
1 - (#keys=0) count(*)[22]
-
2 - (#keys=2)
-
3 - "s"."addr"[raw,8], "r"."addr"[raw,8], "r"."inst_id"[number,22]
-
4 - "s"."addr"[raw,8], "s"."inst_id"[number,22]
-
5 - (#keys=0) "r"."addr"[raw,8], "r"."inst_id"[number,22]
-
6 - "r"."addr"[raw,8], "r"."inst_id"[number,22],
-
"r"."ksqrsidt"[varchar2,2]
-
7 - "saddr"[raw,8], "raddr"[raw,8]
-
8 - strdef[8], strdef[8]
-
9 - "saddr"[raw,8], "raddr"[raw,8]
-
10 - "saddr"[raw,8], "raddr"[raw,8]
-
11 - strdef[8], strdef[8]
-
12 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
13 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
14 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
15 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
16 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
17 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
18 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
19 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
20 - "inst_id"[number,22], "kssobflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
-
21 - "inst_id"[number,22], "ksspaflg"[number,22], "ksqlkres"[raw,8],
-
"ksqlkmod"[number,22], "ksqlkreq"[number,22], "ksqlkses"[raw,8]
破解的办法就是加提示:ordered
说明:
如果从执行联接的sql语句中没有ordered提示,那么优化器将选择联接表的顺序。如果您对优化器不知道的每个表中所选行的数量有所了解,则可能需要使用ordered提示来指定联接顺序。这样的信息可以让您比优化器更好地选择内部和外部表。
当sql将大量表连接在一起(> 5)并且您知道应该始终按特定顺序连接表时,有序提示可能会极大地提高性能。
-
11:30:38 sys@orcl1> set autot trace exp stat
-
11:30:46 sys@orcl1> select /* rule */ count(*) from v$lock where type = 'tx' and request = 6;
-
elapsed: 00:00:00.24
-
-
execution plan
-
----------------------------------------------------------
-
plan hash value: 2026431807
-
-
-------------------------------------------------
-
| id | operation | name |
-
-------------------------------------------------
-
| 0 | select statement | |
-
| 1 | sort aggregate | |
-
| 2 | merge join | |
-
| 3 | sort join | |
-
| 4 | merge join | |
-
| 5 | sort join | |
-
|* 6 | fixed table full | x$ksqrs |
-
|* 7 | sort join | |
-
| 8 | view | gv$_lock |
-
| 9 | union-all | |
-
|* 10 | filter | |
-
| 11 | view | gv$_lock1 |
-
| 12 | union-all | |
-
|* 13 | fixed table full| x$kdnssf |
-
|* 14 | fixed table full| x$ksqeq |
-
|* 15 | fixed table full | x$ktadm |
-
|* 16 | fixed table full | x$ktatrfil |
-
|* 17 | fixed table full | x$ktatrfsl |
-
|* 18 | fixed table full | x$ktatl |
-
|* 19 | fixed table full | x$ktstusc |
-
|* 20 | fixed table full | x$ktstuss |
-
|* 21 | fixed table full | x$ktstusg |
-
|* 22 | fixed table full | x$ktcxb |
-
|* 23 | sort join | |
-
|* 24 | fixed table full | x$ksuse |
-
-------------------------------------------------
-
-
predicate information (identified by operation id):
-
---------------------------------------------------
-
-
6 - filter("r"."ksqrsidt"='tx')
-
7 - access(to_char(userenv('instance'))||rawtohex("raddr")=to_char("r
-
"."inst_id")||rawtohex("r"."addr"))
-
filter(to_char(userenv('instance'))||rawtohex("raddr")=to_char("r
-
"."inst_id")||rawtohex("r"."addr"))
-
10 - filter(userenv('instance')=userenv('instance'))
-
13 - filter("ksqlkreq"=6 and "inst_id"=userenv('instance') and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
14 - filter("ksqlkreq"=6 and "inst_id"=userenv('instance') and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
15 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
16 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
17 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
18 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
19 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
20 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
21 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("kssobflg",1)<>0)
-
22 - filter("inst_id"=userenv('instance') and "ksqlkreq"=6 and
-
("ksqlkmod"<>0 or "ksqlkreq"<>0) and bitand("ksspaflg",1)<>0)
-
23 - access("saddr"="s"."addr")
-
filter("saddr"="s"."addr")
-
24 - filter("s"."inst_id"=userenv('instance'))
-
-
note
-
-----
-
- rule based optimizer used (consider using cbo)
-
-
-
statistics
-
----------------------------------------------------------
-
0 recursive calls
-
1 db block gets
-
0 consistent gets
-
0 physical reads
-
0 redo size
-
596 bytes sent via sql*net to client
-
520 bytes received via sql*net from client
-
2 sql*net roundtrips to/from client
-
3 sorts (memory)
-
0 sorts (disk)
-
1 rows processed
-
-
11:30:48 sys@orcl1>
-
11:31:24 sys@orcl1>
-
11:31:25 sys@orcl1> select /* ordered */count(*) from v$lock where type = 'tx' and request = 6;
-
elapsed: 00:00:00.21
-
-
execution plan
-
----------------------------------------------------------
-
plan hash value: 3730480328
-
-
---------------------------------------------------------------------------------------
-
| id | operation | name | rows | bytes | cost (%cpu)| time |
-
---------------------------------------------------------------------------------------
-
| 0 | select statement | | 1 | 53 | 1 (100)| 00:00:01 |
-
| 1 | sort aggregate | | 1 | 53 | | |
-
|* 2 | hash join | | 1 | 53 | 1 (100)| 00:00:01 |
-
|* 3 | hash join | | 1 | 31 | 0 (0)| 00:00:01 |
-
| 4 | view | gv$_lock | 10 | 120 | 0 (0)| 00:00:01 |
-
| 5 | union-all | | | | | |
-
|* 6 | filter | | | | | |
-
| 7 | view | gv$_lock1 | 2 | 24 | 0 (0)| 00:00:01 |
-
| 8 | union-all | | | | | |
-
|* 9 | fixed table full| x$kdnssf | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 10 | fixed table full| x$ksqeq | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 11 | fixed table full | x$ktadm | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 12 | fixed table full | x$ktatrfil | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 13 | fixed table full | x$ktatrfsl | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 14 | fixed table full | x$ktatl | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 15 | fixed table full | x$ktstusc | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 16 | fixed table full | x$ktstuss | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 17 | fixed table full | x$ktstusg | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 18 | fixed table full | x$ktcxb | 1 | 64 | 0 (0)| 00:00:01 |
-
|* 19 | fixed table full | x$ksuse | 1 | 19 | 0 (0)| 00:00:01 |
-
|* 20 | fixed table full | x$ksqrs | 1 | 22 | 0 (0)| 00:00:01 |
-
---------------------------------------------------------------------------------------
-
-
predicate information (identified by operation id):
-
---------------------------------------------------
-
-
2 - access(to_char(userenv('instance'))||rawtohex("raddr")=to_char("r"."inst
-
_id")||rawtohex("r"."addr"))
-
3 - access("saddr"="s"."addr")
-
6 - filter(userenv('instance') is not null)
-
9 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
10 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
11 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
12 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
13 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
14 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
15 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
16 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
17 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("kssobflg",1)<>0)
-
18 - filter("ksqlkreq"=6 and ("ksqlkmod"<>0 or "ksqlkreq"<>0) and
-
"inst_id"=userenv('instance') and bitand("ksspaflg",1)<>0)
-
19 - filter("s"."inst_id"=userenv('instance'))
-
20 - filter("r"."ksqrsidt"='tx')
-
-
-
statistics
-
----------------------------------------------------------
-
1 recursive calls
-
1 db block gets
-
0 consistent gets
-
0 physical reads
-
0 redo size
-
596 bytes sent via sql*net to client
-
520 bytes received via sql*net from client
-
2 sql*net roundtrips to/from client
-
0 sorts (memory)
-
0 sorts (disk)
-
1 rows processed
从300多秒降低到 0.1秒
但是监控系统是
“成熟”商业软件,不能改写语句,怎么办呢?
设置触发器?还是设置某个神奇的隐含参数?
以下方法有的情况下有效:
-
begin
-
dbms_stats.gather_table_stats('sys','x$ksuse',method_opt=>'for all columns size 1');
-
dbms_stats.gather_table_stats('sys','x$ksqrs',method_opt=>'for all columns size 1');
-
end;
-
/
对于视图内的合并连接卡迪森,之前的方法
alter session set "_optimizer_mjc_enabled"=flase;不起作用
阅读(1350) | 评论(0) | 转发(0) |