pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: The Hermit Hacker <scrappy@hub.org>
To: pgsql-sql@postgresql.org
Subject: [7.0.3] optimizing a LIKE query ...
Date: Wed, 4 Apr 2001 11:59:47 -0300 (ADT)
Message-ID: <Pine.BSF.4.33.0104041156540.81918-100000@mobile.hub.org> (raw)


Can someone suggest how to improve the following query, so as to make the
LIKE section operate on the results found by the = one?

SELECT ndict.url_id,ndict.intag
  FROM ndict,url
 WHERE ndict.word_id=-720551816
   AND url.rec_id=ndict.url_id
   AND ((url.url || '') LIKE '%http://www.postgresql.org/%%';)

ndict.word_id=-720551816 returns 5895 records

((url.url || '') LIKE '%http://www.postgresql.org/%%';)
	- returns 138k records

explain shows:

NOTICE:  QUERY PLAN:

Hash Join  (cost=10163.01..26647.09 rows=42 width=12)
  ->  Index Scan using n_word on ndict  (cost=0.00..16299.52 rows=4180 width=8)
  ->  Hash  (cost=10159.53..10159.53 rows=1390 width=4)
        ->  Seq Scan on url  (cost=0.00..10159.53 rows=1390 width=4)

EXPLAIN


I'm figuring that if I can somehow get the query (using subselects,
maybe?), to have the LIKE part of the query work only on the 6k records
returned by the "=" part of it, the overall results should be faster ...

Possible?


Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org




view thread (2+ messages)  latest in thread

Message-ID: <Pine.BSF.4.33.0104041156540.81918-100000@mobile.hub.org>
Permalink:  ../Pine.BSF.4.33.0104041156540.81918-100000@mobile.hub.org/
Also on:    postgresql.org/message-id/Pine.BSF.4.33.0104041156540.81918-100000@mobile.hub.org

 · 

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-sql@postgresql.org
  Cc: scrappy@hub.org
  Subject: Re: [7.0.3] optimizing a LIKE query ...
  In-Reply-To: <Pine.BSF.4.33.0104041156540.81918-100000@mobile.hub.org>
  References: <Pine.BSF.4.33.0104041156540.81918-100000@mobile.hub.org>

* 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