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 1wS8VL-002ysY-0O for pgsql-bugs@arkaria.postgresql.org; Wed, 27 May 2026 07:16:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wS8VI-007Sq1-2L for pgsql-bugs@arkaria.postgresql.org; Wed, 27 May 2026 07:16:37 +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.96) (envelope-from ) id 1wS8VI-007Sps-1Q for pgsql-bugs@lists.postgresql.org; Wed, 27 May 2026 07:16:37 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wS8VH-00000001eYY-1Ih3 for pgsql-bugs@lists.postgresql.org; Wed, 27 May 2026 07:16:37 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-7bf0b47d2f1so99346627b3.3 for ; Wed, 27 May 2026 00:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779866193; cv=none; d=google.com; s=arc-20240605; b=YpCG6ITiQN3d8Gl+cg5pzs2ST9PW2HfPg2zoj9xeZRU4m/CWsn1bKo8VcmCOYfMB6R isokfqJEduum6iZxTVaP9x0hf9OmaKx1noicA6K05xnxCrFvaIzhw3FqKzIdvdACXXMl IZ5C/R0H8b20arSu0BZi4cHR6VQv6usOqXfdd5HcM1dzpnzdPvB541VTfN5U74rrtPZn TU1qp17bxuKRzk60BM0uB2IG0fUd+MyK4WOW5KgHvcvel+u7cwUir+H75ku+hrEifLs4 tIir7jaOu8HVYNZQa5TwGOL6h72Q8aMNJ9pkTboERvOa99sYl17QQQg3+L8zdnCzF/QD qEeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=O8u/CJNvTVMcBPDe7GIYFNeESeGtFbjoWL47/ecxddE=; fh=Dr1VnHdvMn2+bog9eeuQdrNo681G/B3Of04pOGzKA6Y=; b=BuSqQhZDlQxNHivbInkrBigZvJZrajDx7c/Ac2oK49IouLElwKXbq6RfmpArDhvBiU bADyDk5/nvMH5Ym6LbFQfDu58+SXaeTGU+EC7dQInGo41nVdpSw+dg6+esjNcCv8wSpY 4RbQHUKe0dsXTT65EsbADlk0bze5e8YHxAJsM68QnUjNMu2bs12Q+hp8KzQfd2y9eoKM Luu1MfX9IT1TnLQhBim48pNuCJsSxdBN0prPkDcjVsFe0GvFHqGC3VwcM55QtWZv/s2P jhQFlwXSIeBZJJ8mt++OXZLhxwBcrl7zeJZ3Wmty0DokFFlpCJhFpuJKpmzToljPR6Mw Gt/g==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779866193; x=1780470993; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=O8u/CJNvTVMcBPDe7GIYFNeESeGtFbjoWL47/ecxddE=; b=aAzPz2vq42S0G0ZN4lhLhqHPjvH5mefDrtFySXCBugPFZyPa6p4ANJuh4J9xcXJJPq FFHqtWDTPLfvjhLKhVQUgy3vrAS81VRb6juRpjDKCgcq03TjT2+3lBRG00htwrLkDLD/ EYB9Zgyg72G/cljeI8fesPFWwlQQ/JzKaOo4/dxqP+N6rh228yqw5h5GlU2XmEYYd6tE VeZCJkWmwJf8gl6xFSwuhXDjEEfZbbZpTDsCsoourRP28G1LADoE8R8VBPOqmk1yBSCG Rcz/teY6pqjpivL1rjMnHnMu71yDaNoeicNqrlntdBaYTBUj5Y2kIkJKwuMnVycQLFDq gXfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779866193; x=1780470993; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=O8u/CJNvTVMcBPDe7GIYFNeESeGtFbjoWL47/ecxddE=; b=ZvPSWkiY31g0fqy1TC7FJIsBBr/W6WIlGYu+rXrcgSbTM4yT4o4e8Zi32MIKN4wfVr OF51fWyjn2eriZOWtCWtuH8l7fb7cVtehhCb8WQT8QiGED5asIIgwwCRVwsSFjNUxbog uQFDGRyyqgNpbD2iB8ftlvfibHCQRiJLtNe0Z6vs0ag53SVvBIgN/WaBx5I6ywOMOaib Hyjj41bUJg0TSur8/WjLQjumXNhjRKKbdIClnnjO3L/Cp8R3ZatP4bXIYBbrPKWSl2Z2 EBSVlX9vEVlPLj7s5KiITo5Fi/qNDSDVFP+Y9xrvgXBbTfpVaqJTaWNfDwrh1sB0+b6r UZug== X-Gm-Message-State: AOJu0Yze6ANyWz8bbJfr1iTieyEK0vu68CFzIckrzHPYqrUqgXFnnQKt 6fXrt2zjMb33i6E8Lo3znrsEP6DqNq4MDuh3Ieujy48EqMAnllaB4eDzSRXYY3XW/DLAW5XC7F+ nvdacIiyUyInadywiMQIRWodT298mxTM= X-Gm-Gg: Acq92OEfM/kGgQ12YeLL+akQcU/pVrlVRxGHF8Rx3Y784IUh4YiDXpjmkAaq1nO/1kW 0UWDIu/1cLJ/sp2tfnIZ1bC9Is57kb+rwN4OG1/zTGTtHAOXrFZS5tOGAVJKqKi/tmTzVSxlluw BBsu4qTxElTDRX8yKAS16+8Oj+Qmhb1/2Wjn4KeKfaryipNUSjo9lIH3cu6KwXIBm71vb9Ks5uX G1J1aweHaumuOR5L+fDBITCmcpE1gNbFRjG3VHSt+oewg9pzs+Zd3aWOnD9oD4tAloRPcmk9eq6 2p/bqmd92VYIm2Uf0fFaeQREpjey X-Received: by 2002:a05:690c:a83:b0:79e:8299:7505 with SMTP id 00721157ae682-7d337daf0d9mr217160527b3.6.1779866192826; Wed, 27 May 2026 00:16:32 -0700 (PDT) MIME-Version: 1.0 References: <19493-5878eac7a2525c23@postgresql.org> <2d59d7d6-6afe-4565-8ff7-ae764651589a@gmail.com> <1779843554.737126560@fmail2.qdit> <418106.1779844099@sss.pgh.pa.us> In-Reply-To: From: Ayush Tiwari Date: Wed, 27 May 2026 12:46:24 +0530 X-Gm-Features: AVHnY4KU4zxq_zsoILLuPLqhnZ4vnYu_QBbGX1Rhp4F_DKAVqsW945Rn_aBH8cg Message-ID: Subject: Re: BUG #19493: Assertion failure in pg_plan_advice with EXISTS subquery and DO_NOT_SCAN advice To: Tender Wang Cc: pgsql-bugs@lists.postgresql.org, =?UTF-8?B?0JrQsNC70LjQvdC40L0g0J3QuNC60LjRgtCw?= , Michael Paquier , Pierre Forstmann , Robert Haas , Tom Lane Content-Type: multipart/alternative; boundary="0000000000002bd5170652c76491" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002bd5170652c76491 Content-Type: text/plain; charset="UTF-8" Hi, On Wed, 27 May 2026 at 09:20, Tender Wang wrote: > Hi, all > > I find an easier way as follows: > diff --git a/contrib/pg_plan_advice/pgpa_trove.c > b/contrib/pg_plan_advice/pgpa_trove.c > index ca69f3bd3df..64af4b1435b 100644 > --- a/contrib/pg_plan_advice/pgpa_trove.c > +++ b/contrib/pg_plan_advice/pgpa_trove.c > @@ -179,7 +179,6 @@ pgpa_build_trove(List *advice_items) > * but in the future this > might not be true, e.g. a custom > * scan could replace a join. > */ > - Assert(target->ttype == > PGPA_TARGET_IDENTIFIER); > > pgpa_trove_add_to_slice(&trove->scan, > > item->tag, target); > } > Thanks for checking this. I agree that removing the assertion looks like the better approach. Keeping the original target tree seems preferable. As you noted, pgpa_identifier_matches_target() already handles non-identifier targets by checking their descendants. pgpa_trove_add_to_hash() does the same when building the lookup table, so a grouped target such as ((a)) should still be indexed and matched through its child identifier while preserving the original shape for output. So I think the assertion in pgpa_build_trove() is too strict, and the nearby comment should be adjusted to avoid saying/implying that scan advice always has a direct identifier target. Regards, Ayush --0000000000002bd5170652c76491 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Wed, 27 May 2= 026 at 09:20, Tender Wang <tndrwan= g@gmail.com> wrote:
Hi, all

