Previous   Next 

Tsearch2 README File Example: Overview (Continued)

Because an index has not been defined, the previous query is searching using a sequential scan over each row. This will be slow for large tables.

VACUUM FULL ANALYZE;

EXPLAIN ANAYLZE 
SELECT *, rank(ts_vec, to_tsquery('default', 'database | query'))
FROM ts_readme
WHERE ts_vec @@ to_tsquery('default', 'database | query')
ORDER BY rank(ts_vec, to_tsquery('default', 'database | query')) DESC
LIMIT 5;

						QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Limit  (cost=7.64..7.64 rows=1 width=89) (actual time=0.440..0.455 rows=5 loops=1)
->  Sort  (cost=7.64..7.64 rows=1 width=89) (actual time=0.435..0.440 rows=5 loops=1)
	Sort Key: rank(ts_vec, '\'databas\' | \'queri\''::tsquery)
	->  Seq Scan on ts_readme  (cost=0.00..7.63 rows=1 width=89) (actual time=0.117..0.391 rows=11 loops=1)
		Filter: (ts_vec @@ '\'databas\' | \'queri\''::tsquery)
Total runtime: 0.516 ms