对于自适应游标共享的一点补充
关于自适应游标共享请参加:http://blog.csdn.net/yidian815/article/details/17959907 对自适应游标共享的理解,本人认为难点在于对BIND_SENSITIVE 和BIND_AWARE的认识。再来复习一下: bind_sensitive:oracle认为该语句可能会因为绑定变量的不同而需要采取
关于自适应游标共享请参加:http://blog.csdn.net/yidian815/article/details/17959907
对自适应游标共享的理解,本人认为难点在于对BIND_SENSITIVE 和BIND_AWARE的认识。再来复习一下:
bind_sensitive:oracle认为该语句可能会因为绑定变量的不同而需要采取不同的执行计划,因此需要监控该语句的执行并依据执行结果做出判断。
bind_aware:oracle通过监视已经认定该语句需要针对不同的绑定变量取值采取不同的执行计划。
现在就好出现如下的问题:
oracle认定什么样式的sql语句是bind_sensitve?
对于bind_aware的语句,oracle是如何根据不同的变量取值来选择执行计划的?
在回答这些问题之前,先来看一下测试环境
SQL> desc t2; 名称 是否为空? 类型 ----------------------------------------------------- -------- ------------------------------------ ID NUMBER RTYPE VARCHAR2(20) SEL NUMBER SQL> select column_name,histogram from dba_tab_cols where table_name='T2' AND OWNER='EASY1'; COLUMN_NAME HISTOGRAM ------------------------------ --------------- ID NONE RTYPE FREQUENCY SEL NONE SQL> select rtype,count(1),min(sel),max(sel) from t2 group by rtype order by 3; RTYPE COUNT(1) MIN(SEL) MAX(SEL) -------------------- ---------- ---------- ---------- 1 1 7.6295E-06 7.6295E-06 2 2 .000015259 .000015259 3 4 .000030518 .000030518 4 8 .000061036 .000061036 5 16 .000122072 .000122072 6 32 .000244144 .000244144 7 64 .000488289 .000488289 8 128 .000976577 .000976577 9 256 .001953155 .001953155 10 512 .00390631 .00390631 11 1024 .007812619 .007812619 RTYPE COUNT(1) MIN(SEL) MAX(SEL) -------------------- ---------- ---------- ---------- 12 2048 .015625238 .015625238 13 4096 .031250477 .031250477 14 8192 .062500954 .062500954 15 16384 .125001907 .125001907 16 32768 .250003815 .250003815 17 65536 .50000763 .50000763
首先我们猜测第一个问题的答案。
因为bind_sensitive是针对绑定变量的不同取值而论的,因此我们认为只有具有绑定变量的语句才可能是bind_sensitive的。
SQL> select sum(id) from t2 where rtype=16; SUM(ID) ---------- 1610596352 SQL> select sum(id) from t2 where rtype=1; SUM(ID) ---------- 1
SQL> l 1* select sql_text,is_bind_sensitive,is_bind_aware from v$sql where sql_text like 'select sum(id) from t2%' SQL> / SQL_TEXT I I ------------------------------------------------------------ - - select sum(id) from t2 where rtype=1 N N select sum(id) from t2 where rtype=16 N N
SQL> var v varchar2(100) SQL> select sum(id) from t2 where rtype=:v; SUM(ID) ---------- SQL> select sum(id) from t2 where id=:v; SUM(ID) ----------
SQL> l 1* select sql_text,is_bind_sensitive,is_bind_aware from v$sql where sql_text like 'select sum(id) from t2%' SQL> / SQL_TEXT I I ------------------------------------------------------------ - - select sum(id) from t2 where rtype=1 N N select sum(id) from t2 where id=:v N N select sum(id) from t2 where rtype=:v Y N select sum(id) from t2 where rtype=16 N N
The optimizer has peeked at the bind values to generate selectivity estimates.
A histogram exists on the column containing the bind value.
- 下面一段文字来自网络,尽快参考
Q: What triggers a cursor to be marked "bind sensitive"?
A: Our goal is to consider many types of predicates where the selectivity can change when the bind value changes. In this first version of the feature, we only handle equality predicates where a histogram exists on the column and range predicates (with or without histogram). We do not currently consider LIKE predicates, but it is on the top of our list for future work.
下面我们来看看bind_aware的语句是如何工作的,为了简化操作,我们直接使用BIND_AWARE hint。关于该hint的使用,有如下解释:
From 11.1.0.7 onward it is possible to skip the monitoring that is required to detect bind-sensitive queries by using the BIND_AWARE hint. In the following example, the presence of the hint tells the optimizer that we believe the query is bind-sensitive, so it should use bind-aware cursor sharing from the first execution.
SELECT /*+ BIND_AWARE */ MAX(id) FROM acs_test_tab WHERE record_type = :l_record_type;
Copy after loginThe hint will only work if the query uses bind variables in WHERE clause predicates referencing columns with histograms.
There is also a NO_BIND_AWARE hint that tells the optimizer to ignore bind-sensitive queries, effectively hiding the query from the adaptive cursor sharing functionality.
Bind-aware cursor sharing has a small overhead associated with it, which is why Oracle use the "adaptive" approach to identifying queries that would benefit from bind-aware cursor sharing. Adding the hint to queries that will not benefit from it is a waste.
在进一步实验之前,创建表t1
SQL> create table t1 as select * from t2 where 1 =2; 表已创建。 SQL> alter table t1 modify rtype number; 表已更改。 SQL> insert into t1 select * from t2; 已创建 131071 行。 SQL> commit; 提交完成。 SQL> create index i1 on t1(rtype); 索引已创建。
Copy after loginSQL> exec dbms_stats.gather_table_stats(user,'t1',cascade=>true,estimate_percent=>null,method_opt=>'for all columns size auto,for columns rtype size 40'); PL/SQL 过程已成功完成。 SQL> select table_name,column_name,endpoint_number,to_char(endpoint_value),endpoint_actual_value from user_histograms where table_name='T1'; TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER TO_CHAR(ENDPOINT_VALUE) ENDPOINT_ACTUAL_VALUE ---------- -------------------- --------------- ---------------------------------------- ------------------------------ T1 RTYPE 1 1 T1 RTYPE 3 2 T1 RTYPE 7 3 T1 RTYPE 15 4 T1 RTYPE 31 5 T1 RTYPE 63 6 T1 RTYPE 127 7 T1 RTYPE 255 8 T1 RTYPE 511 9 T1 RTYPE 1023 10 T1 RTYPE 2047 11 TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER TO_CHAR(ENDPOINT_VALUE) ENDPOINT_ACTUAL_VALUE ---------- -------------------- --------------- ---------------------------------------- ------------------------------ T1 RTYPE 4095 12 T1 RTYPE 8191 13 T1 RTYPE 16383 14 T1 RTYPE 131071 17 T1 ID 0 1 T1 SEL 0 .00000762951094834821 T1 ID 1 131071 T1 SEL 1 .87501335164416 已选择19行。
Copy after login对bind_aware的实验过程如下:SQL> select rtype,count(1),min(sel),max(sel) from t1 group by rtype order by 3; RTYPE COUNT(1) MIN(SEL) MAX(SEL) ---------- ---------- ---------- ---------- 1 1 7.6295E-06 7.6295E-06 2 2 .000015259 .000015259 3 4 .000030518 .000030518 4 8 .000061036 .000061036 5 16 .000122072 .000122072 6 32 .000244144 .000244144 7 64 .000488289 .000488289 8 128 .000976577 .000976577 9 256 .001953155 .001953155 10 512 .00390631 .00390631 11 1024 .007812619 .007812619 RTYPE COUNT(1) MIN(SEL) MAX(SEL) ---------- ---------- ---------- ---------- 12 2048 .015625238 .015625238 13 4096 .031250477 .031250477 14 8192 .062500954 .062500954 17 114688 .875013352 .875013352
Copy after login由此可见,计算绑定变量的谓词选择性在bind_aware中扮演者重要角色SQL> alter system flush shared_pool; 系统已更改。 SQL> var vr number; SQL> exec :vr := 1 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 1 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y --由于使用了bind_aware HINT SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 --根据直方图计算出rtype=1的选择性 SQL> exec :vr := 2 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 5 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N --逐步淘汰出内存 select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 --由于rtype=2的选择性不再0.00007~0.00008之间,所以生成新的子游标,由于新游标和旧游标的执行计划相同,所以进行合并,子游标0被设置为非共享,逐步淘汰出内存 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 SQL> exec :vr := 1 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 1 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y Y --使用新的子游标,不再使用0号子游标 SQL> @sho_sel SP2-0310: 无法打开文件 "sho_sel.sql" SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 SQL> exec :vr := 3 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 22 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 2 =VR 0 0.000007 0.000034 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 SQL> exec :vr := 1 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 1 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y Y SQL> exec :vr := 8 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 24512 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 3 =VR 0 0.000007 0.001074 00000000DD40C0E0 2679189014 082txyqgv2bhq 2 =VR 0 0.000007 0.000034 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 SQL> exec :vr := 14 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 100659200 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 4 =VR 0 0.000007 0.068751 00000000DD40C0E0 2679189014 082txyqgv2bhq 3 =VR 0 0.000007 0.001074 00000000DD40C0E0 2679189014 082txyqgv2bhq 2 =VR 0 0.000007 0.000034 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 SQL> exec :vr := 15 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y 已选择6行。 SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 5 =VR 0 0.000003 0.068751 --由于15不存在,所以选择性向下扩充 00000000DD40C0E0 2679189014 082txyqgv2bhq 4 =VR 0 0.000007 0.068751 00000000DD40C0E0 2679189014 082txyqgv2bhq 3 =VR 0 0.000007 0.001074 00000000DD40C0E0 2679189014 082txyqgv2bhq 2 =VR 0 0.000007 0.000034 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 已选择6行。 SQL> exec :vr := 17 PL/SQL 过程已成功完成。 SQL> select /*+ bind_aware */ sum(id) from t1 where rtype = :vr; SUM(ID) ---------- 8455659520 SQL> @show_sql SQL_TEXT EXECUTIONS I I I ------------------------------------------------------------ ---------- - - - select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 2 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y N select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y select /*+ bind_aware */ sum(id) from t1 where rtype = :vr 1 Y Y Y 已选择7行。 SQL> @show_sel ADDRESS HASH_VALUE SQL_ID CHILD_NUMBER PREDICATE RANGE_ID LOW HIGH ---------------- ---------- ------------- ------------ ---------------------------------------- ---------- ---------- ---------- 00000000DD40C0E0 2679189014 082txyqgv2bhq 6 =VR 0 0.787503 0.962503 --新的子游标的执行计划于旧子游标不同,所以均保留 00000000DD40C0E0 2679189014 082txyqgv2bhq 5 =VR 0 0.000003 0.068751 00000000DD40C0E0 2679189014 082txyqgv2bhq 4 =VR 0 0.000007 0.068751 00000000DD40C0E0 2679189014 082txyqgv2bhq 3 =VR 0 0.000007 0.001074 00000000DD40C0E0 2679189014 082txyqgv2bhq 2 =VR 0 0.000007 0.000034 00000000DD40C0E0 2679189014 082txyqgv2bhq 1 =VR 0 0.000007 0.000017 00000000DD40C0E0 2679189014 082txyqgv2bhq 0 =VR 0 0.000007 0.000008 已选择7行。
Copy after login

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

