Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vi5Du-0004Tb-Jo for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2013 16:29:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vi5Dt-0008L6-O1 for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2013 16:29:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vi5Ds-0008Kz-Nj for pgsql-bugs@postgresql.org; Sun, 17 Nov 2013 16:29:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vi5Dp-0007Ze-NF for pgsql-bugs@postgresql.org; Sun, 17 Nov 2013 16:29:20 +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 rAHGTFVB028475; Sun, 17 Nov 2013 11:29:15 -0500 From: Tom Lane To: marko@joh.to cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8598: Row count estimates of partial indexes In-reply-to: References: Comments: In-reply-to marko@joh.to message dated "Sun, 17 Nov 2013 12:58:18 +0000" Date: Sun, 17 Nov 2013 11:29:15 -0500 Message-ID: <28474.1384705755@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org marko@joh.to writes: > We have the following partial index on a small subset of a larger table: > "index_transactions_transaction_balance_details" btree (transactionid) > WHERE NOT processed AND accountbalancesdailyid IS NOT NULL > However, querying with the WHERE clause completely ignores the > pg_class.reltuples value for the index: Yup. Row count estimates are derived by estimating the selectivity of the given WHERE clauses and multiplying by the (estimated) current table size. In the particular case you show here, with a partial index that *exactly* matches the WHERE clause, we could get a better answer by looking at the index size --- but that doesn't scale to any less simplistic case, such as a query with additional WHERE clauses. It's also important to realize that reltuples for an index is a whole lot less trustworthy than it is for a table; ANALYZE doesn't update the former, for example. And scaling from the last-reported VACUUM stats to current reality is going to be shakier. So on the whole, I don't think this would be a good idea. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs