I have the following column:
is_owned_by_admin TINYINT(1) NOT NULL DEFAULT 0;
If I am querying this field a lot, do I need to add an INDEX to it, or is the boolean field just as 'fast' as an indexed boolean field? What is the difference?
I have the following column:
is_owned_by_admin TINYINT(1) NOT NULL DEFAULT 0;
If I am querying this field a lot, do I need to add an INDEX to it, or is the boolean field just as 'fast' as an indexed boolean field? What is the difference?
There's not enough information in the question to give a definitive answer.
The most general answer: there's no benefit to be gained by adding an index on just that one boolean column.
That's because with only two values, if those values are distributed evenly, the index isn't going to improve performance. The index would only be useful if you are always looking for rows that have the value that occurs most infrequently, like less than 5% or 10% of the rows. In that special case, it might improve performance.
I strongly suspect that's not the only predicate in your query. Likely, there are other predicates, on other columns. And including that boolean column as an extra column in another index that will be used by your query, that might actually be of some benefit.
There's some overhead to creating and maintaining an index (it isn't free), so that has to be weighed against the benefit of having an index. Adding an extra column to an existing index would be lot less expensive.
The most appropriate indexes are going to depend on the tables you are querying, and the actual SQL statements you are executing.
Without going into too much detail, the answer is that you should only consider indexing it if you are commonly searching for one of the boolean values AND that value is relatively rare.
That is: if very few of the total pages are "is_owned_by_admin=1" and you are doing searches that tend to want to find some significant number of those, then you might consider indexing. However even in that case, the overhead of the index might not be worth it.