More and more enterprises choose to use exclusive enterprise WeChat, which not only facilitates communication between enterprises and customers and partners, but also greatly improves work efficiency. Enterprise WeChat has rich functions, among which the screen sharing function is very popular. During the meeting, by sharing the screen, participants can display content more intuitively and collaborate more efficiently. So how to share your screen efficiently in WeChat Enterprise? For users who don’t know yet, this tutorial guide will give you a detailed introduction. I hope it can help you! How to share screen on WeChat Enterprise? 1. In the blue area on the left side of the main interface of Enterprise WeChat, you can see a list of functions. We find the "Conference" icon. After clicking to enter, three conference modes will appear.

Users can share the wallpapers they obtain with friends when using WallpaperEngine. Many users do not know how to share WallpaperEngine with friends. They can save their favorite wallpapers locally and then share them with friends through social software. How to share wallpaperengine with friends Answer: Save it locally and share it with friends. 1. It is recommended that you save your favorite wallpapers locally and then share them with friends through social software. 2. You can also upload it to the computer through a folder, and then click Share using the creative workshop function on the computer. 3. Use Wallpaperengine on the computer, open the options bar of the creative workshop and find

Quick Share can save Samsung users a lot of time transferring files between devices. But Samsung Galaxy users have complained about facing issues with the Quick Share feature on their phones. Typically, visibility issues in quick sharing cause this issue. So, this is the only guide you need to troubleshoot the Quick Share feature on your Galaxy device. Fix 1 – Change Quick Share Visibility Settings Toggle the Quick Share visibility setting on your phone. Quick Share might be set to the wrong settings, causing this issue. Step 1 – First, swipe up once to open the app drawer. Step 2 – Once there, open Settings. Step 3 – Go to the Settings page and open the Connected Devices tab. Step 4 – Turn on the “Quick Share” feature. Step 5

