Index in an ENUM field can bring some advantage?

2

I was reading in a response from SOEN that fields in a table that have INDEX can optimize a query. Of course, as long as this query is known, such as a user search for the email field, for example.

I have here a Person table that has a ENUM('M', 'F') field called sex .

This table is very "chubby" and I would like to know if, if I put a INDEX in that field, there may be an improvement in the query. (We have reports that make a specific query for those values.)

Is it advantageous to use INDEX for fields of type ENUM or boolean ( tinyint(1) )?

    
asked by anonymous 02.05.2016 / 13:53

1 answer

2

I can not say in MySQL specifically (nor do I think it matters, I hope not: P). Probably no advantage, if it is an index with single column and / or enumeration so simple. But I'm not so sure.

If you are a registered engineer, you may have some gain when you look for women. Why search the entire database for 1% of the rows? But I do not guarantee that the results will be so much better for that 1%. It certainly will not be for the 99%.

So it depends on the case and you have to do tests with the actual database.

It would certainly look more interesting if the / boolean enumeration column is part of the composite index.

It would be more interesting if this column were calculated from others and would be an aid to filter a certain complex condition and facilitate certain searches.

Some databases even have special index for this by mapping the bits and creating a compact index. This index can be used in a specific condition, typically not used in a Boolean column. The index is created based on a where expression and the result is that it is indexed, so it can already quickly select the rows that satisfy this condition. This is done internally and the developer can not pre-create this index.

Question with a case that shows that the index does not always help as people think .

    
02.05.2016 / 15:03