Oracle 10g - 优化 WHERE IS NOT NULL

Oracle 10g - optimize WHERE IS NOT NULL(Oracle 10g - 优化 WHERE IS NOT NULL)
本文介绍了Oracle 10g - 优化 WHERE IS NOT NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有 Oracle 10g,我们需要查询 1 个表(无连接)并过滤掉其中 1 列为空的行.当我们这样做时 - WHERE OurColumn IS NOT NULL - 我们对一个非常大的表进行全表扫描 - BAD BAD BAD.该列上有一个索引,但在此实例中被忽略.有什么解决办法吗?

We have Oracle 10g and we need to query 1 table (no joins) and filter out rows where 1 of the columns is null. When we do this - WHERE OurColumn IS NOT NULL - we get a full table scan on a very large table - BAD BAD BAD. The column has an index on it but it gets ignored in this instance. Are there any solutions to this?

谢谢

推荐答案

优化器认为全表扫描会更好.

The optimizer thinks that the full table scan will be better.

如果只有几个 NULL 行,则优化器是正确的.

If there are just a few NULL rows, the optimizer is right.

如果您绝对确定索引访问会更快(也就是说,您有超过 75% 行且 col1 IS NULL),则提示您的查询:

If you are absolutely sure that the index access will be faster (that is, you have more than 75% rows with col1 IS NULL), then hint your query:

SELECT  /*+ INDEX (t index_name_on_col1) */
        *
FROM    mytable t
WHERE   col1 IS NOT NULL

为什么是 75%?

因为使用 INDEX SCAN 来检索索引未涵盖的值意味着 ROWID 上的隐藏连接,其成本约为 4 的两倍作为表扫描.

Because using INDEX SCAN to retrieve values not covered by the index implies a hidden join on ROWID, which costs about 4 times as much as table scan.

如果索引范围包含超过 25% 的行,则表扫描通常会更快.

If the index range includes more than 25% of rows, the table scan is usually faster.

正如Tony Andrews 所提到的,聚类因子是衡量这个值的更准确的方法,但25% 仍然是一个很好的经验法则.

As mentioned by Tony Andrews, clustering factor is more accurate method to measure this value, but 25% is still a good rule of thumb.

这篇关于Oracle 10g - 优化 WHERE IS NOT NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)