Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id C6A4F9FB919 for ; Tue, 24 Jul 2007 23:46:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 75086-03 for ; Tue, 24 Jul 2007 23:46:00 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1CD589FA133 for ; Tue, 24 Jul 2007 23:46:00 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l6P2jwYe029634; Tue, 24 Jul 2007 22:45:58 -0400 (EDT) To: Karl Denninger cc: pgsql-performance@postgresql.org Subject: Re: Performance issue with 8.2.3 - "C" application In-reply-to: <46A6A549.1040606@denninger.net> References: <46A6A549.1040606@denninger.net> Comments: In-reply-to Karl Denninger message dated "Tue, 24 Jul 2007 20:20:09 -0500" Date: Tue, 24 Jul 2007 22:45:58 -0400 Message-ID: <29633.1185331558@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/327 X-Sequence-Number: 26011 Karl Denninger writes: > 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 f > alse order by pinned desc, replied desc offset 0 limit 20 Did that ever perform well for you? It's the sub-selects that are likely to hurt ... in particular, > -> Index Scan using post_top on post (cost=0.00..57266.37 > rows=113 width=757) > Index Cond: (toppost = 1) > Filter: (((replied > (subplan)) IS NOT FALSE) AND > ((replied > (subplan)) IS NOT FALSE)) versus > Index Scan using post_top on post (cost=0.00..632.03 rows=1013 width=11) > Index Cond: (toppost = 1) The planner thinks that the two subplan filter conditions will eliminate about 90% of the rows returned by the bare indexscan (IIRC this is purely a rule of thumb, not based on any statistics) and that testing them 1013 times will add over 50000 cost units to the basic indexscan. That part I believe --- correlated subqueries are expensive. regards, tom lane