问题描述
这可能是一个非常愚蠢的问题,但是在索引数据库表中的布尔字段有很大的好处吗?
This is probably a really stupid question, but is there going to be much benefit in indexing a boolean field in a database table?
给定一个常见的情况, soft-delete记录被标记为不活动,因此大多数查询包括 WHERE deleted = 0
,它将有助于该字段自己索引,
Given a common situation, like "soft-delete" records which are flagged as inactive, and hence most queries include WHERE deleted = 0
, would it help to have that field indexed on its own, or should it be combined with the other commonly-searched fields in a different index?
推荐答案
否。
您索引搜索的字段,并具有高选择性/基数。布尔字段的基数在几乎任何表中都被删除。如果有什么,它会使你的写入速度变慢(通过一个哦这么小的量)。
You index fields that are searched upon and have high selectivity/cardinality. A boolean field's cardinality is obliterated in nearly any table. If anything it will make your writes slower (by an oh so tiny amount).
也许你会使它成为聚集索引中的第一个字段,如果每个查询都考虑到软删除?
Maybe you would make it the first field in the clustered index if every query took into account soft deletes?
这篇关于索引布尔字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!