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 1uVGn5-00GDaF-R8 for pgsql-general@arkaria.postgresql.org; Fri, 27 Jun 2025 21:39:23 +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 1uVGn3-004kLF-9Y for pgsql-general@arkaria.postgresql.org; Fri, 27 Jun 2025 21:39:21 +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 1uVGn2-004kL7-UB for pgsql-general@lists.postgresql.org; Fri, 27 Jun 2025 21:39:21 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uVGn1-004TTJ-0O for pgsql-general@lists.postgresql.org; Fri, 27 Jun 2025 21:39:21 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3a522224582so1312244f8f.3 for ; Fri, 27 Jun 2025 14:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1751060358; x=1751665158; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=TUWC+Tmaeokh0O994b5ZE9PhvQ6qM/gxpOs07iDe2rU=; b=Ele7nz3qh9cEdXK3X/ZA6wt+WER9qOXCN2cjagRMQ9AjgFnddflH3ZSpFYZoJXA9NY FiUC6X7RD4SHuksm5BE8PNW+5pzTwKmP9/pPiDiHXiPlnN4/CQDGt4pD/doYxwb5MxUO xOxMBYWcqy6lvQq/YVruN7NfvQsr2fSu/5VzB3j8zQUkZQZpvFAWCfmw+INgzfM93cKr G4Zq0eamLwhrAV6d9Cd/lCSrinnGc6UnURcy0qsmO1mUxXxLpOEaLHrQ3gp6XJ0tY4ED ZbCD+DMrkF8ldX3znhcCFpiy/Pd4DKEZPS2m33JB3jQZTgZMTR7lU1nESJODKj5oWBnw U/Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751060358; x=1751665158; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TUWC+Tmaeokh0O994b5ZE9PhvQ6qM/gxpOs07iDe2rU=; b=IrfqUsBMIr9Xo+UnQK3k8p93Fs9wDeE5ZLFQVulJ9dNsoDSiS82ddxcbpt6FxPx8tm 31ICb4vfanymfBRbkdjnHg85xGV+b2Uz046uRXZzk1a5VDRbEcsmVnkHoUN0XgZEaEHP yKHkQWMa3sblGzqixrAIyS+nZH+GlHoZHsFhG/OC7lfI2KMBO74KE9AnB0V/z0d9cLWV YlVc8km0UMgMabJuPCITnC0j9ZfzWPWEZEOntmShy2hXYtn5vWKg7IakGgxOL+yfi7H0 6/EU8vN7Mi1/h30115XZgsTj1nK4b9y3BP9eOdw01NlOsar9n5E3J0tFkck9guxzz4lM JXtg== X-Forwarded-Encrypted: i=1; AJvYcCWZjmrfeI2zNDug12CKQenqWcheAw/8JibqE6K+C6crd94zt9LLn1r7eEvIkGeeW4hHPOEp83rN3hE5vxnP@lists.postgresql.org X-Gm-Message-State: AOJu0YynAKtSkgtMFvP17ZRY128K5iSSRw4x8RorYi+Ar4wBPOV+LQ91 1DQHqWwm9M2DPeClntROodw2V9pjALf8+IZwsQJBVkUp7bWE1EeYzmvmwbZM1g+v4cThC0IuxO/ 9wUbKOEs= X-Gm-Gg: ASbGncsON15i22anCzhR1q1GqYOq7ylggGzg2oOJFhPEi4d5TXWpT3ddtnusNAI/R56 bY9dPNaxGRAKX/bjWPF376bzYbE8hwxXRm5LIyDuYBu2mr8DDhA0niJ8pqmnZyMzFHrBlurTP+U hcKsqDH848PMFapMdl7VjBfBxxSOXFoYcL9S8NKTqhGOej3v0ZbNl4//ss5f48TCCjkcynoCcSf LLtdWHn6yDAflpaY/fAIxWLkceJFvXLQNdwBcXq4xNUHxFLJAzIPYPA8bUngyTX/bFF9BNkSdns x4zTFcXO0/eN3EJZ6ORjMwVdsMmR/2WJVfCdkW/g/KSvLFawq72dcbfAhIgQ3sIlMe5FeSOCFLm JkFbziPweNCH/ogEurCuK6Ca4J5qTGxyXhOwmmBQh0b+GAg== X-Google-Smtp-Source: AGHT+IG7ylo557HDEo79QFqu6bvpZ4hU0st2TBKlo3NOIN3rsrv1DDwZugj4eL77DoZrPTwfyQZ5cg== X-Received: by 2002:adf:9cc9:0:b0:3a3:67bb:8f3f with SMTP id ffacd0b85a97d-3a902f70a1cmr4267287f8f.53.1751060358101; Fri, 27 Jun 2025 14:39:18 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D (31-10-149-38.cgn.dynamic.upc.ch. [31.10.149.38]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4538a423abbsm63053135e9.39.2025.06.27.14.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jun 2025 14:39:17 -0700 (PDT) Message-ID: <4d8122febd3007143504e4b6034b4253f7000761.camel@cybertec.at> Subject: Re: analyze-in-stages post upgrade questions From: Laurenz Albe To: Adrian Klaver , "Zechman, Derek S" , "pgsql-general@lists.postgresql.org" Date: Fri, 27 Jun 2025 23:39:17 +0200 In-Reply-To: <6add2a9a-7cf2-4d1b-8f3e-2e26a7ebe883@aklaver.com> References: <6add2a9a-7cf2-4d1b-8f3e-2e26a7ebe883@aklaver.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-1.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2025-06-27 at 08:31 -0700, Adrian Klaver wrote: > On 6/27/25 06:35, Zechman, Derek S wrote: > > We recently performed an upgrade from pg14 (14.18) to pg16 (16.9) and= =20 > > performed the analyze-in-stages post upgrade.=C2=A0 It has been noticed= that=20 > > some plans changed to use hash joins instead of nested loops.=C2=A0 Fur= ther=20 > > investigation found it was because the parent table of partitioned=20 > > tables did not have stats.=C2=A0 After running an ANALYZE on the parent= =20 > > tables we got similar plan an execution times as before. > >=20 > > I have two questions > >=20 > > 1 - Why does analyze-in-stages not analyze the parent tables? > >=20 > > 2 =E2=80=93 What happens if we do not run analyze-in-stages post upgrad= e and=20 > > just run an analyze? >=20 > It is spelled out in the docs: >=20 > https://www.postgresql.org/docs/current/pgupgrade.html >=20 > Emphasis added >=20 > "Using vacuumdb --all --analyze-only can efficiently generate such=20 > statistics, and the use of --jobs can speed it up. Option=20 > --analyze-in-stages can be used to generate **minimal statistics**=20 > quickly. If vacuum_cost_delay is set to a non-zero value, this can be=20 > overridden to speed up statistics generation using PGOPTIONS, e.g.,=20 > PGOPTIONS=3D'-c vacuum_cost_delay=3D0' vacuumdb ...." >=20 > and from here: >=20 > https://www.postgresql.org/docs/current/app-vacuumdb.html >=20 > "--analyze-in-stages >=20 > Only calculate statistics for use by the optimizer (no vacuum),=20 > like --analyze-only. Run three stages of analyze; the first stage uses= =20 > the lowest possible statistics target (see default_statistics_target) to= =20 > produce usable statistics faster, and subsequent stages build the full= =20 > statistics. >=20 > This option is only useful to analyze a database that currently has= =20 > no statistics or has wholly incorrect ones, such as if it is newly=20 > populated from a restored dump or by pg_upgrade. Be aware that running= =20 > with this option in a database with existing statistics may cause the=20 > query optimizer choices to become transiently worse due to the low=20 > statistics targets of the early stages. Well, that wouldn't explain why it doesn't work on partitioned tables. I am under the impression that it should. Derek, can cou share the pg_stats entries for the partitioned table? Yours, Laurenz Albe