tsearch query question

From: roy simkes <roy(at)parkyeri(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: tsearch query question
Date: 2007-08-24 14:18:27
Message-ID: 46CEE8B3.4090903@parkyeri.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

SELECT contentid, title, (rank(to_tsvector(body),q) +
rank(to_tsvector(title),q) + rank(to_tsvector(subtitle),q)) AS Score
FROM content, to_tsquery('parkyeri') AS q
WHERE statusid = 1
AND ispublished = 1
AND (to_tsvector(body) @@ q
OR to_tsvector(title) @@ q
OR to_tsvector(subtitle) @@ q )
ORDER BY Score

I have such a query. I'm not very sure if it will work but that's not
the part of the question. As you see I'm using a lot to_tsvector()
function. Which I believe it will not be good for the performance. So I
thought changing my query to something like this:

SELECT contentid, title, (rank(fts_body, q) + rank(fts_title,q) +
rank(fts_subtitle,q) ) AS Score
FROM content,
to_tsquery('search & string') AS q,
to_tsvector(body) AS fts_body,
to_tsvector(title) AS fts_title,
to_tsvector(subtitle) AS fts_subtitle
WHERE statusid = 1
AND ispublished = 1
AND ( fts_body @@ q
OR fts_title @@ q
OR fts_subtitle @@ q )
ORDER BY Score

So when I have changed to this, will the to_tsvector part will be
available for every row? Or will it be just computed once? I mean in the
first query where part is executed for every row, so I'm sure that it
will be evaluated for all the rows. But when I put that in the from part
will it compute the value once and will use the same value for all the
where clauses? If that's the case what will be the value of fts_body?
The tsvector of every row's data or just one row's data?

thank you for your time and patience

roy simkes

note: I had posted the same question a week ago too, but I think it's
missing. I'm sorry if it's already posted and I'm double posting.

Browse pgsql-general by date

  From Date Subject
Next Message Lee Keel 2007-08-24 14:41:15 Re: [OT - sorta] How to extract a substring using Regex
Previous Message Gregory Stark 2007-08-24 14:02:32 Re: FATAL: could not reattach to shared memory (Win32)