Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id CB2E29FB6D9 for ; Wed, 6 Jun 2007 06:22:11 -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 11169-06 for ; Wed, 6 Jun 2007 06:22:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id 0EA659FB697 for ; Wed, 6 Jun 2007 06:22:06 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1HvriJ-000122-Js; Wed, 06 Jun 2007 10:21:59 +0100 From: Gregory Stark To: "weiping" Cc: Subject: Re: different query plan because different limit # (Re: weird query plan) In-Reply-To: <46666128.7050500@pgsqldb.com> (laserlist@pgsqldb.com's message of "Wed, 06 Jun 2007 15:24:24 +0800") Organization: EnterpriseDB References: <46662DE7.4030602@pgsqldb.com> <46663114.3000501@pgsqldb.com> <46666128.7050500@pgsqldb.com> X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.performance" 835) Date: Wed, 06 Jun 2007 10:21:59 +0100 Message-ID: <87ejkph1zc.fsf@oxford.xeocode.com> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/91 X-Sequence-Number: 25124 "weiping" writes: > -> Index Scan using urlusermaps_userid on wd_urlusermaps > (cost=0.00..6750.55 rows=1094 width=4) (actual time=1.478..16.563 rows=41 loops=1) > Index Cond: (userid = 219177) > Filter: ("share" = 1) It's estimating 1094 rows and getting 41 rows. You might considering raising the statistics target for that table. Does it get accurate estimates for the number of rows for each of these? explain analyze select * from wd_urlusermaps where userid=219177 explain analyze select * from wd_urlusermaps where share=1 (the latter might take a while) -- Gregory Stark EnterpriseDB http://www.enterprisedb.com