Is there any performance gain in indexing a boolean field?

后端 未结 7 1870
独厮守ぢ
独厮守ぢ 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:44

    Not really. You should think about it like a book. If there were only 3 kinds of words in a book and you index all of them, you would have the same number of index pages as normal pages.

    There would be a performance gain if there are relatively few records of one value. For example, if you have 1000 records and 10 of them are TRUE, then it would be useful if you searching with isok = 1

    As Michael Durrant mentioned, it also makes writes slower.

    EDIT: Possible duplication: Indexing boolean fields

    Here it explains that even if you have an index, if you have too many records it doesn't use the index anyways. MySQL not using index when checking = 1 , but using it with = 0

提交回复
热议问题