pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: Jie Liang <jie@stbernard.com>
Cc: Postgresql Performance <pgsql-performance@postgresql.org>
Subject: Re: LIKE and INDEX
Date: Wed, 05 May 2004 13:31:45 -0400
Message-ID: <1083778304.60668.3.camel@jester> (raw)
In-Reply-To: <E7E213858379814A9AE48CA6754F5ECB36335D@mail01.stbernard.com>
References: <E7E213858379814A9AE48CA6754F5ECB36335D@mail01.stbernard.com>

> 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.




view thread (3+ messages)  latest in thread

Message-ID: <1083778304.60668.3.camel@jester>
Permalink:  ../1083778304.60668.3.camel@jester/
Also on:    postgresql.org/message-id/1083778304.60668.3.camel@jester

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: pg@rbt.ca, jie@stbernard.com
  Subject: Re: LIKE and INDEX
  In-Reply-To: <1083778304.60668.3.camel@jester>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox