pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Monnerie <michael.monnerie@is.it-management.at>
To: pgsql-admin@postgresql.org
Subject: Re: "like" and index
Date: Wed, 25 Feb 2009 12:41:40 +0100
Message-ID: <200902251241.40700@zmi.at> (raw)
In-Reply-To: <8f750b7c0902250259w6065515as350aca3b5d7d8173@mail.gmail.com>
References: <8f750b7c0902250259w6065515as350aca3b5d7d8173@mail.gmail.com>

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%';

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




view thread (11+ messages)  latest in thread

Message-ID: <200902251241.40700@zmi.at>
Permalink:  ../200902251241.40700@zmi.at/
Also on:    postgresql.org/message-id/200902251241.40700@zmi.at

 · 

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-admin@postgresql.org
  Cc: michael.monnerie@is.it-management.at
  Subject: Re: "like" and index
  In-Reply-To: <200902251241.40700@zmi.at>

* 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