Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thomas H. wrote:
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


same result, have tried this as well (22sec). it's the LEFT JOIN shop.data_soundmedia for which the planer picks a seqscan instead of index scan, no matter what...

Two things to try:
1. "SET enable_seqscan = false" and see if that forces it. If not there's something very odd 2. Try adding a LIMIT 99 to the inner query (bar) so PG knows how many (few) rows will emerge.

I'm guessing we're up against PG's poor estimate on the '%...%' filter. If you were getting 160,000 rows in the final result then a seq-scan might well be the way to go.

The only workaround that I can think of (if we can't persuade the planner to cooperate) is to build a temp-table containing dvd_ean's for the first part of the query then analyse it and join against that. That way PG's row estimate will be accurate regardless of your text filtering.

--
  Richard Huxton
  Archonet Ltd


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux