我记得曾经读到过,为一个基数较低(不同值的数量较少)的字段建立索引实际上并不值得。我承认,我对索引的工作原理了解得不够,无法理解其中的原因。
So what if I have a table with 100 million rows in it, and I am selecting records where a bit field is 1? And let's say that at any point in time, there are only a handful of records where the bit field is 1 (as opposed to 0). Is it worth indexing that bit field or not? Why?
当然,我可以仅仅测试它并检查执行计划,我将这样做,但是我也对其背后的理论感到好奇。基数什么时候重要,什么时候不重要?