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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to