Full Scans and Throwaway 全扫描和“抛弃”
Always remember that whether or not a full scan will be an effective choice depends on the number of
blocks that will need to be read as much as on how many rows will end up in the final result set. How
the data is stored plays an important role in the decision, as demonstrated in this example. However,
the other key factor in whether or not a full scan is an effective choice is throwaway. Throwaway rows
are those rows that are checked against a filter predicate and don’t match the filter and are thus
rejected from the final result set.
永远记住全扫描是否是有效的选择取决于所需读入的块数,也就是有多少行集将影响最终结果集。数据如何存储在抉择的过程中扮演了重要的角色,正如本例中所演示的。然而,是否全扫描是一个有效的选择的另个关键的因素则是“抛弃”。抛弃行是指这些行由过滤器谓词检查,且不匹配过滤器,则被排除于最终的结果集中。
In the previous example, the full table scan operation would have to check all 10,000 rows in the
table and throw away 9,900 of them to end up with the final result set of 100 rows. The check on each
row is simply the filter predicate on id = 1 (seen in Listing 3-4 in the Predicate Information section
for step 1). In order to execute this filter, the CPU will be utilized for each check. That means that while
the number of blocks accessed will be limited, there will be quite a bit of CPU resources used to
complete the filter checks for each row. The use of the CPU will be factored into the cost of the full scan.
As the number of blocks accessed and the amount of throwaway increases, the more costly the full
scan will become. Listing 3-5 is a simple query to show the number of rows and number of blocks for
table T2 in your example. Based on the number of blocks shown, the full table scan would access
approximately 164 blocks.
在上个例子中,全表扫描操作将必须检查表中所有的10000行然后抛弃其中9900行而最终结果集是100行。对每行的检查简单的由过滤谓词id=1(查
看列表3-4的步骤1谓词信息段)。为了执行该过滤器,在每次检查中都要用到CPU。这意味着即使访问的块数是有限的,对于完成每行的检查依然要占用很大CPU资源。CPU的使用将算入全扫描成本中。
因为访问的块数和抛弃的数量的增加,全扫描的成本也越发变高。列表3-5是一个简单的查询展示例子中T2表的行数和块数。基于展示的块数,全表扫描将大概访问164个块。
Listing 3-5. Rows and Blocks Statistics for Tables T1 and T2 表T1和T2的行和块统计
SQL> select table_name, num_rows, blocks from user_tables where table_name = 'T2' ;
TABLE_NAME NUM_ROWS BLOCKS
------------------------------ --------------- ---------------
T2 10000 164
1 rows selected.
Over time, as rows are added to the table and the table grows larger, the cost of throwing away so
many rows would increase enough to cause the optimizer to switch to an index scan operation instead.
The point where the optimizer decides to switch over may not necessarily be the point where you
achieve optimal performance.
You can use hints to force the optimizer to use an index and test to see at
what point it might make more sense to use an index, and if the optimizer doesn’t choose that path,you
can consider using hints or SQL profiles to help.
Chapter 16 will cover using hints and profiles so
you’ll be prepared to use them if you ever need to do so.
随着时间的推移,行加入表中,表变得越来越大,抛弃如此多的行的成本将迫使优化器切换成索引扫描操作来代替。优化器决定切换的那个(转折)点可能也不一定是你取得优化性能的那个(转折)点。
你能通过提示而强制优化器使用索引,再测试看在哪一点可能使用索引更合理,若优化器不选择那条路径,你就可以考虑使用
提示或者SQL配置参数予以辅助。
第十六章将讲述使用提示和配置,如果你曾经有需要这么做你将用的上他们。
Full Scans and Multiblock Reads 全扫描和多块读
Another thing you need to know about full scans is how blocks are read. A full scan operation makes
multiblock reads. This means that a single IO call will request several blocks instead of just one. The
number of blocks requested will vary and can actually range anywhere from one to the number of
blocks specified in the db_file_multiblock_read_count parameter.
For example, if the parameter is set
to 16 and there are 160 blocks in the table, there could be only 10 calls made to get all the blocks.
你需要知道的关于全扫描的另一件事就是块是如何读取的。全扫描可多块读入。这意味着一次IO调用将请求几个块而不只是一个。请求的块数会变动,实际的范围
可能是1到参数db_file_multiblock_read_count所指定的块数。
例如,如果参数设置成16而表中有160个块,可能只需要10
次读就能获取所有的块。
I say that only 10 calls could be made because of the following limitations on multiblock read calls.
Oracle will read db_file_multiblock_read_count blocks unless reading the full number of blocks
我是说可能只要10次调用因为还有对多块读调用还有下面这些限制。Oracle将读db_file_multiblock_read_count设定的块数,除非读满额块数。
-
causes Oracle to have to read blocks that cross an extent boundary
. In this case, Oracle will
read the blocks up to the extent boundary in one call, then issue another call to read the
remainder.
-
means a block already in the buffer cache would be read again as part of the multiblock read.
Oracle will simply read the blocks up to those not already in memory, then issue another read
call that skips those blocks to read the rest.
This could mean that a multiblock read might only
read one block at a time. For example, let’s say the multiblock read count was 16 and the
range of blocks to be read was between block number 1 and 16. If the even numbered blocks
had already been placed into the buffer cache, individual single block reads would be done for
each odd numbered block in that range. In that case, 8 read calls would be made—one for
each block in that range not already in the buffer cache.
-
would exceed an operating system limit for multiblock read sizes. This is dependent on your
operating system so it can vary.
- 若Oracle必须读取跨出范围边界
的块。在这种情况下,Oracle将一次调用中读在范围边界以内的块。再发送另一次调用读取其它的块。
-
若块已经在缓冲区缓存中,作为多块读的一部分,该块将再次被读取。Oracle将只是读取那些没有在内存中的块,而发送另一个读调用跳过那些块去读其它部分。
这意味着可能多块读只是一次读一个块。例如,若多块读数是16(就是要读16个块)而读入块的范围则是1到16.如果偶数标号的块已经置于缓冲区缓存
中,范围中各奇数块的读取就需由独立的单个块读完成。这种情况下,将有8次读----对在那个范围中的各个没在缓冲区中的块各一次。
-
多块读的大小可能超出操作系统的限制。这取决于你操作系统,所以它会变动。
分享到:
相关推荐
《Pro Oracle SQL》是Oracle数据库查询优化的一本权威著作,其中第三章着重讲解了全面扫描(Full Scan Access Methods)这一重要的访问方法。在数据库查询优化中,了解并掌握不同的访问方法对于提高SQL查询性能至关...
解决Linux下Oracle缺失依赖 libgcc-3.4.6-3.1.i386.rpm
flink-sql-connector-oracle-cdc 2.5-SNAPSHOT
《Pro Oracle SQL》是Oracle数据库查询优化的经典之作,其中Chapter 3深入探讨了SQL查询的执行机制。在3.1.4章节中,主要讲解了全扫描(Full Scans)和高水线标记(Highwater Mark)的概念及其对查询性能的影响。这...
jdk-17.0.3.1 (jdk-17_windows-x64_bin.zip)适用于Windows x64 系统 :是 Java SE 平台的最新长期支持版本。根据Oracle 免费条款和条件许可,JDK 17 二进制文件可在生产中免费使用,并可免费重新分发。
《Pro Oracle SQL》是Oracle数据库查询的一本权威指南,Chapter 5主要探讨了与数据相关的问题,特别是关于NULL值的处理。在Oracle SQL中,NULL是一个特殊的值,表示未知或缺失的信息,它与任何其他值都不相等,包括...
linux下安装Oracle的必备库文件
Practical Guide for Oracle SQL,T-SQL and MySQL 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...
5. **验证安装**:安装完成后,通过启动数据库服务并运行一些基本的SQL查询来验证Oracle 11g是否正确安装和运行。 提供这样的依赖包,尤其是以一个固定且相对较低的价格,对于那些寻找可靠资源的运维人员来说,是一...
《Pro Oracle SQL》一书的第10章深入探讨了SQL优化,特别是10.2节,重点关注如何测试执行计划,这是SQL性能调优的关键环节。在这个部分,作者旨在帮助读者理解如何有效地评估和改进SQL查询的性能,以提高数据库系统...
jdk-17.0.3.1 (jdk-17_windows-x64_bin.msi)适用于Windows x64 系统 :是 Java SE 平台的最新长期支持版本。根据Oracle 免费条款和条件许可,JDK 17 二进制文件可在生产中免费使用,并可免费重新分发。
《PRM-DUL v3.1:紧急数据库恢复利器》 在信息技术领域,数据安全与恢复始终是至关重要的一环。当面临Oracle数据库无法正常打开的情况,数据恢复工具就显得尤为重要。"PRM-DUL v3.1.zip"是一款专为解决这类问题而...
《Oracle Linux环境准备:深入理解libgcc-3.4.6-3.1.i386》 在Oracle Linux环境中,正确配置和管理软件库是系统优化和稳定运行的关键环节。这里我们关注的是"libgcc-3.4.6-3.1.i386.rpm"这个组件,它在Linux系统中...
《Pro Oracle SQL》是Oracle数据库查询的一本权威指南,其中第二章主要讲解SQL查询的高级技巧。在2.8节“子查询展开(Subquery Unnesting)”中,我们将会深入探讨Oracle SQL中一种优化查询性能的重要策略。这一部分...
《Pro Oracle SQL》一书的第七章第7.8节主要探讨了如何通过GROUPING_ID()函数来扩展Oracle SQL报告的功能。GROUPING_ID()在数据分析和报表生成中扮演着重要角色,尤其在处理分组数据时,能提供更详细的分组信息。本...
《Pro Oracle SQL》是Oracle数据库查询的一本权威指南,其中第9章主要讲解了如何使用Model子句进行行间引用,这是一个高级SQL特性,用于处理复杂的行与行之间的计算和逻辑操作。9.2章节专注于Inter-Row Referencing...
《Pro Oracle SQL》是Oracle数据库查询优化的经典之作,第六章主要聚焦在Execution Plans(执行计划)上,这是数据库查询性能优化的关键。本章节的第四部分深入探讨了如何理解和解析执行计划,以及它对SQL性能的影响...
jdk-17.0.3.1 (jdk-17_windows-x64_bin.exe)适用于Windows x64 系统 :是 Java SE 平台的最新长期支持版本。根据Oracle 免费条款和条件许可,JDK 17 二进制文件可在生产中免费使用,并可免费重新分发。
《Pro Oracle SQL》一书的第9章,重点关注了使用"Model"子句进行性能调优的方法。在Oracle数据库中,Model子句是一种强大的功能,它允许数据建模和复杂的计算,尤其适用于解决多步骤计算问题,如模拟、预测和序列...