From: | Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> |
---|---|
To: | Matthew Terenzio <mterenzio(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: tsearch2 query |
Date: | 2008-10-02 16:28:05 |
Message-ID: | Pine.LNX.4.64.0810022026080.15810@sn.sai.msu.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2 Oct 2008, Matthew Terenzio wrote:
> There are less than 20,000 records being searched here, but the query takes
> several minutes.
>
> I know this may not be enough info, but would one suggest I optimize the
> query or put my attention towards other areas.
>
>
> SELECT id,date,headline as head,headline(body,q),rank(vectors,q),timestamp
> FROM stories,to_tsquery('$query') AS q WHERE vectors @@ q ORDER BY $sort
> DESC OFFSET $offset LIMIT 20
>
This is common mistake, use subselect and you'll be happy.
Explanation:
headline() is very cost operation, so in your query you obtain headline()
for *ALL* results, while you need to do this only for 20 of them.
Feel the difference ?
Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru)
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83
From | Date | Subject | |
---|---|---|---|
Next Message | Oleg Bartunov | 2008-10-02 16:32:05 | Re: tsearch 2 query |
Previous Message | Martin Pitt | 2008-10-02 16:12:47 | Re: [Pkg-postgresql-public] Postgres major version support policy on Debian |