Karl Denninger skrev: > I've got an interesting issue here that I'm running into with 8.2.3 > > This is an application that has run quite well for a long time, and has > been operating without significant changes (other than recompilation) > since back in the early 7.x Postgres days. But now we're seeing a LOT > more load than we used to with it, and suddenly, we're seeing odd > performance issues. > > It APPEARS that the problem isn't query performance per-se. That is, > while I can find a few processes here and there in a run state when I > look with a PS, I don't see them consistently churning. > > But.... here's the query that has a habit of taking the most time.... > > select forum, * from post where toppost = 1 and (replied > (select > lastview from forumlog where login='theuser' and forum=post.forum and > number is null)) is not false AND (replied > (select lastview from > forumlog where login='theuser' and forum=post.forum and > number=post.number)) is not false order by pinned desc, replied desc offset 0 > limit 20
Since I can do little to help you with anything else, here is a little help from a guy with a hammer. It seems you may be able to convert the subqueries into a left join. Not sure whether this helps, nor whether I got some bits of the logic wrong, but something like this might help the planner find a better plan: SELECT forum, * FROM post LEFT JOIN forumlog ON post.forum = forumlog.forum AND forumlog.login = 'theuser' AND (post.number = forumlog.number OR forumlog.number IS NULL) AND post.replied <= lastview WHERE forumlog.forum IS NULL AND forum.toppost = 1 ORDER BY pinned DESC, replied DESC OFFSET 0 LIMIT 20 ; Nis ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match