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.96) (envelope-from ) id 1wmeNG-000twd-1s for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jul 2026 21:21:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wmeMF-00DpTZ-1C for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jul 2026 21:20:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wmeME-00DpTQ-2z for pgsql-hackers@lists.postgresql.org; Wed, 22 Jul 2026 21:20:02 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wmeMC-00000001TSu-0Et9 for pgsql-hackers@lists.postgresql.org; Wed, 22 Jul 2026 21:20:01 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4954c0833b4so38682395e9.1 for ; Wed, 22 Jul 2026 14:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784755198; x=1785359998; darn=lists.postgresql.org; h=in-reply-to:references:from:cc:subject:to:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=ng3R5hgNzEhZEkvSyXTAJhKKV3Z01fcqs97AtbUrk4M=; b=O3DgS0ZLBw7pTwaan317b3nXuwcAI7uPG4m7aA6gd2klBmoPvZnIUrMLUSE0JvtAVs k+i8EzRCsN5T557QwqPw33cAFeK3xfNZwDiaxSzhY1vt0kAUeOnvMENgtPejd8+NHomK FqTkVd101Uyi+MIyg4tkEzRsYvu84Ni9Aa9DOxclIy+FHOYFe/P1QuLVm17rLM8qMzoS 6yWnFkFf09pN4tisCOQ0dsY3iOOO9J68ubnGIrnjVFi/6iTXkJrOJZUcSaCRnjS2CUFY NGrRUuV1ekI3unbn36pavTq6BaHLFVzokGtPKtaah5Iqa4YeffJw/y3kxPsCQrEytrJq 3GXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784755198; x=1785359998; h=in-reply-to:references:from:cc:subject:to:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ng3R5hgNzEhZEkvSyXTAJhKKV3Z01fcqs97AtbUrk4M=; b=lEt6sTOzQcjHhfGsdoRCbo+fxT6S9+uodhpVaAXj6DBHUiq256BaGUK+IkD8sNG7rP TwGpCI1ULYZlSvI5xhVbQUnWtTMs4TESL7Mpp2EhlKnygZQviS+DYAzJtIAIqleb1vdm 1m2MxCrGHTlCDwBy3aTTJygtC7IlSXMcSAIdT7nNjlbmoIkvsQjVnyFFaBNeLlUxa3S5 Zp3yOrDOgFXMJ5CIgnvcf3w6QTlf7iWlRRUZb4ejW5sOGm83VcEW7qYuiAJw1nskaiQB HqYy3kx4UoTLTu0X33OsobqcGNdxOQV1yEZe3UNVPORFCGVxbLyCPnDivvNTeMa2ge9f Ea0g== X-Forwarded-Encrypted: i=1; AHgh+Ro3zHCl2Kl44e93kk0rauh53aQHZZZPm5gnssFk6JAfOUWy+ydQjQxNYYRuD51MqkzFFrTeZcNvTtzfsKju@lists.postgresql.org X-Gm-Message-State: AOJu0YzdX+GK0Pwr5xDbu8jT8fjdcA1WIESWPne+hu85uDHi0nyb6L10 ENgE1rkmCI/93n16odeieftnA8JXpPSXvmTyJEJkT2VK5ieTdHim0kAe X-Gm-Gg: AR+sD12SUDoFRNbOfCQ/HE4c1lSFyCEw2gHOSMQn2jnFHCb1YZ0KeLo3G1A2M4n4gqe rXFZ83Tfc4U1xE48kkncRXwluvJ1sL11sD1qT5H82j1GRk9ry3YLiTzg4ot8pjTSZlTzsSGeXwd l8CRhdPW2lUVoh+uEEAhnbxsEP1RpqtiJ1CQ4SKleE6OYKJUwXVv/CONAMzIO3ZpOjAm/d4ihYp bMPVBW39tA23pK8fepRyK7VRCZSOGTjz923W9K1Ilrl4wpya+ny0oLxhcXyXfZu+b1mu8jiPoJv LWjsP/TdEKJ/lFrELVSMWlmYzV2rsakZbceB1mx8o3aBqSsm/wY/1yqoAj1QfT0AMKxkQVvKC/h POXv/Nao0r4DoNnZ0DkJy4mSNPgJaGBuZydnDd2UkosUUuHxy8w46WVALZcVukgKfnuNAjO4UGv Cx0vEHQpacES1b8EzgIF2w X-Received: by 2002:a5d:5e8f:0:b0:47f:5371:1b15 with SMTP id ffacd0b85a97d-47f8da5f9d2mr470395f8f.26.1784755197537; Wed, 22 Jul 2026 14:19:57 -0700 (PDT) Received: from localhost ([2a02:169:191:0:1981:4f04:eaef:a25]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85bd850asm9127844f8f.15.2026.07.22.14.19.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jul 2026 14:19:56 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 22 Jul 2026 23:19:56 +0200 Message-Id: To: "Antonin Houska" , "Alberto Piai" Subject: Re: Allow progress tracking of sub-commands Cc: "Rahila Syed" , , , , From: "Alberto Piai" X-Mailer: aerc 0.21.0 References: <106920.1782734246@localhost> <69363.1782919477@localhost> <10153.1784708881@localhost> In-Reply-To: <10153.1784708881@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed Jul 22, 2026 at 10:28 AM CEST, Antonin Houska wrote: >>=20 >> @@ -33,9 +37,30 @@ pgstat_progress_start_command(ProgressCommandType cmd= type, Oid relid) >> return; >>=20 >> PGSTAT_BEGIN_WRITE_ACTIVITY(beentry); >> - beentry->st_progress_command =3D cmdtype; >> - beentry->st_progress_command_target =3D relid; >> - MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progre= ss_param)); >> + /* Sub-command should not be started w/o parent command. */ >> + if (beentry->st_progress_command =3D=3D PROGRESS_COMMAND_INVALID= ) >> + { >> + Assert(beentry->st_progress_command2 =3D=3D PROGRESS_COM= MAND_INVALID); >> + >> + beentry->st_progress_command =3D cmdtype; >> + beentry->st_progress_command_target =3D relid; >> + MemSet(&beentry->st_progress_param, 0, >> + sizeof(beentry->st_progress_param)); >> + } >> + else if (beentry->st_progress_command2 =3D=3D PROGRESS_COMMAND_I= NVALID) >> + { >> + Assert(beentry->st_progress_command !=3D PROGRESS_COMMAN= D_INVALID); >> + >> + beentry->st_progress_command2 =3D cmdtype; >> + beentry->st_progress_command_target2 =3D relid; >> + MemSet(&beentry->st_progress_param2, 0, >> + sizeof(beentry->st_progress_param2)); >> + } >> + else >> + { >> + /* Only one level of nesting is supported. */ >> + Assert(false); >> + } >> PGSTAT_END_WRITE_ACTIVITY(beentry); >> } >>=20 >>=20 >> The comments of the two macros warn about the fact that they create a >> critical section, and code within the critical section should be kept as >> simple as possible because any error would be promoted to PANIC. Now >> sure, Assert() doesn't matter in production builds, but still I think >> there is value in getting rid of a possible error path. > > The patch only adds an if-else construct, but the other lines added are j= ust > variants of the existing ones. So I don't think the patch increases the r= isk > of an error ERROR (promoted to PANIC). > >> (And a restart to clean up shared memory would be pretty annoying even i= n >> debug builds.) > > If Assert() fires, then what I consider annoying is the bug that caused i= t, > not the restart. Restart could be a problem if I wanted the other regress= ion > tests to complete before fixing the bug. However that doesn't make much s= ense > to me because all the regression tests should be run again as soon as the= bug > is fixed. Sorry, I could have been clearer. I was referring specifically to the Assert(), which would be hit in the edge case you mentioned (a command trying to report progress past the 2nd level of nesting). I think it would be nicer if attempts at progress reporting past the maximum supported level of nesting would be a noop rather than an error, and in general if the command didn't need to know whether it's reporting progress at level 1 or level 2. >> The main advantage would be that the compiler would yell if we forgot to >> change a reader. > > Not sure I understand the difference. Can you please describe the situati= on > w/o this advantage, i.e. w/o the compiler errors? > >> While looking into this for example, I ran into some code in >> vacuumlazy.c (heap_vacuum_rel()) which writes into st_progress_param >> directly: >>=20 >> appendStringInfo(&buf, _("delay time: %.3f ms\n"), >> (double) MyBEEntry->st_progress_param[PROGRESS_VACUUM_DELAY_TIME] = / 1000000.0); >>=20 >> Purely theoretical of course, but if this was done by code which could >> run both as a main command or a subcommand, this would end up writing >> to the wrong spot. What I meant to say: with your patch, existing code referring to st_progress_command would not break, but might find itself working with st_progress_param, when it should be st_progress_param2 (depending on how the command is nested). If we instead changed to an array of structs, it would be a breaking change and we would have to fix all the callers. > >> What do you think, is something like this feasible? Maybe it would >> address Rahila's point, while not being too much extra work / complex >> code. > > Yes, I think it's worth at least a prototype. Do you want to adjust my pa= tch > yourself or should I do? Please go on, I was just trying to help as a reviewer. Looking forward to the second version then :) Regards, Alberto --=20 Alberto Piai Sensational AG Z=C3=BCrich, Switzerland