Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g068c-0000SJ-6V for pgsql-admin@arkaria.postgresql.org; Wed, 12 Sep 2018 14:29:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g068Y-0003HQ-Fr for pgsql-admin@arkaria.postgresql.org; Wed, 12 Sep 2018 14:28:58 +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.89) (envelope-from ) id 1g068Y-0003HJ-51 for pgsql-admin@lists.postgresql.org; Wed, 12 Sep 2018 14:28:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g068Q-00060b-6f for pgsql-admin@postgresql.org; Wed, 12 Sep 2018 14:28:56 +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 w8CESl9n002419; Wed, 12 Sep 2018 10:28:47 -0400 From: Tom Lane To: MirrorX cc: pgsql-admin@postgresql.org Subject: Re: vacuum and query plans? In-reply-to: <1536759109470-0.post@n3.nabble.com> References: <1536759109470-0.post@n3.nabble.com> Comments: In-reply-to MirrorX message dated "Wed, 12 Sep 2018 06:31:49 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2417.1536762527.1@sss.pgh.pa.us> Date: Wed, 12 Sep 2018 10:28:47 -0400 Message-ID: <2418.1536762527@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk MirrorX writes: > i ve seen lately more and more occurences of queries having huge planning > times (>500ms) while their execution time is very low (<10ms). at that > point, if a vacuum is executed on the table involved (without analyze) then > the planning time goes back to 'normal'. could someone elaborate on the > connection between planning time and what vacuum does? i am asking bc i > would have thought that an analyze would have resolved the issue (with > increased sampling for example) but it didnt. only vacuum does resolve it. > (the version is 9.4.x) I'm leaping to a conclusion from insufficient data here, but: what this sounds like is a known issue where the planner spends too much time trying to identify the current minimum or maximum value of a column by searching an index for that column. In principle that should be quick, but if there are a whole lot of recently-dead entries at the relevant end of the index, it's not quick. VACUUM fixes it by removing said entries. We've gone through a couple rounds of refinement to improve that situation, but the most recent one is only in v11 not prior branches: https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=3ca930fc3 regards, tom lane