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 1tXdrf-00BbWf-7s for pgsql-general@arkaria.postgresql.org; Tue, 14 Jan 2025 10:09:39 +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 1tXdrc-00GtZA-EF for pgsql-general@arkaria.postgresql.org; Tue, 14 Jan 2025 10:09:36 +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 1tXdrc-00GtZ1-0A for pgsql-general@lists.postgresql.org; Tue, 14 Jan 2025 10:09:36 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tXdrZ-000Kur-2n for pgsql-general@lists.postgresql.org; Tue, 14 Jan 2025 10:09:35 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-53df80eeeedso4931679e87.2 for ; Tue, 14 Jan 2025 02:09:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736849373; x=1737454173; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bW9+yXgJqET3WPvvtAdFqqrfP775Dccu3XQ6mDjaPeM=; b=R23WYYEQcUy52Kx9RDPE15oIqTtON/HxNgTcDPNIo97nMobKVJxPoKBco7OZgn9tGu mXlvicsWUlb06grf4k1miLeccZd9gD6N1fsVKn/qXOivTNvpRL4i2zEQAnkMHTTGnzHk Bno/b6m633i3HBhehcTI5P//dJqvANjfWvsnp829T/8iRmBiJbfkwDJx/MjpgxtV+oc5 j52sgDsCmePv8en8N3HmpybgmJ9/fxbEmjurR9Tw2I3tmJdx5tUhe43/k25PzHTsd2nd TSTZ3bwWAqOZm41C/2yhGB2aDES5DrzVAuzQDnd47wSNTLqD0aKguidVlKiZXSGUXGUI b3AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736849373; x=1737454173; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bW9+yXgJqET3WPvvtAdFqqrfP775Dccu3XQ6mDjaPeM=; b=mnA+QULDn85teUZOf1VR7xF7hn+vzs9IjbJ0K0fpijNJoYRLq9N/tsLb6jk2xLFNai YR+Sqec449+wz6XJNz3dJAryGdlwdDJJTe3kr8Tt7GLgRfbuLmKkRAPsD2djVKLoqxeG 4XEgFcrGgZxyeji9ZWtXzbcyDxGezhoyfYINyKS4XeBDH1CyjdEdFAptHEjZ3EVMcqJE A1kxhL/HgudWx4/bst1eZz1MCxYNfByDIc95D7qGCgv0puPkd8XM8w7DGpcHTaGz+CH1 cY3EsY/pX415GntdB8qm++zrvlLBtuSkFAlqudGg//Emwq8s6HAH8+KSnhhABQi65YWg VDjQ== X-Gm-Message-State: AOJu0Yx5DZSqg//h1MDvNh5722PS/ZG5TIH2YqDC5Oacs9KV4QBVoGf6 y+lXmqDTiIAh93qh8Jf0eCAGYHWjNngJ5YvKyoto//JO8Zth88TypdGjCJZb2YlvxPu07dO60yh C9FjwyyxbZLHNQ9wnQcSVE41jRHc= X-Gm-Gg: ASbGnctvIbDWQuI+wFmRB6+62T7/7yjy8hIua96ilzegDR9IjXla5u64NQCsdRtIkyY fX0ZY1dc/7zjxRml9p8YIX0sVJLsYSylptcHPV0y1YIDiiFqTvVHk1q2epScn/3YGGHxHqnGW X-Google-Smtp-Source: AGHT+IHo+HyHTzXeKY6v6510uVvHcNCc8ORHKPRpdaE8dm9wfvsfOMW2hJ1ttR3lkBqJBWGqTYr0DoNEveF6xmjlKZg= X-Received: by 2002:a05:6512:3ba2:b0:53e:39ed:85e6 with SMTP id 2adb3069b0e04-54284546fb5mr7530026e87.32.1736849372117; Tue, 14 Jan 2025 02:09:32 -0800 (PST) MIME-Version: 1.0 References: <1348181736777057@mail.yandex.com> In-Reply-To: <1348181736777057@mail.yandex.com> From: David Rowley Date: Tue, 14 Jan 2025 23:09:19 +1300 X-Gm-Features: AbW1kvYyCUInFuYKUq24XZREhGAfbRYDz_DFrcrPhIzhqTn4ACvHXNu4-pXnrqE Message-ID: Subject: Re: About PostgreSQL Query Plan To: =?UTF-8?B?RcWfcmVmIEhhbMSxY8Sxb8SfbHU=?= Cc: "pgsql-general@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 14 Jan 2025 at 03:45, E=C5=9Fref Hal=C4=B1c=C4=B1o=C4=9Flu wrote: > I do not fully understand the logic of this issue. I would be very gratef= ul if you can share information on the subject. > > The query plan is as follows. > > Update on "test_table1" tt1 (cost=3D0.13..159112.84 rows=3D0 width=3D0) > Update on "test_table1_partition_2020_10" tt1 > Update on "test_table1_partition_2020_11" tt1 ... Update on "test_table1_partition_2025_12" tt1 > Update on "test_table1_partition_default" tt1 > -> Nested Loop (cost=3D0.13..159112.84 rows=3D1 width=3D53) > -> Seq Scan on "temp_test_table1" temp (cost=3D0.00..19.20 rows= =3D920 width=3D31) > -> Append (cost=3D0.13..172.29 rows=3D64 width=3D38) > Subplans Removed: 60 The partitions mentioned in the "Update on" portion of the EXPLAIN aren't being scanned. These are just result relations that potentially could have tuples routed to them. The key part of the EXPLAIN output to knowing that the unrelated partitions are pruned is from which partitions are mentioned below the "Append" node. You can see that 60 of your 64 partitions were pruned with the "Subplans Removed: 60" part. The executor is only going to scan the 4 remaining ones that you see below the "Append". I wouldn't worry too much about the additional partitions mentioned in the "Update on". We maybe could do a bit more work to initialise those more lazily as we do for INSERT statements, but I'd be surprised if it was a problem for 64 partitions, especially so for an update statement that might be touching 3 months of data. Nothing about these existing in the "Update on" portion of the EXPLAIN output means that that partition will be scanned by the UPDATE statement, rest assured. David