[20190423]簡單測試user和SYS_CONTEXT ('USERENV','CURRENT_USER').txt
[20190423]簡單測試user和SYS_CONTEXT ('USERENV','CURRENT_USER').txt
1.環境:
SCOTT@book> @ ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2.建立測試指令碼:
--//create table job_times (sid number, time_ela number,method varchar2(20));
$ cat u1.txt
set verify off
host sleep $(echo &&3/50 | bc -l )
variable vmethod varchar2(20);
exec :vmethod := '&&2';
insert into job_times values ( sys_context ('userenv', 'sid') ,dbms_utility.get_time ,:vmethod) ;
commit ;
declare
v_id number;
v_d date;
v varchar2(30);
begin
for i in 1 .. &&1 loop
v := USER;
--//v := sys_context('USERENV', 'CURRENT_USER');
--//SELECT USER INTO v FROM dual;
end loop;
end ;
/
update job_times set time_ela = dbms_utility.get_time - time_ela where sid=sys_context ('userenv', 'sid') and method=:vmethod;
commit;
quit
--//注:最好不要寫成 SELECT USER INTO v FROM dual;之類的語句!!特別是使用sys_context方式,我沒有測試.
3.測試:
$ sqlplus -s -l scott/book @u1.txt 1e6 user 0 >/dev/null
$ seq 50 | xargs -I{} -P 50 sqlplus -s -l scott/book @u1.txt 1e6 user50 {} >/dev/null
--//修改指令碼,重複測試:
$ sqlplus -s -l scott/book @u1.txt 1e6 sys_context 0 >/dev/null
$ seq 50 | xargs -I{} -P 50 sqlplus -s -l scott/book @u1.txt 1e6 sys_context50 {} >/dev/null
--//修改指令碼,重複測試,使用SELECT USER INTO v FROM dual;
$ sqlplus -s -l scott/book @u1.txt 1e6 suser 0 >/dev/null
4.結果:
SCOTT@book> Select method,count(*),round(avg(TIME_ELA),0),sum(TIME_ELA) from job_times
where method in ('user','user50','sys_context','sys_context50','suser','suser50') group by method order by 3 ;
METHOD COUNT(*) ROUND(AVG(TIME_ELA),0) SUM(TIME_ELA)
-------------------- ---------- ---------------------- -------------
sys_context 1 191 191
sys_context50 50 660 32977
suser 1 1610 1610
user 1 1755 1755
suser50 50 6296 314790
user50 50 6701 335063
6 rows selected.
--//可以發現透過sys_context取user最快,實際上具體應用很少人使用sys_context取user.
--//問題在與user函式,實際上呼叫SELECT USER FROM SYS.DUAL,如果查詢共享池就可以發現問題.
SCOTT@book> select * from (select sql_id,sql_text,executions from v$sqlarea order by 3 desc) where rownum<=3;
SQL_ID SQL_TEXT EXECUTIONS
------------- ------------------------------------------------------------ ----------
1v717nvrhgbn9 SELECT USER FROM SYS.DUAL 50198062
d6r1mk4p3j2uf SELECT USER FROM DUAL 34955112
96g93hntrzjtr select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, 51568
timestamp#, sample_size, minimum, maximum, distcnt, lowval,
hival, density, col#, spare1, spare2, avgcln from hist_head
$ where obj#=:1 and intcol#=:2
--//執行次數異常之高.實際上使用user函式,在SYS.STANDARD 包中
SCOTT@book> @ desc_proc sys STANDARD user
INPUT OWNER PACKAGE_NAME OBJECT_NAME
sample : @desc_proc sys dbms_stats gather_%_stats
OWNER PACKAGE_NAME OBJECT_NAME SEQUENCE ARGUMENT_NAME DATA_TYPE IN_OUT DEFAULTED
---------- -------------------- ------------------------------ ---------- -------------------- -------------------- --------- ----------
SYS STANDARD USER 1 VARCHAR2 OUT N
SCOTT@book> alter system flush shared_pool ;
System altered.
SCOTT@book> alter system flush shared_pool ;
System altered.
$ sqlplus -s -l scott/book @u1.txt 1e5 Suser 0 >/dev/null
SCOTT@book> select * from (select sql_id,sql_text,executions from v$sqlarea order by 3 desc) where rownum<=2;
SQL_ID SQL_TEXT EXECUTIONS
------------- ------------------------------------------------------------ ----------
d6r1mk4p3j2uf SELECT USER FROM DUAL 100000
96g93hntrzjtr select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, 52549
timestamp#, sample_size, minimum, maximum, distcnt, lowval,
hival, density, col#, spare1, spare2, avgcln from hist_head
$ where obj#=:1 and intcol#=:2
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2642206/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20211112]SYS_CONTEXT ('USERENV','DBID').txtContext
- [20190423]簡單測試latch nowilling等待模式.txt模式
- [20190423]oradebug peek測試指令碼.txt指令碼
- AUTHID CURRENT_USER的注意點
- [20190301]簡單測試linux fsfreeze命令.txtLinux
- @1-MYSQL當前使用者user()與current_user()MySql
- [20190211]簡單測試埠是否開啟.txt
- [20190211]簡單測試埠是否開啟(補充).txt
- InnoSetup簡單教程一,安裝使用和簡單測試
- [20190423]那個更快的疑問3.txt
- 簡單的 ping 測試
- mysql簡單效能測試MySql
- Oracle logmnr簡單測試Oracle
- 建立簡單的表測試
- Jmeter效能測試簡單使用JMeter
- try的簡單效能測試
- 【PG效能測試】pgbench效能測試工具簡單使用
- [20181116]SYS_CONTEXT函式的使用(12c).txtContext函式
- stepci:讓 API 測試和監控變得簡單
- 簡單談一下我對持續測試下的測試左移、迭代測試和測試右移的理解吧
- Hibernate對注入的簡單測試
- 讓 API 測試變的簡單API
- 簡單的神經網路測試神經網路
- C++ 巢狀類簡單測試C++巢狀
- Python容器相關簡單效能測試Python
- iOS 單元測試和 UI 測試快速入門iOSUI
- .Net單元測試xUnit和整合測試指南(1)
- 如何寫好測試用例以及go單元測試工具testify簡單介紹Go
- 一個簡單的介面測試框架 demo框架
- 移動效能測試---工具PerfDog簡單使用
- WPF 分隔欄分割窗體簡單測試
- [20210723]Database link and user defined datatypes.txtDatabase
- 測試 之Java單元測試、Android單元測試JavaAndroid
- 記一次簡單的vue元件單元測試Vue元件
- 記一次想簡單化的單元測試
- 換種思路寫Mock,讓單元測試更簡單Mock
- 4大軟體測試策略的特點和區別(單元測試、整合測試、確認測試和系統測試)
- [20181226]簡單探究cluster table.txt