Re: tsearch2 poor performance - Mailing list pgsql-admin

From George Essig
Subject Re: tsearch2 poor performance
Date
Msg-id 20040928134803.88842.qmail@web53705.mail.yahoo.com
Whole thread Raw
In response to tsearch2 poor performance  (Kris Kiger <kris@musicrebellion.com>)
List pgsql-admin
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

pgsql-admin by date:

Previous
From: "Thomas Madsen"
Date:
Subject: Vacuum full - disk space eaten by WAL logfiles
Next
From: "CHRIS HOOVER"
Date:
Subject: Help determining values for max_fsm_pages, max_fsm_relations