Is there any performance gain in indexing a boolean field?

后端 未结 7 1856
独厮守ぢ
独厮守ぢ 2020-12-02 10:39

I\'m just about to write a query that includes a WHERE isok=1. As the name implies, isok is a boolean field (actually a TINYINT(1) UNSIGNED

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 10:53

    Just to put a finer point on several other answers here, since in my experience, those looking at questions like this are in the same boat we were, we've all heard that indexing Boolean fields is pointless, and yet...

    We have a table with about 4 million rows, only about 1000 or so at a time will have a Boolean switch flagged and that's what we search against. Adding an index on our Boolean field sped up queries by orders of magnitude, it went from about 9+ seconds to a fraction of a second.

提交回复
热议问题