Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id D0EE79FB7A4 for ; Wed, 25 Jul 2007 03:18:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 05190-01 for ; Wed, 25 Jul 2007 03:18:17 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 73BBD9FB6FB for ; Wed, 25 Jul 2007 03:18:18 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IDaCK-0003Ol-RU for pgsql-performance@postgresql.org; Wed, 25 Jul 2007 08:18:12 +0200 Received: from port380.ds1-vbr.adsl.cybercity.dk ([212.242.125.201]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Jul 2007 08:18:12 +0200 Received: from nis by port380.ds1-vbr.adsl.cybercity.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Jul 2007 08:18:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: =?ISO-8859-1?Q?Nis_J=F8rgensen?= Subject: Re: Performance issue with 8.2.3 - "C" application Date: Wed, 25 Jul 2007 08:17:58 +0200 Lines: 40 Message-ID: References: <46A6A549.1040606@denninger.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: port380.ds1-vbr.adsl.cybercity.dk User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) In-Reply-To: <46A6A549.1040606@denninger.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/333 X-Sequence-Number: 26017 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