Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id F3F3864FC15 for ; Tue, 23 Sep 2008 23:58:16 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 90016-07 for ; Tue, 23 Sep 2008 23:58:13 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 2275864FC0D for ; Tue, 23 Sep 2008 23:58:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m8O2wAC7017588; Tue, 23 Sep 2008 22:58:10 -0400 (EDT) To: Einars cc: pgsql-performance@postgresql.org Subject: Re: Chaotically weird execution plan In-reply-to: <4f8bd5c90809231753xbcdacd2xfba4d38c2eb34faf@mail.gmail.com> References: <4f8bd5c90809231753xbcdacd2xfba4d38c2eb34faf@mail.gmail.com> Comments: In-reply-to Einars message dated "Wed, 24 Sep 2008 03:53:49 +0300" Date: Tue, 23 Sep 2008 22:58:10 -0400 Message-ID: <17587.1222225090@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200809/207 X-Sequence-Number: 31520 Einars writes: > When displaying information about information about an user in our > site, I noticed an unreasonable slowdown. The culprit turned out to be > a trivial select, which determines the number of comments left by an > user: I don't see anything even slightly wrong here. Your first example pulls 15888 rows from the table in 13134 ms. Your second example pulls 3 rows from the table in 0.121 ms --- which I rather imagine is because those three rows are already in cache; it would take a lot longer if it actually had to go to disk several times. The planner's rowcount estimates are on target and it appears to be choosing appropriate plans in each case. It just takes longer to process 5000 times as many rows ... regards, tom lane