Indexing will not help when used in conjunction with LIKE '%something%' .
It is like looking up words in a dictionary that have ae . The dictionary (or index in this case) is organized based on the first letter of the word, then the second letter, etc. He does not have a mechanism for all words with ae to be close to each other in them. You are still reading the entire dictionary from start to finish.
Indexing the fields used in the CASE clause will most likely not help. Indexing helps simplify the search for records in a table. The CASE clause is the processing of found records, not their search in the first place.
Optimizers can also struggle with optimizing several unrelated
OR conditions, such as yours. The optimizer tries to narrow down the effort to complete your request, but it's hard to do when unrelated conditions can make the record acceptable.
In general, your query will be useful from indexes on roots(root_id) and / or roots(id) , but not much more.
If you specify additional fields, then there are two main costs: - Increased recording time (insert, update or delete) due to additional indexes for writing to
- Increased disk space
source share