i have a table that stores about 50k rows and here’s my query :
select * from video where status = 1 and filter = 1 and category = 4
these columns are tinyint and i wonder should i do index on these columns ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No!
You should always consider index selectivity! If the result of a where clause on an index will return more than 20% of the table, then the index is NOT used, but it’s mantained.
So, for example, the status of your video will be 1, 2, 3, then you have 3 posible states. If those indexes are well distributed we can think that will be 33.3% of them aprox. Then, the query:
will NOT use that index! Instead, a FULL TABLE SCAN would be used.
Please, read about it. It’s really important and a common mistake.
Google search