pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hamann.w@t-online.de
To: pgsql-general@postgresql.org
Subject: optimize query?
Date: Wed, 30 Jan 2013 12:33:17 +0100
Message-ID: <510904FD.mailx3XR19NPI6@amadeus3.local> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

Hi,

I am trying to match items from 2 tables based on a common string.
One is a big table which has one column with entries like XY123, ABC44, etc
The table has an index on that column.
The second table is, typically, much smaller

select .... from tab1, tab2 where tab1.code = tab2.code;

This works fine and fast.
Now, as a variant, I have some entries like XY423A, XY423B, GF55A, GF55D in the
big table and want them to match XY423, GF55 in the second table

Variants I have tried

select  .... from tab1, tab2 where tab1.code ~ (tab2.code||'($|[A-Z])');
select  .... from tab1, tab2 where tab1.code ~ ('^'||tab2.code||'($|[A-Z])');

both take an enormous time. In the better case that I can subset (e.g. all candidates in table 2
share initial "AX") I get back to manageable times by adding
  and tab1.code ~ '^AX'
into the recipe. Actual runtime with about a million entries in tab1 and 800 entries in tab2
is about 40 seconds.

Regards
Wolfgang Hamann



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



view thread (14+ messages)  latest in thread

Message-ID: <510904FD.mailx3XR19NPI6@amadeus3.local>
Permalink:  ../510904FD.mailx3XR19NPI6@amadeus3.local/
Also on:    postgresql.org/message-id/510904FD.mailx3XR19NPI6@amadeus3.local

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hamann.w@t-online.de
  Subject: Re: optimize query?
  In-Reply-To: <510904FD.mailx3XR19NPI6@amadeus3.local>
  References: <510904FD.mailx3XR19NPI6@amadeus3.local>

* 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