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?
答案 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.