Re: "like" and index

From: Tony Liao <tonyliao(at)yuehetone(dot)com>
To: Michael Monnerie <michael(dot)monnerie(at)is(dot)it-management(dot)at>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: "like" and index
Date: 2009-02-25 11:48:08
Message-ID: 8f750b7c0902250348jfee8784k5065c14725555a12@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

2009/2/25 Michael Monnerie <michael(dot)monnerie(at)is(dot)it-management(dot)at>

> On Mittwoch 25 Februar 2009 Tony Liao wrote:
> > hi all,
> > I have a table table_A (id serial,prefix varchar),for example.
> > now I want to get the id of "johnsmith"'s prefix match
> > table_A.prefix,so I do select id from table_A where 'johnsmith' like
> > prefix||'%'
>
> SELECT id FROM table_A WHERE prefix LIKE 'johnsmith%';

* in my table,the values of prefix are
('john','tom','anne','jim'......),so I don't think my SELECT was wrong.*
by the way,my postgres-server version is 8.36.thanks

>
>
> > ,the table_A is very large so I would like to make
> > index. create table_A_index on table_A(prefix)
> > I try to explain analyze,but it doesn't work ,it use seq scan.
>
> Because your SELECT was wrong.
>
> > I try another index. drop index table_A_index; create
> > table_A_index on table_A(prefix varchar_pattern_ops); it doesn't
> > work,too.
> > thanks
> > ps:I have another table table_B would use table_B.prefix=
> > table_A.prefix.so how can I create the index?
>
> That's a foreign key, if I understand you correctly.
>
> ALTER TABLE ONLY B
> ADD CONSTRAINT B_prefix_fkey FOREIGN KEY (prefix) REFERENCES
> A(prefix) ON UPDATE CASCADE ON DELETE CASCADE;
>
> mfg zmi
> --
> // Michael Monnerie, Ing.BSc ----- http://it-management.at
> // Tel: 0660 / 415 65 31 .network.your.ideas.
> // PGP Key: "curl -s http://zmi.at/zmi.asc | gpg --import"
> // Fingerprint: AC19 F9D5 36ED CD8A EF38 500E CE14 91F7 1C12 09B4
> // Keyserver: wwwkeys.eu.pgp.net Key-ID: 1C1209B4
>
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Daniel J. Summers 2009-02-25 14:20:40 Re: "like" and index
Previous Message Michael Monnerie 2009-02-25 11:41:40 Re: "like" and index