Re: indexing and LIKE - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: indexing and LIKE
Date
Msg-id Pine.BSF.4.21.0110111252570.93189-100000@megazone23.bigpanda.com
Whole thread Raw
In response to indexing and LIKE  (Patrik Kudo <kudo@partitur.se>)
List pgsql-sql
On Thu, 11 Oct 2001, Patrik Kudo wrote:

> Hi!
> 
> If I want to be able to search for stringmatches using LIKE, doing
> something like the following:
> 
> select id, name from table1 where lower(name) like 'somestring%';
> 
> Actually I will be joining with some other table on id too, but the join
> will produce a substancial amount of data to be filtered with the LIKE
> clause so I figure if it'd be possible to index on lower(name) somehow,
> it would result in an appreciated speed gain.

You can make functional indexes:
create index <name> on table(lower(<col>));

If you're running in a locale other than C however I don't think postgres
will use it in any case in 7.1 and earlier (I'm not sure about 7.2)

> what type of index and using what syntax? Is it possible to create a
> multicolumn index on both id and name? Both id and name are of type
> "text".

Yes, you can do a multicolumn index, but if you want an id and lower(name)
index, it's a little more complicated and probably wouldn't do what you
want (I think the functional indexes are limited to a single function with
only column references as parameter).




pgsql-sql by date:

Previous
From: Alexander Deruwe
Date:
Subject: BIGINT's and indexes.
Next
From: Bruce Momjian
Date:
Subject: Re: Server crash caused by CHECK on child