[20210202]計算標量子查詢快取數量2.txt
[20210202]計算標量子查詢快取數量2.txt
--//昨天做了計算標量子查詢快取數量的測試,實際上還有1個簡單的方法測試,就是看執行計劃,
--//唯一的方式就是開啟statistics_level = all,或者設定提示gather_plan_statistics.
--//透過例子說明:
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 t1 tablespace users
as
with generator as (
select --+ materialize
rownum id
from all_objects
where rownum <= 3000
)
select
/*+ ordered use_nl(v2) */
rownum n1,
lpad(rownum,16,'0') v16,
lpad(rownum,32,'0') v32
from
generator v1,
generator v2
where
rownum <= 16384
;
insert /*+ append */ into t1 select * from t1;
commit;
begin
dbms_stats.gather_table_stats(
user,
't1',
cascade => true,
estimate_percent => null,
method_opt => 'for all columns size 1'
);
end;
/
create or replace package pack1 as
g_ct number(10) := 0;
function f_n(i in number) return number;
function f_v(i in varchar2) return varchar2;
function f_vn(i in varchar2) return number;
end;
/
create or replace package body pack1 as
function f_n(i in number) return number
is
begin
dbms_application_info.set_client_info(userenv('client_info')+1 );
return i;
end;
function f_v(i in varchar2) return varchar2
is
begin
dbms_application_info.set_client_info(userenv('client_info')+1 );
return i;
end
;
function f_vn(i in varchar2) return number
is
begin
dbms_application_info.set_client_info(userenv('client_info')+1 );
return length(i);
end
;
end;
/
3.測試:
SCOTT@book> select count(distinct x) from ( select /*+ gather_plan_statistics no_merge */ (select pack1.f_n(n1) from dual) x from t1) ;
COUNT(DISTINCTX)
----------------
16384
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID cvqr6u5a0yq15, child number 0
-------------------------------------
select count(distinct x) from ( select /*+ gather_plan_statistics
no_merge */ (select pack1.f_n(n1) from dual) x from t1)
Plan hash value: 2761048924
-------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 81 (100)| | 1 |00:00:00.31 | 275 | | | |
| 1 | FAST DUAL | | 31744 | 1 | | 2 (0)| 00:00:01 | 31744 |00:00:00.01 | 0 | | | |
| 2 | SORT AGGREGATE | | 1 | 1 | 13 | | | 1 |00:00:00.31 | 275 | | | |
| 3 | VIEW | VW_DAG_0 | 1 | 32768 | 416K| 81 (3)| 00:00:01 | 16384 |00:00:00.31 | 275 | | | |
| 4 | HASH GROUP BY | | 1 | 32768 | 416K| 81 (3)| 00:00:01 | 16384 |00:00:00.31 | 275 | 3072K| 2891K| 1843K (0)|
| 5 | VIEW | | 1 | 32768 | 416K| 79 (0)| 00:00:01 | 32768 |00:00:00.29 | 275 | | | |
| 6 | TABLE ACCESS FULL| T1 | 1 | 32768 | 160K| 79 (0)| 00:00:01 | 32768 |00:00:00.01 | 275 | | | |
-------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$3 / DUAL@SEL$3
2 - SEL$C33C846D
3 - SEL$5771D262 / VW_DAG_0@SEL$C33C846D
4 - SEL$5771D262
5 - SEL$2 / from$_subquery$_001@SEL$1
6 - SEL$2 / T1@SEL$2
29 rows selected.
--//id=2,starts=31744,說明呼叫函式次數是31744.
--//16384*2-31744 = 1024
--//hash table size=1024.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2755293/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20210201]19c計算標量子查詢快取數量.txt快取
- 標量子查詢
- 標量子查詢(二)
- 標量子查詢(一)
- 20180601]函式與標量子查詢2.txt函式
- 用WITH…AS改寫標量子查詢
- 都是標量子查詢惹的禍
- MySQL查詢快取引數詳解MySql快取
- MYSQL學習筆記25: 多表查詢(子查詢)[標量子查詢,列子查詢]MySql筆記
- MYSQL count標量子查詢改left joinMySql
- 用LEFT JOIN優化標量子查詢優化
- 方法快取與查詢快取
- Oracle常用抓取SQL-標量子查詢等OracleSQL
- 帶彙總的標量子查詢改寫
- 標量子查詢優化(用group by 代替distinct)優化
- 藉助查詢引數來利用 Laravel 快取Laravel快取
- mysql 標量子查詢和現金盤程式製作非法子查詢MySql
- redis 快取 singlefly 查詢Redis快取
- IBM量子計算機亮相 距離標準量子計算機相距甚遠IBM計算機
- 影響Oracle標量子查詢效能的三個因素Oracle
- mysql查詢快取簡單使用MySql快取
- mysql的查詢快取說明MySql快取
- Mysql 查詢快取 query_cacheMySql快取
- hibernate的查詢快取薦快取
- 快取遞迴計算快取遞迴
- 關於快取與資料查詢次數的問題快取
- 【TUNE_ORACLE】列出有標量子查詢的SQL參考OracleSQL
- 效能為王:SQL標量子查詢的優化案例分析SQL優化
- [20150709]慎用標量子查詢.txt
- day03-商家查詢快取02快取
- hibernate的查詢快取和二級快取的配合使用快取
- in list查詢計算cost
- [20200325]慎用標量子查詢.txt
- GreatSQL 最佳化技巧:將 MINUS 改寫為標量子查詢SQL
- 微服務複雜查詢之快取策略微服務快取
- day02-2-商鋪查詢快取快取
- 老司機使用 Redis 快取複雜查詢Redis快取
- 查詢快取(query_cache)的影響快取