MySQL: Index for two boolean fields

时间:2017-04-06 16:50:37

标签: mysql indexing

I have a MySQL table with two boolean (TINYINT or BIT or something like this) fields.

For efficient counting (and paginating in general, just is for "cutting" a slice from the DB to show in a page of a pagination) all rows where both booleans are false, should I create an index on each of these two fields, composite index on both fields, or both?

1 个答案:

答案 0 :(得分:1)

Normally when you're talking about indexing data you need to accommodate any columns included in a WHERE clause. That is, if you're doing:

SELECT * FROM boolean_table WHERE a_flag=0 AND b_flag=0

Then yes, you need an index on a_flag,b_flag. If there are additional fields involved in filtering those will need to be included as well.