Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uVB2s-00Ep9H-3j for pgsql-general@arkaria.postgresql.org; Fri, 27 Jun 2025 15:31:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uVB2q-002tOX-6o for pgsql-general@arkaria.postgresql.org; Fri, 27 Jun 2025 15:31:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uVB2p-002tOP-55 for pgsql-general@lists.postgresql.org; Fri, 27 Jun 2025 15:31:16 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uVB2m-004Qdv-1L for pgsql-general@lists.postgresql.org; Fri, 27 Jun 2025 15:31:15 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id B529C140019A; Fri, 27 Jun 2025 11:31:09 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Fri, 27 Jun 2025 11:31:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1751038269; x=1751124669; bh=HR301Hsvy/quwYsrbgsSsqOggtRU3pOZEDSQkKyAqt4=; b= iH8+Dcrq5DgspxnaLu0xPkYsvkgeOR2XJzftdGJAbHqS7hLsB2bLWMbgb/eEkp8L 5HN8L5dUvOkEFIDtZu+c9zqATYZEt4M9mrQNJ/vnLdZEeNYtiSvYtiyDVnYwR7+S BN5p0BjcqrMrI8KvdMXp+M/BCEUmort+VTt8McPkaouXjOiHPLP38HY9+zD5SP4H x2r5/RJSVzNBYtmuYkCCT9v6MVkbGOityAs47Opo/AU8YiOMKC/EwsqWbXaBkbek uTOA4DemD9dx7ZvysmmdFfuBdNRQaaOX27jnRqCXWydo85ShmIMlyCGDb2CdAOyp Ovy42S0/6qn503gOiEzTdA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1751038269; x=1751124669; bh=H R301Hsvy/quwYsrbgsSsqOggtRU3pOZEDSQkKyAqt4=; b=Rycba4qDUMYXavymj V/t8yf+2nE1Mp0DUsCVc3NJV/J+QD4KeJoimMERVTkcki0gkklK7wb79+94Zo5iH nV+HXrdwDtML4/gK0j1mnXwYPxup3DZyJ9ZGgoFWcbg6Ka1q7zkJS8LrdU3/qALh yiSVM6+esl8hmz2rP4YkxgZ+grbfCLPS2cOMIPHQttTtJ7Qsx6O4MeTppG9VS6z1 VIHNNrxe9cEHy7NFsOm0IVqrwZckhAm5QJ/OkgJVBUbK2WVxXTzETYqHW2oR7/CW jI4yA2eOKVFnHde8llamTfcLFNxa84FjepDjAIuvnp2pr2GVdsrLJyBIBFMh1Xv1 Esm7g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdefgedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghnucfm lhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenuc ggtffrrghtthgvrhhnpeelgeevkeekkeeuiefgtdevieeluefhfedufeetkeejffekjeeu jeehgeehgeektdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtohepuggvrhgvkhdrshdriigvtghhmhgrnhesshhnrghp ohhnrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrph hoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Jun 2025 11:31:08 -0400 (EDT) Message-ID: <6add2a9a-7cf2-4d1b-8f3e-2e26a7ebe883@aklaver.com> Date: Fri, 27 Jun 2025 08:31:08 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: analyze-in-stages post upgrade questions To: "Zechman, Derek S" , "pgsql-general@lists.postgresql.org" References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/27/25 06:35, Zechman, Derek S wrote: > We recently performed an upgrade from pg14 (14.18) to pg16 (16.9) and > performed the analyze-in-stages post upgrade.  It has been noticed that > some plans changed to use hash joins instead of nested loops.  Further > investigation found it was because the parent table of partitioned > tables did not have stats.  After running an ANALYZE on the parent > tables we got similar plan an execution times as before. > > I have two questions > > 1 - Why does analyze-in-stages not analyze the parent tables? > > 2 – What happens if we do not run analyze-in-stages post upgrade and > just run an analyze? It is spelled out in the docs: https://www.postgresql.org/docs/current/pgupgrade.html Emphasis added "Using vacuumdb --all --analyze-only can efficiently generate such statistics, and the use of --jobs can speed it up. Option --analyze-in-stages can be used to generate **minimal statistics** quickly. If vacuum_cost_delay is set to a non-zero value, this can be overridden to speed up statistics generation using PGOPTIONS, e.g., PGOPTIONS='-c vacuum_cost_delay=0' vacuumdb ...." and from here: https://www.postgresql.org/docs/current/app-vacuumdb.html "--analyze-in-stages Only calculate statistics for use by the optimizer (no vacuum), like --analyze-only. Run three stages of analyze; the first stage uses the lowest possible statistics target (see default_statistics_target) to produce usable statistics faster, and subsequent stages build the full statistics. This option is only useful to analyze a database that currently has no statistics or has wholly incorrect ones, such as if it is newly populated from a restored dump or by pg_upgrade. Be aware that running with this option in a database with existing statistics may cause the query optimizer choices to become transiently worse due to the low statistics targets of the early stages. " > > Thanks, > > Sean > -- Adrian Klaver adrian.klaver@aklaver.com