pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Trutwin <josh@trutwins.homeip.net>
To: pgsql-sql@postgresql.org
Subject: Re: Alternative to INTERSECT
Date: Tue, 31 Jul 2007 13:52:22 -0500
Message-ID: <20070731135222.394da3dd@sinkhole.intrcomm.net> (raw)
In-Reply-To: <200707311730.51280.andreak@officenet.no>
References: <200707311730.51280.andreak@officenet.no>

On Tue, 31 Jul 2007 17:30:51 +0000
Andreas Joseph Krogh <andreak@officenet.no> wrote:

> Hi all. I have the following schema:
> 
> CREATE TABLE test (
>     id integer NOT NULL,
>     field character varying NOT NULL,
>     value character varying NOT NULL
> );
> 
> ALTER TABLE ONLY test
>     ADD CONSTRAINT test_id_key UNIQUE (id, field, value);
> 
> CREATE INDEX test_like_idx ON test USING btree (id, field, value 
> varchar_pattern_ops);
> 
> Using INTERSECT I want to retrieve the rows matching (pseudo-code)
> "firstname LIKE ('andrea%' OR 'jose%') AND lastname LIKE 'kro%'"

Why not:

WHERE (t.field = lastname AND t.value LIKE 'kro%')
   OR (t.field = firsname AND (
       t.value LIKE 'jose%' OR t.value LIKE 'andrea%')
       )

Not tested.  If you're having performance problems is probably less
like that the INTERSECT is the problem with all those LIKE's in
there?  Is t.value indexed?

Josh



view thread (6+ messages)  latest in thread

Message-ID: <20070731135222.394da3dd@sinkhole.intrcomm.net>
Permalink:  ../20070731135222.394da3dd@sinkhole.intrcomm.net/
Also on:    postgresql.org/message-id/20070731135222.394da3dd@sinkhole.intrcomm.net

 · 

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-sql@postgresql.org
  Cc: josh@trutwins.homeip.net
  Subject: Re: Alternative to INTERSECT
  In-Reply-To: <20070731135222.394da3dd@sinkhole.intrcomm.net>

* 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