performance - 仅包含一个值的数据库索引

标签 performance oracle oracle10g

我有一个巨大的表(数百万条记录),其中有几百到几千条记录由 bool 字段标记(值 = 1 而不是 0)。

我只关心真实的记录(值 = 1)。有没有办法创建一个只“索引”这些记录的索引?我应该使用什么样的索引?

select count(*) 
from records 
where boolean_field = 1

环境:Oracle 10g(但我也对其他 dbms 的评论感兴趣)

谢谢!

最佳答案

如果您可以使您的“假”值为空而不是 0,您将获得您想要的结果。

否则,您可以像这样创建一个基于函数的索引:

create index idx on recors (case boolean_field when 1 then 1 end);

这只会索引 1,但要让 Oracle 在您的查询中使用它,您的查询必须像这样:

select * from records where case boolean_field when 1 then 1 end = 1;

关于performance - 仅包含一个值的数据库索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283258/

相关文章:

c++ - 在 C++ 中创建 setter 函数的最佳方法

mysql - 使用 PreparedStatement 从 MySQL 数据库传输数据的开销

java - 如何避免重复加载大文件?

oracle - 如何查找Oracle中授予用户的权限和角色?

database - oracle 无法登录sqlplus

c++ - 我可以在 Rust 中就地构建吗?

Oracle 的 C# 参数化查询 - 严重而危险的错误!

sql - 永无止境的查询

ROracle 不处理 Unicode

sql - 下一个和上一个记录