Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXWV6-0000Dg-9f for pgsql-performance@arkaria.postgresql.org; Tue, 08 Apr 2014 13:55:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WXWV5-00025f-NS for pgsql-performance@arkaria.postgresql.org; Tue, 08 Apr 2014 13:55:43 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXWV4-00024L-Bp for pgsql-performance@postgresql.org; Tue, 08 Apr 2014 13:55:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXWV1-0005hc-Lr for pgsql-performance@postgresql.org; Tue, 08 Apr 2014 13:55:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s38Dtcaa023515; Tue, 8 Apr 2014 09:55:38 -0400 From: Tom Lane To: "Andrew W. Gibbs" cc: pgsql-performance@postgresql.org Subject: Re: query against large table not using sensible index to find very small amount of data In-reply-to: <20140408124835.GA5618@raptor.commandosoftware.com> References: <20140408124835.GA5618@raptor.commandosoftware.com> Comments: In-reply-to "Andrew W. Gibbs" message dated "Tue, 08 Apr 2014 08:48:35 -0400" Date: Tue, 08 Apr 2014 09:55:38 -0400 Message-ID: <23514.1396965338@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org "Andrew W. Gibbs" writes: > A very common query against this table is of the form... > SELECT * FROM events WHERE entity_type_id = XXX ORDER BY published_at DESC LIMIT 25; > ... to get the most recent 25 events from the table for a given type > of entity, and generally the query planner does the expected thing of > using the two-part index on (entity_type_id, published_at). Every now > and again, though, I have found the query planner deciding that it > ought use the single column (published_at) index. What is the estimated rows count according to EXPLAIN when it does that, versus when it chooses the better plan? > FWIW, we're running on 8.4.X and using the out-of-the-box > default_statistics_target setting and haven't dabbled with setting > table level statistics configurations. 8.4.X is due to reach EOL in July, so you really ought to be thinking about an upgrade. It's not clear from the given info whether this issue is fixable with stats configuration adjustments, is a bug already fixed in later versions, or neither, but we're unlikely to make any significant changes in the 8.4 planner code at this point... regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance