仅涵盖一个值的数据库索引
我有一个巨大的表(数百万条记录),其中几百到几千条由布尔字段标记(值 = 1 而不是 0)。
我只关心真实的记录(值 = 1)。有没有办法创建一个仅“索引”这些记录的索引?我应该使用什么样的指数?
select count(*)
from records
where boolean_field = 1
环境:Oracle 10g(但我也对其他dbms的评论感兴趣)
谢谢!
I have huge table (millions of records) in which a few hundreds to a few thousands are marked by a boolean field (value = 1 instead of 0).
I only care for records which are true (value = 1). Is there a way to create an index which only 'indexes' these records? What kind of indices should I use?
select count(*)
from records
where boolean_field = 1
Environment: Oracle 10g (but I'm also interested in comments about other dbms)
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以将“假”值设置为 null 而不是 0,那么您将获得您想要的结果。
否则,您可以创建一个基于函数的索引,如下所示:
这只会索引 1,但要让 Oracle 在查询中使用它,您的查询必须类似于:
If you could make your "false" value be null rather than 0, you would achieve the result you want.
Otherwise, you could create a function-based index like this:
That would only index the 1s, but for Oracle to use it in your queries your queries would have to be like:
这似乎是 Oracle 中位图索引的典型情况。
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm#i2062403
This seems like a typical case for bitmap indexes in oracle.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm#i2062403