I find an easier way as follows:
diff --git a/contrib/pg_plan_advice/pgpa_trove.c
b/contrib/pg_plan_advice/pgpa_trove.c
index ca69f3bd3df..64af4b1435b 100644
--- a/contrib/pg_plan_advice/pgpa_trove.c
+++ b/contrib/pg_plan_advice/pgpa_trove.c
@@ -179,7 +179,6 @@ pgpa_build_trove(List *advice_items)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* = but in the future this
might not be true, e.g. a custom
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* = scan could replace a join.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/=
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Assert(ta= rget->ttype =3D=3D
PGPA_TARGET_IDENTIFIER);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pgpa_tro= ve_add_to_slice(&trove->scan,

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0item->tag,= target);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }

Tha= nks for checking this.

I agree that removing the assertion looks lik= e the better approach.=C2=A0

Keeping the original target tree seems preferable.=C2=A0 As you= noted,
pgpa_identifier_matches_target() already handles non-identifier = targets by
checking their descendants. =C2=A0pgpa_trove_add_to_hash() do= es the same when
building the lookup table, so a grouped target such as = ((a)) should still be
indexed and matched through its child identifier w= hile preserving the original
shape for output.

So I think the ass= ertion in pgpa_build_trove() is too strict, and the nearby
comment shoul= d be adjusted to avoid saying/implying that scan advice always
has a dir= ect identifier target.

Regards,
Ayush=C2=A0
--0000000000002bd5170652c76491--