From: | Rod Taylor <pg(at)rbt(dot)ca> |
---|---|
To: | Jie Liang <jie(at)stbernard(dot)com> |
Cc: | Postgresql Performance <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: LIKE and INDEX |
Date: | 2004-05-05 17:31:45 |
Message-ID: | 1083778304.60668.3.camel@jester |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
> but if I use:
> select url from urlinfo where url like 'http://%.lycos.de';
> it won't use index at all, NOT good!
> is there any way I can force secon query use index???
create index nowww on urlinfo(replace(replace(url, 'http://', ''),
'www.', '')));
SELECT url
FROM urlinfo
WHERE replace(replace(url, 'http://', ''), 'www.', '') = 'lycos.de'
AND url LIKE 'http://%.lycos.de' ;
The replace() will narrow the search down to all records containing
lycos.de. Feel free to write a more complex alternative for replace()
that will deal with more than just optional www.
Once the results have been narrowed down, you may use the original like
expression to confirm it is your record.
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2004-05-05 18:12:38 | Re: LIKE and INDEX |
Previous Message | Gaetano Mendola | 2004-05-05 17:31:01 | Re: Bug in optimizer |