Re: SeqScan with full text search - Mailing list pgsql-performance

From Віталій Тимчишин
Subject Re: SeqScan with full text search
Date
Msg-id CABWW-d2YQHQn7vZwxJTVJ1xjhZa+Y9R5t3auE+w9QSjJHG7wVg@mail.gmail.com
Whole thread Raw
In response to SeqScan with full text search  (Tomek Walkuski <tomek.walkuski@gmail.com>)
List pgsql-performance


2012/4/16 Tomek Walkuski <tomek.walkuski@gmail.com>
Hello group!

I have query like this:

SELECT
 employments.candidate_id AS candidate_id,
 SUM(TS_RANK(employers.search_vector, TO_TSQUERY('simple', 'One:* |
Two:* | Three:* | Four:*'), 2)) AS ts_rank
FROM
 employments
INNER JOIN
 employers ON employments.employer_id = employers.id
AND
 employers.search_vector @@ TO_TSQUERY('simple', 'One:* | Two:* |
Three:* | Four:*')
GROUP BY
 candidate_id;

And it results with this:

http://explain.depesz.com/s/jLM

The JOIN between employments and employers is the culprit. I'm unable
to get rid of the seq scan, and setting enable_seqscan to off makes
things even worse.

Is there any way to get rid of this JOIN?


Have you got an index on employments.employer_id? It seems for me that only some employments get out of join, so index would help here. What's the plan with seq_scan off?

P.S. I don't see why all employments are needed. May be I am reading something wrong? For me it's max 2616 employments out of 1606432.

Best regards, Vitalii Tymchyshyn

--
Best regards,
 Vitalii Tymchyshyn

pgsql-performance by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: SeqScan with full text search
Next
From: Scott Marlowe
Date:
Subject: Re: H800 + md1200 Performance problem