Yes, your database engine will use an index (if available and depending on your query, optimisor) when you do like 'bla%'. I did read the theory on this once, but have since forgot... i guess i should hop off to google now.. :-) | [reply] [d/l] |
OK, so i found an article which summed it up, its pretty obvious really. To paraphrase:
No an index won't work in the above situation - if you think about it, what benefit could an index be when your search string starts with a wildcard - at what point in the index would you begin to search?
| [reply] |
Well, the theoretical situation i was talking about would have the wildcard at the end of the string instead of the beginning, so I could see that it would have a place to start in the index. However, after some reading of the PostgreSQL docs (the database I'm using for this particular project) and doing an EXPLAIN on several queries, it looks like PostgreSQL does not use the index at all if it is any sort of LIKE query (even WHERE id LIKE '42'), but will use the index on a regular query (WHERE id = '42'). Though I suspect this could differ with another databse.
| [reply] [d/l] [select] |