NULL值如何影响数据库搜索中的性能? [英] How do NULL values affect performance in a database search?

查看:282
本文介绍了NULL值如何影响数据库搜索中的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的产品中,我们有一个通用的搜索引擎,并尝试优化搜索性能。查询中使用的很多表允许空值。我们的产品运行在 Oracle



code>

解决方案 / code>, NULL 值未编制索引,i。 e。此查询:

  SELECT * 
FROM table
WHERE列is NULL

将始终使用全表扫描,因为索引不覆盖您需要的值。



不仅如此,这个查询:

  SELECT列
FROM table
ORDER BY
column

也将使用全表扫描和排序,原因相同。



如果你的值本质上不允许 NULL ,那么将列标记为 NOT NULL


In our product we have a generic search engine, and trying to optimze the search performance. A lot of the tables used in the queries allow null values. Should we redesign our table to disallow null values for optimization or not?

Our product runs on both Oracle and MS SQL Server.

解决方案

In Oracle, NULL values are not indexed, i. e. this query:

SELECT  *
FROM    table
WHERE   column IS NULL

will always use full table scan since index doesn't cover the values you need.

More than that, this query:

SELECT  column
FROM    table
ORDER BY
        column

will also use full table scan and sort for same reason.

If your values don't intrinsically allow NULL's, then mark the column as NOT NULL.

这篇关于NULL值如何影响数据库搜索中的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