gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:55:57 26 4
gpt4 key购买 nike

我有一个巨大的表(数百万条记录),其中有几百到几千条记录由 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com