X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9F3F5D1CACC for ; Fri, 6 Feb 2004 22:37:51 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 33912-06 for ; Fri, 6 Feb 2004 18:37:51 -0400 (AST) Received: from davinci.ethosmedia.com (server228.ethosmedia.com [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 11381D1B45B for ; Fri, 6 Feb 2004 18:37:49 -0400 (AST) Received: from [63.195.55.98] (HELO 192.168.1.29) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 4383941; Fri, 06 Feb 2004 14:38:54 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Karl Denninger , pgsql-performance@postgresql.org Subject: Re: Why is query selecting sequential? Date: Fri, 6 Feb 2004 14:36:57 -0800 User-Agent: KMail/1.5.4 References: <20040206153602.B4910@Denninger.Net> <200402061351.39084.josh@agliodbs.com> <20040206162232.D4910@Denninger.Net> In-Reply-To: <20040206162232.D4910@Denninger.Net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402061436.57903.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/103 X-Sequence-Number: 5627 Karl, Well, still with only 5 rows in the forumlog table you're not going get realistic results compared to a loaded database. However, you are making things difficult for the parser with awkward query syntax; what you currently have encourages a sequential loop. If there are potentially several rows in forumlog for each row in post, then your query won't work either. > akcs=> explain analyze select forum, (replied > (select lastview from forumlog where forumlog.login='genesis' and forumlog.forum='General' and number=post.number)) as newflag, * from post where forum = 'General' and toppost = 1 order by pinned desc, replied desc; Instead: if only one row in forumlog per row in post: SELECT (replied > lastview) AS newflag, post.* FROM post, forumlog WHERE post.forum = 'General' and toppost = 1 and forumlog.login = 'genesis' and forumlog.forum='General' and forumlog.number=post.number; -- -Josh Berkus Aglio Database Solutions San Francisco