In daily life and work, we often need to share files and folders between different devices. Windows 11 system provides convenient built-in folder sharing functions, allowing us to easily and safely share the content we need with others within the same network while protecting the privacy of personal files. This feature makes file sharing simple and efficient without worrying about leaking private information. Through the folder sharing function of Windows 11 system, we can cooperate, communicate and collaborate more conveniently, improving work efficiency and life convenience. In order to successfully configure a shared folder, we first need to meet the following conditions: All devices (participating in sharing) are connected to the same network. Enable Network Discovery and configure sharing. Know the target device

Who can view your contact photos and posters on iPhone? Apple offers options for personalizing how you appear on someone's iPhone when they call or send a message. The options include Memoji, simple text, or a custom photo with effects as your contact photo and display image. You are free to change these selections at any time and switch between profiles on the contact card. Additionally, Apple is giving you the ability to control who can view and access photos or display images of your choice on iOS17. You can decide to share these with individuals saved in your contact list, or you can set your iPhone to prompt you every time you interact with a contact. If you wish, you can also disable the name permanently

With the launch of the new Apple iPhone15 series mobile phones and the launch of the latest iOS17 mobile operating system, a wealth of new features, adjustments and enhancements have been brought to Apple devices. Users may be wondering how to use the new NameDrop feature on iPhone and iOS17. This guide will provide a brief overview of how to share your contact information quickly and efficiently using the new NameDrop system available on iOS17. NameDrop is a feature that allows iPhone users to quickly share their contact information with others. It's a convenient tool for social events, business meetings or social gatherings where you need to exchange contact details with new friends. However, it's important to note that NameDrop only works for sending new contacts

With the development of the digital era, shared printers have become an indispensable part of the modern office environment. However, sometimes we may encounter the problem that the shared printer cannot be connected to the printer, which will not only affect work efficiency, but also cause a series of troubles. This article aims to explore the reasons and solutions for why a shared printer cannot connect to the printer. There are many reasons why a shared printer cannot connect to the printer, the most common of which is network issues. If the network connection between the shared printer and the printer is unstable or interrupted, normal operation will not be possible.

How to solve the problem that printer cannot be shared after Win10 system is updated? Many friends reported that after updating to win10 system, they could not share the printer. What happened? The inability to share the printer is a troublesome thing for some friends. If you don’t know how to solve it , the editor below has sorted out the solutions to the problem of being unable to share printers after the Win10 system is updated. If you are interested, take a look below! Solution to the inability to share printers after Win10 system update 1. First, press the "win+r" keys to open the run window, enter the "control" command to open the control panel interface, as shown in the figure; 2. Then, in the open control panel interface , find and open the "Uninstall a program" option, and then click on the left
