in reply to Re: Re: (tye)Re2: DBI, quoting, and LIKE searches
in thread DBI, quoting, and LIKE searches

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?
  • Comment on Re: Re: Re: (tye)Re2: DBI, quoting, and LIKE searches

Replies are listed 'Best First'.
Re: Re: Re: Re: (tye)Re2: DBI, quoting, and LIKE searches
by Mr_Person (Hermit) on Dec 30, 2002 at 15:49 UTC
    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.