Re: planer picks a bad plan (seq-scan instead of index)

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Thomas H(dot)" <me(at)alternize(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: planer picks a bad plan (seq-scan instead of index)
Date: 2006-11-09 12:12:38
Message-ID: 45531B36.7030005@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thomas H. wrote:
>> Try putting your conditions as part of the join:
>> SELECT * FROM shop.dvds
>> LEFT JOIN
>> oldtables.movies
>> ON
>> mov_id = dvd_mov_id
>> AND (
>> lower(mov_name) LIKE '%superman re%'
>> OR lower(dvd_name) like '%superman re%'
>> OR lower(dvd_edition) LIKE '%superman re%'
>> )
>> LEFT JOIN shop.data_soundmedia ON sm_info_ean = dvd_ean
>
> unfortunately its getting optimized into the same plan :-)

OK - in that case try explicit subqueries:

SELECT ... FROM
(SELECT * FROM shop.dvds
LEFT JOIN shop.oldtables.movies
WHERE lower(mov_name) LIKE ...
) AS bar
LEFT JOIN shop.data_soundmedia

>> I'd also be tempted to look at a tsearch2 setup for the word searches.
>
>
> tsearch2 doesn't work that well for exact matches (including special
> chars). but the culprit here isn't the '%...'%' seqscan, but rather the
> additional joined table (where no lookup except for the join-column
> takes place) that makes the query going from 200ms to 24sec.

Agreed, but I'd still be inclined to let tsearch do a first filter then
limit the results with LIKE.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeremiasz Miedzinski 2006-11-09 12:15:26 [PL/pgSQL] How should I use FOUND special variable. Documentation is little unclear for me
Previous Message Anton Melser 2006-11-09 12:12:29 Re: autovacuum blues