Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZZnHG-0003CE-9P for pgsql-performance@arkaria.postgresql.org; Wed, 09 Sep 2015 21:51:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZZnHF-0006ja-MH for pgsql-performance@arkaria.postgresql.org; Wed, 09 Sep 2015 21:51:37 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZZnHE-0006jP-S4 for pgsql-performance@postgresql.org; Wed, 09 Sep 2015 21:51:37 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZZnHC-0000km-72 for pgsql-performance@postgresql.org; Wed, 09 Sep 2015 21:51:35 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1ZZnHB-0001yf-7s; Wed, 09 Sep 2015 17:51:33 -0400 Date: Wed, 9 Sep 2015 17:51:33 -0400 From: Bruce Momjian To: Jeff Janes Cc: Nicolas Paris , pgsql-performance Subject: Re: pg_stat_all_indexes understand Message-ID: <20150909215133.GE16463@momjian.us> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) 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 On Thu, Jul 9, 2015 at 09:45:25AM -0700, Jeff Janes wrote: > > On Thu, Jul 9, 2015 at 5:20 AM, Nicolas Paris wrote: > > Hello, > > I wonder how understanding pg_stat_all_indexes working > > When I run an explain, some index are not used, but > pg_stat_all_indexes.idx_scan is incremented for those indexes. > > > When the planner considers using a merge join on a indexed column, it uses an > index to check the endpoints of the column (the min and the max) to make sure > it has the latest values to get the most accurate estimate.  This causes the > usage counts to get incremented.  Even when it doesn't end up using the merge > join. And it will be documented in 9.5: commit 7e9ed623d9988fcb1497a2a8ca7f676a5bfa136f Author: Bruce Momjian Date: Thu Mar 19 22:38:12 2015 -0400 docs: mention the optimizer can increase the index usage count Report by Marko Tiikkaja + The optimizer also accesses indexes to check for supplied constants + whose values are outside the recorded range of the optimizer statistics + because the optimizer statistics might be stale. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance