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 1wS5Ho-002wRU-14 for pgsql-bugs@arkaria.postgresql.org; Wed, 27 May 2026 03:50:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wS5Hl-006wtk-03 for pgsql-bugs@arkaria.postgresql.org; Wed, 27 May 2026 03:50:25 +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 1wS5Hk-006wtb-2L for pgsql-bugs@lists.postgresql.org; Wed, 27 May 2026 03:50:25 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wS5Hj-00000001d7d-2wKs for pgsql-bugs@lists.postgresql.org; Wed, 27 May 2026 03:50:25 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-bce57c132b2so2055196966b.0 for ; Tue, 26 May 2026 20:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779853821; cv=none; d=google.com; s=arc-20240605; b=ljNOx+ULAY/+PJTChkgEN3o0yyQeYQ9tHjt4ZI2NBpZT43Gu9/9INb+3KLLFgG8qdL 5f4vxo/fX2xx7o+bkgAsVq3M5WALsgmffoDqxiHs/jTi7YeP9nddFn+cbwYJ3vVMa9yx GqDGevQx2+uxYnfLDym0VgSEAh2wCcPnf9dmoJ04kYkHYHQoYWKBschmNEoPSF64GDnX V8GJXZy4L/9Wv5a4uJRxe6exvLiWEseU09YaAVMx/0lNh1hJxRJrcHhibsvXYY9ddEzN Ej41cau9dQZZBvKsHEUQoTgMJCEZIkiahrBxuQz6C1I8I/5dEu8qa7aCz4MEBMnKrYZ/ S6Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=YS1UWP8Yw20yC14iKX2Otznie+VOauIuB9XDz85IJFw=; fh=QwasdCIHbExr0uQe2bzhyGsFoqqSxHBa4juQoi4oK68=; b=aaKqbdlyiMwYPI8hn2XgYafW8Aw/QEFdtPxwSKuNHWNxntyS0SUNkt2PTvoVxEZ5ls VQU23zD/X5KME+zaRfojN4QLfJRiKh8lNWH0ebMQpxvNBAmHC/WIpfJKwRfUK6EP0GOp yBWyHNmCl83ZDkPbp+cOECHwdYFjuHWQPxc115jqM4Hnty37P0LpZQ/nSFUe4KoJ8nh4 TauuYwZP0QJ+/z665c1hHgWIHb+ZOB36S0mDicfbwR3yx48pML3aPZxnH+MUCCrFpiGN hkr3p2Brn9lIQx6dFBU8/UsaN9ot1bewbYzoorCkbn5qZfBrUsqpgA/ni8KR172c/Wji qm/A==; 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=1779853821; x=1780458621; 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=YS1UWP8Yw20yC14iKX2Otznie+VOauIuB9XDz85IJFw=; b=rXBx1sKJNkoSQToGci3zvXlbRY5yCbno4cyYWhifwXc/HdkbZBE7G0VENgL+4Q7yxA 2cRIc7275Iv7K93aV85+s97h/d9t9gn+HMryVFvu/4YH6CAxLbXjzuiXdlGPyKhurDsr gqY5634/w+Pf4KdK0hGW5AaBrascxXXj4LVPdFYEL44cNzHLzLrX4wEvU5LT5Usadz8U IQauhFZBPwWEl2xcU+2zWIk8vEeSS1PKD4ZUBzrgKxEYq0/EwjvC+fNRp3uAk6EQsgaV JZuE3MzvoYIUjJAp+llmUpFNixAdH1U40yDCXhUxFjP6xv0N6nQSUsNQekDBuT95HU8L BPzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779853821; x=1780458621; h=content-transfer-encoding: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=YS1UWP8Yw20yC14iKX2Otznie+VOauIuB9XDz85IJFw=; b=bkKKhiZIxEy7idcGgAo51khSXibxU+91roe9OFpQTJ1KUYAw4qpVGpzWI1QZIdfSXy AGJD14QaAp8ekqC9aeuCp2vQY7y5wvyvV41aAnOafhF+l2wF7dvyokW3wMPEo7KN2IzF EPmcJtYFXdIJVnSYW7WFkqiBW11iMrMIxzK01NNbqIuOKDshNuKqfxSKcOkHXoos715H eB9nQ0HAUIUfUHZL3nYbsocCcIAePmbZjq77Ac+eOznuPpvicwrq3fVhZT0wJthiN2Jn u4KSc/g120E45EkfySUBXiw4OZ4dpk0YiMXntdJq6bvF+4i7fMlR41tr/z2FRBqRcJAF 57nA== X-Gm-Message-State: AOJu0Yx1A7dHznbtdTfdyl7g2i+gmNqlygTmF9ranR9BLPKikYgp+061 TECtXUu6Wqy6HN9uC7r578skeMMgZ7z5tlGmFSKqgbHZZtTSN8xTQwZYOc7FN6W69QcrthCevZc Bnx8TkDTkjM9IS+hK4QFR2J6UHuK/cjIw7BTLskT47g== X-Gm-Gg: Acq92OE3ndNPtI/9IoQ+XSg+mzVui9fC8VF/5Z93T74ekvK5Tq30VqzO+mzNXUDRtEt 2TenBuiZLl+OplpjFSPpbEuukCxP0EVdHZWgiwQ4vlQ3RxXDR+1wP1Rjxmhk0z0CoYUYhNzZF1j VbcZjw+cVHFzCGjVwSiXwXdQtMM2ZVfAUDYwWy7RWlrmO/wfguPCKKwnxV45lonjM4d02D9hUni qzMfpX92NjUlc80G9nxhpzlYWSzGgBKRKoG5OtikpGzRtsDuT2Fv77KmZ3ZfSrRZXTHNngzmTtl d15MxCqzGlcTFmWejXsy6sBgguSAIjJp9GBRURGd9570rFL+BBoJgTBefOMb1g6T+uyUgfTN8Tk = X-Received: by 2002:a17:906:7945:b0:bd4:f2c7:25e2 with SMTP id a640c23a62f3a-bdd47dfb7e0mr1009082166b.5.1779853820882; Tue, 26 May 2026 20:50:20 -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: Tender Wang Date: Wed, 27 May 2026 11:50:09 +0800 X-Gm-Features: AVHnY4LDJizODgy0W4S5Y48a6R3wGzS5qIGYAkYE4YTvQ-qRHFMZ5j21X3iMg8k Message-ID: Subject: Re: BUG #19493: Assertion failure in pg_plan_advice with EXISTS subquery and DO_NOT_SCAN advice To: pgsql-bugs@lists.postgresql.org Cc: =?UTF-8?B?0JrQsNC70LjQvdC40L0g0J3QuNC60LjRgtCw?= , Michael Paquier , Pierre Forstmann , Robert Haas , Tom Lane 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 Hi, all Tender Wang =E4=BA=8E2026=E5=B9=B45=E6=9C=8827=E6=97= =A5=E5=91=A8=E4=B8=89 09:28=E5=86=99=E9=81=93=EF=BC=9A > > Hi, all > > Tender Wang =E4=BA=8E2026=E5=B9=B45=E6=9C=8827=E6=97= =A5=E5=91=A8=E4=B8=89 09:17=E5=86=99=E9=81=93=EF=BC=9A > > > > Tom Lane =E4=BA=8E2026=E5=B9=B45=E6=9C=8827=E6=97= =A5=E5=91=A8=E4=B8=89 09:08=E5=86=99=E9=81=93=EF=BC=9A > > > > > > =3D?UTF-8?B?0JrQsNC70LjQvdC40L0g0J3QuNC60LjRgtCw?=3D writes: > > > > Could this be related to GCC? I'm using GCC 16.1.1 and I can reprod= uce the crash with that version. > > > > > > Maybe. Does it still fail if you set the optimization level to -O0 ? > > I can reproduce this crash on my machine with CFLAGS=3D"-O0 -g3". And m= y > > GCC version is 11.4.0 > diff --git a/contrib/pg_plan_advice/pgpa_trove.c > b/contrib/pg_plan_advice/pgpa_trove.c > index ca69f3bd3df..0d15af1cbba 100644 > --- a/contrib/pg_plan_advice/pgpa_trove.c > +++ b/contrib/pg_plan_advice/pgpa_trove.c > @@ -179,9 +179,18 @@ 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 =3D=3D > PGPA_TARGET_IDENTIFIER); > - pgpa_trove_add_to_slice(&trove->s= can, > - > item->tag, target); > + if (target->ttype =3D=3D > PGPA_TARGET_IDENTIFIER) > + > pgpa_trove_add_to_slice(&trove->scan, > + > item->tag, target); > + else > + { > + Assert(target->ttype > =3D=3D PGPA_TARGET_ORDERED_LIST); > + > foreach_ptr(pgpa_advice_target, child_target, target->children) > + { > + > pgpa_trove_add_to_slice(&trove->scan, > + > item->tag, child_target); > + } > + } > } > > I tried the above fix, and no crash again. 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 =3D=3D PGPA_TARGET_IDENTIFIER); pgpa_trove_add_to_slice(&trove->sca= n, item->tag, target); } Just remove the Assert, then it works as well. The previous fix is not ok, because the output of explain is not the same as the user input: Supplied Plan Advice: DO_NOT_SCAN(a) /* matched, failed */ We should get DO_NOT_SCAN((a)) The new fix will get what we want: postgres=3D# EXPLAIN SELECT * FROM a WHERE EXISTS ( SELECT 1 FROM b WHERE b.i =3D a.i ); QUERY PLAN ----------------------------------------------------------------------- Hash Join (cost=3D46.38..102.75 rows=3D1275 width=3D4) Hash Cond: (a.i =3D b.i) -> Seq Scan on a (cost=3D0.00..35.50 rows=3D2550 width=3D4) Disabled: true -> Hash (cost=3D43.88..43.88 rows=3D200 width=3D4) -> HashAggregate (cost=3D41.88..43.88 rows=3D200 width=3D4) Group Key: b.i -> Seq Scan on b (cost=3D0.00..35.50 rows=3D2550 width=3D4= ) Supplied Plan Advice: DO_NOT_SCAN((a)) /* matched, failed */ (10 rows) In pgpa_identifier_matches_target(), if it is not the PGPA_TARGET_IDENTIFIER, we will check all descendants. The original comments may need to be adjusted. I added Robert to the cc list. He knows more about pg_plan_advice than I. -- Thanks, Tender Wang