Hello all fellow Oracle geeks and technology enthusiasts! Long time no see ;-)
In the hacking session about Oracle full table scans and direct path reads I explained how the direct path read decision is not done by the optimizer, but instead during every execution, separately for every single segment (partition) scanned in the query. I also explained how the _small_table_threshold parameter and the X$KCBOQH.NUM_BUF(which keeps track of how many buffers of any segment are currently cached) are used for determining whether to scan using direct path reads or not.
If you don’t know what the _small_table_threshold parameter is and how it relates to the direct path read decision, then read this post by Alex Fatkulin first.
In addition to the abovementioned values, Oracle needs to know how many blocks there are to scan (under the HWM) in a segment. This was traditionally done by reading in the segment header block first (using a regular buffered single block read – “db file sequential read”).
Starting from Oracle 11.2.0.2, things have changed a little. Instead of making the direct path read decision based on the actual segment block count extracted from the segment header, Oracle actually takes this number from TAB$.BLKCNT (dba_tables.blocks) or TABPART$.BLKCNT, IND$.LEAFCNT etc.
There’s a new parameter _direct_read_decision_statistics_driven which controls this:
SQL> @pd direct_read_decision Show all parameters and session values from x$ksppi/x$ksppcv... NAME VALUE DESCRIPTION -------------------------------------------------- -------- ---------------------------------------------------------- _direct_read_decision_statistics_driven TRUE enable direct read decision based on optimizer statistics
- When this parameter is FALSE, the direct path read decision is done based on the segment header’s block count (actual block count).
- When TRUE (default in 11.2.0.2+), the direct path read decision is done based on the block count stored in one of the base tables (TAB$, IND$) – the optimizer statistics
Note that even though the block counts are taken from the optimizer statistics in data dictionary, it’s not the optimizer who does the direct path read decision in the traditional sense (it’s not a cost-based decision).
Here’s an example from my test database:
SQL> CREATE TABLE t AS SELECT * FROM dba_source; Table created. SQL> @gts t Gather Table Statistics for table t... PL/SQL procedure successfully completed. SQL> SQL> SELECT blocks FROM user_tables WHERE table_name = 'T'; BLOCKS ---------- 10704 SQL>
The table uses 10704 blocks (up HWM).
SQL> SELECT name,block_size,buffers FROM v$buffer_pool; NAME BLOCK_SIZE BUFFERS -------------------- ---------- ---------- DEFAULT 8192 9424
The table (10704 blocks) is bigger than the entire buffer cache (9424 buffers). And this is way bigger than the _small_table_threshold value of 168 in my instance (watch the full table scans and direct path reads) hacking session for more about this parameter.
So whenever I run a SELECT COUNT(*) FROM t, I see direct path reads show up:
SQL> @snapper ash,stats=sw,sinclude=table.scan|gets 5 1 99 Sampling SID 99 with interval 5 seconds, taking 1 snapshots... -- Session Snapper v3.54 by Tanel Poder ( http://blog.tanelpoder.com ) ---------------------------------------------------------------------------------------------------------------------------------------- SID, USERNAME , TYPE, STATISTIC , DELTA, HDELTA/SEC, %TIME, GRAPH ---------------------------------------------------------------------------------------------------------------------------------------- 99, SYS , STAT, db block gets , 1, .2, 99, SYS , STAT, db block gets from cache , 1, .2, 99, SYS , STAT, consistent gets , 11867, 2.37k, 99, SYS , STAT, consistent gets from cache , 7, 1.4, 99, SYS , STAT, consistent gets from cache (fastpath) , 6, 1.2, 99, SYS , STAT, consistent gets - examination , 1, .2, 99, SYS , STAT, consistent gets direct , 11860, 2.37k, 99, SYS , STAT, no work - consistent read gets , 11859, 2.37k, 99, SYS , STAT, cleanouts only - consistent read gets , 1, .2, 99, SYS , STAT, table scans (long tables) , 1, .2, 99, SYS , STAT, table scans (direct read) , 1, .2, 99, SYS , STAT, table scan rows gotten , 739834, 147.97k, 99, SYS , STAT, table scan blocks gotten , 11860, 2.37k, 99, SYS , TIME, parse time elapsed , 46, 9.2us, .0%, | | 99, SYS , TIME, DB CPU , 79988, 16ms, 1.6%, |@ | 99, SYS , TIME, sql execute elapsed time , 254990, 51ms, 5.1%, |@ | 99, SYS , TIME, DB time , 255375, 51.08ms, 5.1%, |@ | 99, SYS , WAIT, enq: KO - fast object checkpoint , 174947, 34.99ms, 3.5%, |@ | 99, SYS , WAIT, direct path read , 1280, 256us, .0%, | | 99, SYS , WAIT, SQL*Net message to client , 9, 1.8us, .0%, | | 99, SYS , WAIT, SQL*Net message from client , 4672912, 934.58ms, 93.5%, |@@@@@@@@@@| 99, SYS , WAIT, events in waitclass Other , 6, 1.2us, .0%, | | -- End of Stats snap 1, end=2012-09-02 20:03:55, seconds=5 --------------------------------------------------------------------------------- Active% | SQL_ID | EVENT | WAIT_CLASS --------------------------------------------------------------------------------- 2% | 88r4qn9mwhcf5 | enq: KO - fast object checkpoint | Application 2% | 88r4qn9mwhcf5 | ON CPU | ON CPU -- End of ASH snap 1, end=2012-09-02 20:03:55, seconds=5, samples_taken=43
Let’s now fake the table stats so it looks like that there’s only 5 blocks in it – way below the _small_table_threshold value
SQL> EXEC DBMS_STATS.SET_TABLE_STATS(user,'T',numblks=>5); PL/SQL procedure successfully completed. SQL> SELECT COUNT(*) FROM t /* attempt 2 */; COUNT(*) ---------- 1000
The direct path reads are gone – we are doing regular buffered reads now!
SQL> @snapper ash,stats=sw,sinclude=table.scan|gets 5 1 99
Sampling SID 99 with interval 5 seconds, taking 1 snapshots...
-- Session Snapper v3.54 by Tanel Poder ( http://blog.tanelpoder.com )
----------------------------------------------------------------------------------------------------------------------------------------
SID, USERNAME , TYPE, STATISTIC , DELTA, HDELTA/SEC, %TIME, GRAPH
----------------------------------------------------------------------------------------------------------------------------------------
99, SYS , STAT, db block gets , 1, .17,
99, SYS , STAT, db block gets from cache , 1, .17,
99, SYS , STAT, consistent gets , 11865, 1.98k,
99, SYS , STAT, consistent gets from cache , 11865, 1.98k,
99, SYS , STAT, consistent gets from cache (fastpath) , 11528, 1.92k,
99, SYS , STAT, consistent gets - examination , 1, .17,
99, SYS , STAT, no work - consistent read gets , 11851, 1.98k,
99, SYS , STAT, cleanouts only - consistent read gets , 1, .17,
99, SYS , STAT, table scans (long tables) , 1, .17,
99, SYS , STAT, table scan rows gotten , 738834, 123.14k,
99, SYS , STAT, table scan blocks gotten , 11852, 1.98k,
99, SYS , TIME, parse time elapsed , 84, 14us, .0%, | |
99, SYS , TIME, DB CPU , 109983, 18.33ms, 1.8%, |@ |
99, SYS , TIME, sql execute elapsed time , 116709, 19.45ms, 1.9%, |@ |
99, SYS , TIME, DB time , 117102, 19.52ms, 2.0%, |@ |
99, SYS , WAIT, db file scattered read , 63956, 10.66ms, 1.1%, |@ |
99, SYS , WAIT, SQL*Net message to client , 8, 1.33us, .0%, | |
99, SYS , WAIT, SQL*Net message from client , 5119722, 853.29ms, 85.3%, |@@@@@@@@@ |
-- End of Stats snap 1, end=2012-09-02 20:06:19, seconds=6
---------------------------------------------------------------------------------
Active% | SQL_ID | EVENT | WAIT_CLASS
---------------------------------------------------------------------------------
2% | 07sgczqj432mr | db file scattered read | User I/O
-- End of ASH snap 1, end=2012-09-02 20:06:19, seconds=5, samples_taken=46
Note that I deliberately forced a hard parse (with the “attempt 2″ comment) to compile a new cursor. The _direct_read_decision_statistics_driven parameter is not part of the optimizer environment, so a new child cursor would not be automatically created after the parameter change (the same applies to the _small_table_threshold and _serial_direct_read parameters, by the way). But when I change the SQL text, then an entirely new (parent and child) cursor will be compiled anyway.
But wait a minute! Why do I need to compile a new cursor to get Oracle to read the new block count value from optimizer stats?!
I have said in the beginning of this post (and in many other places) that the direct path read decision is not done by the optimizer anyway and is a runtime decision done during every execution, every time any segment (including individual partitions) is scanned during query runtime. This is true for the old (up to 11.2.0.1) Oracle versions, where a direct path decision is done based on the actual, current block count in the segment header, thus the decision can suddenly change when a segment grows by a few blocks, crossing the _small_table_threshold calculation threshold. Perhaps due to performance stability reasons, this seems to have changed.
My tests on 11.2.0.2 have so far shown that when using the new statistics-driven direct path read decisions, each segments’ block counts are stored somewhere in the compiled cursor and reused during next executions of it, even if the block count of the segment changes in the optimizer stats later on! This might result in somewhat better stability as long as you don’t gather new stats – and your buffer cache size (and already cached block counts) don’t change. However if the amount of cached blocks of a segment does change (due to other, index-based accesses for example), then the direct path decision can still change during runtime. It’s just the block counts which are stored in the cursor, but the other factors affecting the decision (buffer cache size, cached block counts) can still change.
This topic is especially relevant on Exadata, as the entire Smart Scanning functionality depends on whether a direct path read IO method gets picked for full segment scans. When experimenting with this, you’ve got to be pretty careful and thorough (to not come to wrong conclusions) as there multiple moving parts and factors involved in the decisions:
- Are block counts taken from optimizer stats or segment header
- Do the segment header and/or optimizer stats block counts change
- Does the buffer cache size change (thus the _small_table_threshold too)
- Does the amount of cached blocks of a segment change
- Parallel vs Serial execution
- Are buffered parallel full scans allowed (the in-memory PX feature of 11.2)
- Did a new child cursor get created or the old one reused
- etc :)
参考至:http://blog.tanelpoder.com/2012/09/03/optimizer-statistics-driven-direct-path-read-decision-for-full-table-scans-_direct_read_decision_statistics_driven/
如有错误,欢迎指正
邮箱:czmcj@163.com
相关推荐
Python课程设计,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。
《松鼠》生态性课堂体验教案
Java系统源码+智慧图书管理系统 内容概要: 本资源包含了完整的Java前后端源码及说明文档,适用于想要快速搭建并部署Java Web应用程序的开发者、学习者。 技术栈: 后端:Java生态系统,包含Spring Boot、Shiro、MyBatis等,数据库使用Mysql 前端:Vue、Bootstrap、Jquery等 适用场景示例: 1、毕业生希望快速启动一个新的Java Web应用程序。 2、团队寻找一个稳定的模板来加速产品开发周期。 3、教育机构或个人学习者用于教学目的或自学练习。 4、创业公司需要一个可以立即投入使用的MVP(最小可行产品)。
项目包含前后台完整源码。 项目都经过严格调试,确保可以运行! 具体项目介绍可查看博主文章或私聊获取 助力学习实践,提升编程技能,快来获取这份宝贵的资源吧!
《松鼠》教学方案
学生角色 学生用户在系统的前台界面可以浏览站内新闻、系统公告等公共的信息,在进行了注册和登录等操作后可以进入个人后台管理界面,对自己的个人信息进行管理,还可以进行实验成绩查看和实验交流等操作。 教师角色 教师用户也可以正常使用本系统的前台功能,但最主要的功能还是在个人后台界面中。在教师的个人后台界面中,首先教师可以管理自己的个人信息,还可以对学生进行实验任务书下达,对学生的实验成果和实验成绩管理等操作。 管理员角色 系统管理员可以管理整个系统的数据,比如可以管理教师和学生的个人资料,对违反了网站及学校实验室规定的同学可以进行删除。除了管理教师和学生的信息外,管理员用户还可以对公告信息及新闻信息等进行管理。 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7 数据库工具:Navicat11 开发软件:eclipse/idea Maven包:Maven3.3 服务器:tomcat7
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、本项目仅用作交流学习参考,请切勿用于商业用途。
管理员 管理员管理 工作人员管理 用户管理 公告信息管理 往届项目管理 工作人员 个人资料修改 公告查看 项目申报信息管理,发布(项目申报信息、要求、时间节点等信息) 项目模板管理 往届项目查询 用户 个人资料修改 公告查看 项目模板下载 项目申报信息查看 我的项目申报 项目申报结果查看 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7 数据库工具:Navicat11 开发软件:eclipse/idea Maven包:Maven3.3 服务器:tomcat7
福禄寿FloruitShow - 多一个世界 [mqms].ogg
Python课程设计,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。
商业企业资本结构与公司价值关系研究 开题报告.docx
间位芳纶纸全球市场研究报告:2023年市场规模达到约6.31亿美元 在特种纸材料领域,间位芳纶纸以其高强度、耐高温、耐腐蚀、本质阻燃和卓越的电绝缘性能,成为了现代工业不可或缺的关键材料。从电气绝缘到蜂窝结构材料,再到民间用品,间位芳纶纸的广泛应用不仅推动了多个行业的进步,更展现了其巨大的市场潜力。然而。本文将深入探讨间位芳纶纸市场的现状、技术创新、应用领域、竞争格局及未来趋势,并强调用户咨询在引领市场发展中的关键作用。 市场概况 据QYR最新调研,2023年全球间位芳纶纸市场规模达到约6.31亿美元,同比增长12.88%。这一增长主要得益于电气绝缘领域和蜂窝芯材领域的强劲需求。电气绝缘领域作为间位芳纶纸的主要应用领域,2023年占比高达62.76%,而蜂窝芯材领域则紧随其后,占比34.71%。在中国市场,间位芳纶纸的发展同样令人瞩目。尽管起步较晚,但得益于技术进步和政策支持,国内间位芳纶纸市场规模持续走高,从2016年的4.8亿元增长至2023年的10亿元,期间复合年增长率为12.01%。 技术创新与趋势 技术创新是推动间位芳纶纸市场发展的核心动力。随着纳米技术、智能制造等技术的不断发
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、本项目仅用作交流学习参考,请切勿用于商业用途。
Python 批量转换PPT、Excel、Word为PDF文件工具
四川大学期末考试试题(开卷).pdf
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、本项目仅用作交流学习参考,请切勿用于商业用途。
springboot-基于JavaScript的在线考试系统.zip
深圳市2005-2024年近20年的历史气象数据,每3小时更新一次数据,参数包含气温、气压、降水量、云层、能见度、风向、湿度等,几万条数据
Python课程设计,含有代码注释,新手也可看懂。毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。
2024北邮数电大实验——实验3:水位检测与控制 全功能代码开源。本人期末复习任务繁重,代码无时间作详细注释。