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 1pbiZB-0006ts-Ci for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Mar 2023 13:50:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pbiZA-0007Ys-2s for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Mar 2023 13:50:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbiZ9-0007Yb-Gz for pgsql-hackers@lists.postgresql.org; Mon, 13 Mar 2023 13:50:19 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pbiZ1-000531-OA for pgsql-hackers@lists.postgresql.org; Mon, 13 Mar 2023 13:50:18 +0000 Received: by mail-io1-xd32.google.com with SMTP id 76so5016801iou.9 for ; Mon, 13 Mar 2023 06:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; t=1678715411; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=N7FfYzMEjc97+MwjuGaVUTr7w6MeUytTBA13MMh22Us=; b=SZLL/7goubQ0M1OzC3lIPpKwOyc8Tm7ArH2fqPxEAKfbmPOw52pTRuKVpQiJE9Wfmu Z7p+r/Xb+88sBOL0Q9r9K/y+dt0QL8msi5u9BSFmPywTQHaDWpg5aCLneuuqkKrbKZGI b6GsDA82uBKiFW0KJbWjmiIBMTf1VKRAG+phYhkKBGeGOBan002V72KAdWXZz0p6/9kF v3NDXYDYnl7XNXWw2YLRLLa4m2nDyXAaiGBcnh2ejejHkfZQQqfBBIrw+AiUOxylsMBK R1WaWc9iFUyhQvHaCrO93XDupzfdUc85rwRKtVNXKNmMDf3NTYaumTGtW5+WrqGHUY/a 3fIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678715411; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=N7FfYzMEjc97+MwjuGaVUTr7w6MeUytTBA13MMh22Us=; b=WIn1ufJHw536B66ROpdIJu5MF/YFwHfugKgPE8ja+x6qMcHy6lGbovdKTK5Vh/eWY2 xCKodQECuoMIZ2ZhEYb4/+ps7en361vXR9WlhoBSemJRkH3M30p6Z1d5+/Qc7u3hQ0hX Lp8nN8sljG3RqcaYLiE4D80uXVOGE3u63/paJz90p6EmBuhRCr9WLQFdEy/HUq3TklXJ 2o/W5EmzX6KZlUmQLYKiFaNuzTHvLzhGzUhXOQc8J7YI2gG2zClNIrye35XwP9EYa8U3 /JxkjKR4WDwwrkGB32dFXkyUur/N5ObceVrTtx0cEuv1hL7NhE1gpJ27Kx2J6Vu70Ai9 qmMg== X-Gm-Message-State: AO0yUKWU/GE8UdtCAV18303VmOb/gMu7Eq2/Djxv3/8qoNuoZTf7EtbQ p96mjcRcO/rCSd8BLyJ4xMlEnA== X-Google-Smtp-Source: AK7set9+gAIGlZvFbMJsIQ9Iuu1goA/D37G3PLhwCiprZ+piLahOBzIZWCpdemhRulg19oPLsh0CJg== X-Received: by 2002:a6b:fb15:0:b0:711:6a68:6afd with SMTP id h21-20020a6bfb15000000b007116a686afdmr9959868iog.10.1678715410987; Mon, 13 Mar 2023 06:50:10 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id z27-20020a02cebb000000b003c4f7c419dasm2499848jaq.128.2023.03.13.06.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 06:50:10 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 85D19800170; Mon, 13 Mar 2023 08:50:08 -0500 (CDT) Date: Mon, 13 Mar 2023 08:50:08 -0500 From: Justin Pryzby To: Tom Lane Cc: Matthias van de Meent , Ilya Gladyshev , Alvaro Herrera , Tomas Vondra , pgsql-hackers@lists.postgresql.org Subject: Re: Progress report of CREATE INDEX for nested partitioned tables Message-ID: References: <20230202151807.GY22427@telsasoft.com> <20230208224049.GO1653@telsasoft.com> <20230217002651.GW1653@telsasoft.com> <1000008.1678480570@sss.pgh.pa.us> <1605789.1678652046@sss.pgh.pa.us> <1621054.1678659913@sss.pgh.pa.us> <1634535.1678666528@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1634535.1678666528@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Mar 12, 2023 at 06:25:13PM -0400, Tom Lane wrote: > Justin Pryzby writes: > > On Sun, Mar 12, 2023 at 04:14:06PM -0400, Tom Lane wrote: > >> Hm. Could we get rid of count_leaf_partitions by doing the work in > >> ProcessUtilitySlow? Or at least passing that OID list forward instead > >> of recomputing it? > > > count_leaf_partitions() is called in two places: > > > Once to get PROGRESS_CREATEIDX_PARTITIONS_TOTAL. It'd be easy enough to > > pass an integer total via IndexStmt (but I think we wanted to avoid > > adding anything there, since it's not a part of the statement). > > I agree that adding such a field to IndexStmt would be a very bad idea. > However, adding another parameter to DefineIndex doesn't seem like a > problem. It's a problem since this is a bug and it's desirable to backpatch a fix, right ? > Or could we just call pgstat_progress_update_param directly from > ProcessUtilitySlow, after counting the partitions in the existing loop? That'd be fine if it was only needed for TOTAL, but it doesn't handle the 2nd call to count_leaf_partitions(). On Sun, Mar 12, 2023 at 08:15:28PM -0400, Tom Lane wrote: > I wrote: > > Justin Pryzby writes: > >> count_leaf_partitions() is also called for sub-partitions, in the case > >> that a matching "partitioned index" already exists, and the progress > >> report needs to be incremented by the number of leaves for which indexes > >> were ATTACHED. > > > Can't you increment progress by one at the point where the actual attach > > happens? > > Oh, never mind; now I realize that the point is that you didn't ever > iterate over those leaf indexes. > > However, consider a thought experiment: assume for whatever reason that > all the actual index builds happen first, then all the cases where you > succeed in attaching a sub-partitioned index happen at the end of the > command. In that case, the percentage-done indicator would go from > some-number to 100% more or less instantly. > > What if we simply do nothing at sub-partitioned indexes? Or if that's > slightly too radical, just increase the PARTITIONS_DONE counter by 1? > That would look indistinguishable from the case where all the attaches > happen at the end. Incrementing by 0 sounds terrible, since someone who has intermediate partitioned tables is likely to always see 0% done. (It's true that intermediate partitioned tables don't seem to have been considered by the original patch, and it's indisputable that progress reporting currently misbehaves in that case). And incrementing PARTITIONS_DONE by 1 could lead to bogus progress reporting with "N_done > N_Total" if an intermediate partitioned table had no leaf partitions at all. That's one of the problems this thread is trying to fix (the other being "total changing in the middle of the command"). Maybe your idea is usable though, since indirect partitioned indexes *can* be counted correctly during recursion. What's hard to fix is the case that an index is both *partitioned* and *attached*. Maybe it's okay to count that case as 0. The consequence is that the command would end before the progress report got to 100%. The other option seems to be to define the progress report to count only *direct* children. https://www.postgresql.org/message-id/20221213044331.GJ27893%40telsasoft.com > The reason I find this annoying is that the non-optional nature of the > progress reporting mechanism was sold on the basis that it would add > only negligible overhead. Adding extra pass(es) over pg_inherits > breaks that promise. Maybe it's cheap enough to not matter in the > big scheme of things, but we should not be having to make arguments > like that one. If someone is running a DDL command involving nested partitions, I'm not so concerned about the cost of additional scans of pg_inherits. They either have enough data to justify partitioning partitions, or they're doing something silly. -- Justin