Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vi8RZ-00037z-9P for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2013 19:55:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vi8RY-0001wc-Ou for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Nov 2013 19:55:40 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vi8RW-0001wT-Mj for pgsql-bugs@postgresql.org; Sun, 17 Nov 2013 19:55:38 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vi8RS-00080s-Mq for pgsql-bugs@postgresql.org; Sun, 17 Nov 2013 19:55:37 +0000 Received: by mail-lb0-f181.google.com with SMTP id q8so2974662lbi.40 for ; Sun, 17 Nov 2013 11:55:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=/gsQIdjU7NcKCEHIOWDc5PDm5dDXw4Ajt/2utUVeBxY=; b=V9HfuyfiVNwLF91xSTxIwcZ0yBQkVJVVvxQBSpNMa4Py2WVcGd5T554gLK1G2nGxhr 0vLz5rQVDcsz95Cg40t2qjCfWuS1J0HgiGONALee9o+2hHztGxhLq9GYD68EBjA7hHns A936mo4fcSHCa0wrsKK1gmD0H1v762CaOeru7Evw4Kin+vn//4pnhcWhGzCmHixppunO dnAmOj0/myIrAMo2cdqpYLsrBTGPxKmIF2PqWJTmzsR1sQJiOlTG1vqYr1H8LSTJlYZt bxIJ3FXI2J8F63/isXEqe1q1LqNTMD+o1L57uMZoaijeRsMLTrAZYckaJsk4Pex4xv+q G9OQ== X-Gm-Message-State: ALoCoQm7l3cyJoSkaXzeERGZVWSJceKRaqeaM9EnvgKej1uQR7s7BQkM5aH/8nkVf1KmxU/FVCG8 X-Received: by 10.152.36.225 with SMTP id t1mr10870724laj.5.1384718132978; Sun, 17 Nov 2013 11:55:32 -0800 (PST) Received: from dalli.local (c-24a7e355.026-50-73746f15.cust.bredbandsbolaget.se. [85.227.167.36]) by mx.google.com with ESMTPSA id k3sm9844226lbs.0.2013.11.17.11.55.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 17 Nov 2013 11:55:31 -0800 (PST) Message-ID: <52891F32.8010902@joh.to> Date: Sun, 17 Nov 2013 20:55:30 +0100 From: Marko Tiikkaja User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: BUG #8598: Row count estimates of partial indexes References: <28474.1384705755@sss.pgh.pa.us> In-Reply-To: <28474.1384705755@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 On 11/17/13, 5:29 PM, Tom Lane wrote: > 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. Any suggestions for a workaround? When reading this index as a part of a bigger query the horrible estimate ensures that nobody's having fun. I currently have something like: SELECT * FROM (SELECT * FROM transactions WHERE LIMIT 25000) transactions JOIN .. And I *really* don't like that as a workaround. Regards, Marko Tiikkaja -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs