I
I
ivandao2021-04-29 08:27:43
Database
ivandao, 2021-04-29 08:27:43

Does it make sense to index a boolean field?

There is a field of type boolean in the table, it is often selected by it.
Does it make sense to index it or boolean itself is already maximally indexed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-04-29
@ivandao

When answering the question "whether it makes sense to index field X" you should always operate:
0. Features of a particular DBMS.
1. Structure of tables.
2. The structure of the request.
3. The contents of the table.
4. EXPLAIN results on request before indexing.
5. EXPLAIN results after test indexing.
In your question, you did not cite any of the above, so you can only give theoretical calculations:
1. The cardinality of this index will be low. It's not very good, but it's not fatal either.
2. For inquiriesselect id from mytable where field = 1;this index can give a decent profit, provided that the table has many other columns - the DBMS will not have to read extra data from the disk, only the index will be used. If the query is more complicated or the table is simpler, then the profit decreases. Specific values ​​can only be given by EXPLAIN.
Learn to work with EXPLAIN, no answers on the Internet will help better than him. Another good book to read is High Performance MySQL .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question