I have a table member, with column name that I want to put an index on, because it is searched quiet frequently. When I create my sql search string, the name will consist only of alpha-numeric characters and be compared against lowercase matches.
SELECT *
FROM member
WHERE lower(regexp_replace(member_name, '[^[:alnum:]]', '', 'g')) ~* 'search_string'
OR lower(metaphone(name, 4)) = lower(metaphone('search_string', 4));
is it better to create an index that matches my search?
create index member_name_idx on member (lower(regexp_replace(name, '[^[:alnum:]]', '', 'g')));
What if we decide we want to allow more characters in the search later - just have to remember to update the index?
do I need two indexes? one for both search parameters (regexp & metaphone)?
perhaps there is a solution that I haven't thought of. any input would be appreciated!
Thanks,
Jamie K.
Jamie K.