Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcp9i-0002xZ-9a for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2023 15:04:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcp9h-0004Y6-4I for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2023 15:04:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcp9g-0004Xx-P5 for pgsql-hackers@lists.postgresql.org; Thu, 16 Mar 2023 15:04:36 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pcp9a-0000oj-6b for pgsql-hackers@lists.postgresql.org; Thu, 16 Mar 2023 15:04:36 +0000 Received: by mail-wm1-x330.google.com with SMTP id fm20-20020a05600c0c1400b003ead37e6588so3366959wmb.5 for ; Thu, 16 Mar 2023 08:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678979069; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=R8fdM/fY7jWAuj5LEC7rkwqnO6fy1Nk0a5KG7u2a1fY=; b=RJ2SP6EuXNkajNYbOCCrXeoLzR30+KtH29N+TW99Ee4uApAQgGoka4gdbxhhWg/Jry sxlPVVYqDFmiGV6+WgIs5ctqkOBzGWixq4JbAjbGE8DbDq1Z6xFKenWYBfGqFeb7gbhd Blh6PVBTHmUutRteTdG6fNRkK+UZKkvfzKrDf8mHiT1nHmQHndk12dMhnsxlCoDk+Ofs RMeQuvQS2ghlSqjaCCCNobHKz39ohn7BfiCgrE8pwUHiqI5VxJK/STRGdtjiOXZBYLNq XEiFd4hhH/frX5s/3Z/VskEz/QngaP3ttx2qJ7msgxSqpbEI3s0LJlWoRN79mp+VB01B gekw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678979069; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R8fdM/fY7jWAuj5LEC7rkwqnO6fy1Nk0a5KG7u2a1fY=; b=KoNCjGL0aeWeCvmmxZtAeuEkTsUG50g5ErgzLaFnRo73hxB8w/V5O5B5q+ayrohj9h 88zQtjgRr3IS4ctr60XtwtcSpet/dbnhON1fMpONsba67kYkigRZtc3ZaG9paFeE7nQ5 RouokcPV73ZlE8y7+gSjfkFIBsKX8/BLwd6qnyPoXcYPbiRAexEuYLm4FA18+xS73RUk oXrzLOnmju0l/2da4B2aKuG+WBKZ4IepBCWaWd+YbJ1AVB3xxkiPhhRd1H1B7Eewt64k Zvg8cvxFahJaJuusauNYOFmpdxbXsG0rZ+ktCq00M0/tJ5Ar+7NUHEVEAV03klLRwzwi 6dsw== X-Gm-Message-State: AO0yUKUz8OkmfxWO5P6FP9hYI2ADK0QJaUoW4maMnw5ntf1GgHOCkPoW vw/7G5RTtyfzJ8K/cpHInlo= X-Google-Smtp-Source: AK7set9Um51P9BGRcFIY+dZo/zt+ENJUhWSJTP6voOKejUR5ZziRqLMzi9RAs/Fw92wt0jau+XnJ3w== X-Received: by 2002:a05:600c:b8a:b0:3eb:578d:ded3 with SMTP id fl10-20020a05600c0b8a00b003eb578dded3mr21670246wmb.35.1678979069400; Thu, 16 Mar 2023 08:04:29 -0700 (PDT) Received: from smtpclient.apple ([46.70.70.90]) by smtp.gmail.com with ESMTPSA id x1-20020a5d6501000000b002c54241b4fesm7724695wru.80.2023.03.16.08.04.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2023 08:04:28 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Subject: Re: Progress report of CREATE INDEX for nested partitioned tables From: Ilya Gladyshev In-Reply-To: Date: Thu, 16 Mar 2023 19:04:16 +0400 Cc: Tom Lane , Matthias van de Meent , Alvaro Herrera , Tomas Vondra , pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <266AAEDA-786B-4DDB-B115-AE8EF0E5F283@gmail.com> References: <1000008.1678480570@sss.pgh.pa.us> <1605789.1678652046@sss.pgh.pa.us> <1621054.1678659913@sss.pgh.pa.us> <1634535.1678666528@sss.pgh.pa.us> <1760574.1678718579@sss.pgh.pa.us> <34FE3024-5025-46B7-B435-8DDD59072705@gmail.com> To: Justin Pryzby X-Mailer: Apple Mail (2.3731.400.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > 16 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2023 =D0=B3., =D0=B2 04:07, Justin = Pryzby =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0= =B0): >=20 > On Tue, Mar 14, 2023 at 06:58:14PM +0400, Ilya Gladyshev wrote: >>> The only change from the current patch is (3). (1) still calls >>> count_leaf_partitions(), but only once. I'd prefer that to = rearranging >>> the progress reporting to set the TOTAL in ProcessUtilitySlow(). >>=20 >> As for reusing TOTAL calculated outside of DefineIndex, as I can see, = ProcessUtilitySlow is not the only call site for DefineIndex (although, = I don=E2=80=99t know whether all of them need progress tracking), for = instance, there is ALTER TABLE that calls DefineIndex to create index = for constraints. So I feel like rearranging progress reporting will = result in unnecessary code duplication in those call sites, so passing = in an optional parameter seems to be easier here, if we are going to = optimize it, after all. Especially if back-patching is a non-issue. >=20 > Yeah. See attached. I don't like duplicating the loop. Is this = really > the right direction to go ? >=20 > I haven't verified if the child tables are locked in all the paths = which > would call count_leaf_partitions(). But why is it important to lock > them for this? If they weren't locked before, that'd be a = pre-existing > problem... > <0001-fix-CREATE-INDEX-progress-report-with-nested-partiti.patch> I=E2=80=99m not sure what the general policy on locking is, but I have = checked ALTER TABLE ADD INDEX, and the all the partitions seem to be = locked on the first entry to DefineIndex there. All other call sites = pass in the parentIndexId, which means the progress tracking machinery = will not be initialized, so I think, we don=E2=80=99t need to do locking = in count_leaf_partitions().=20 The approach in the patch looks good to me. Some nitpicks on the patch:=20= 1. There=E2=80=99s an unnecessary second call to get_rel_relkind in = ProcessUtilitySlow, we can just use what=E2=80=99s in the variable = relkind. 2. We can also combine else and if to have one less nested level like = that: + else if = (!RELKIND_HAS_PARTITIONS(child_relkind)) 3. There was a part of the comment saying "If the index was built by = calling DefineIndex() recursively, the called function is responsible = for updating the progress report for built indexes.", I think it is = still useful to have it there.