pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: George Essig <george_essig@yahoo.com>
To: Kris Kiger <kris@musicrebellion.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: tsearch2 poor performance
Date: Tue, 28 Sep 2004 06:48:03 -0700 (PDT)
Message-ID: <20040928134803.88842.qmail@web53705.mail.yahoo.com> (raw)

Kris Kiger wrote:

> search_test=#  explain analyze SELECT count(q) FROM product, 
> to_tsquery('oil') AS q  WHERE vector @@ q;
>                                                             QUERY PLAN
>  
---------------------------------------------------------------------------------------------------------------------------------
>  Aggregate  (cost=67847264.50..67847264.50 rows=1 width=32) (actual 
> time=83311.552..83311.555 rows=1 loops=1)
>    ->  Nested Loop  (cost=12.50..67839764.50 rows=3000001 width=32) 
> (actual time=0.204..81960.198 rows=226357 loops=1)
>          Join Filter: ("outer".vector @@ "inner".q)
>          ->  Seq Scan on product  (cost=0.00..339752.00 rows=3000000 
> width=32) (actual time=0.100..27415.795 rows=3000000 loops=1)
>          ->  Materialize  (cost=12.50..22.50 rows=1000 width=32) (actual 
> time=0.003..0.006 rows=1 loops=3000000)
>                ->  Function Scan on q  (cost=0.00..12.50 rows=1000 
> width=32) (actual time=0.020..0.024 rows=1 loops=1)
>  Total runtime: 83311.735 ms
> (7 rows)

The explain analyze output doesn't show that a gist index on the vector column is being used. 
This is because either you don't have an index defined and\or the query is causing a poor plan to
be chosen.  I've found that putting to_tsquery in the FROM clause does not execute fast.

Try rewriting the query as:

explain analyze SELECT count(to_tsquery('oil')) FROM product  WHERE vector @@ to_tsquery('oil');

or

explain analyze SELECT count(*) FROM product WHERE vector @@ to_tsquery('oil');

George Essig



view thread (18+ messages)  latest in thread

Message-ID: <20040928134803.88842.qmail@web53705.mail.yahoo.com>
Permalink:  ../20040928134803.88842.qmail@web53705.mail.yahoo.com/
Also on:    postgresql.org/message-id/20040928134803.88842.qmail@web53705.mail.yahoo.com

 · 

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-admin@postgresql.org
  Cc: george_essig@yahoo.com, kris@musicrebellion.com
  Subject: Re: tsearch2 poor performance
  In-Reply-To: <20040928134803.88842.qmail@web53705.mail.yahoo.com>
  References: <20040928134803.88842.qmail@web53705.mail.yahoo.com>

* 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