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 1wJcEd-0004Lt-1p for pgsql-bugs@arkaria.postgresql.org; Sun, 03 May 2026 19:12:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wJcEb-004JCm-0Q for pgsql-bugs@arkaria.postgresql.org; Sun, 03 May 2026 19:12:09 +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 1wJcEa-004JCd-2R for pgsql-bugs@lists.postgresql.org; Sun, 03 May 2026 19:12:08 +0000 Received: from mail-vk1-xa29.google.com ([2607:f8b0:4864:20::a29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wJcEY-00000000JxV-2HYq for pgsql-bugs@lists.postgresql.org; Sun, 03 May 2026 19:12:08 +0000 Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-5751770a178so210323e0c.3 for ; Sun, 03 May 2026 12:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777835523; cv=none; d=google.com; s=arc-20240605; b=LWjBo0iFVIXkTTZba8MuGG68XuJpNsTw+d17B5YQIbroSAEtxiXl4M2oqSQ+InJYhu LpiBm4iMDyQnAYlOj/p+tfc1j5kg2XBWE7p/EWBVSeZ9zDuZYTXN/tEt/aBuVUPs6LkG tx6AYX7GNAUy9WOBUs7Wcim7vKYg+TYkEM18OufXRWxSomTYfZE+7i4F3hf+uN4IxtMB eS0igMXdXV5YKsDaEZWZmLybyqIe07cF/jGIQwQ8O2ggqoE+pVI579mXqaaG1wXcPscV JZPcXtFJiqALovKiESUcB1FHQ9bViOfs/tRQXd6evMpczLnzN/mZbSaPUhqHhmvjzSJ6 VBSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=F9Y4x1oahmx/n0InD6/LMnPiPiiis3m4hT4183EoAgw=; fh=L+prL8H+1G7KBdTggxJNEnoIyKQ+jcuWm7+LgaPNJjc=; b=DUbltkNvxwlMFsc4iKv7ZDKCU3gjQPC0R8LIL/GVPR/CN9wJh8LGn/dYr666DVT9r0 yZS0wX5olGZgnIwrUa8E9pDNLb6pqhfC/U8eGAsOmKTw3ZuiRjrWX/6UIzl1Ui0e1MzS 2YNSF21a6cQbRdmSLS0tqRmvMCElBN22al/409/SWjcvbovnhniFsCYtaO1uIsxZB402 LbRw0FQky5NwL3m7Q3B2XMlGQmcGg3cKjm3jaZB0FoMQ8UUuwf8g/sUYpVSLTrdlR+fX 4oTzHMBLeAv29PkrbKIUD4sMgYKMZDhwmdr3LaCGj4EdfLv8O04UjfZ/lary8XpiFQCj m1Aw==; 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=1777835523; x=1778440323; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=F9Y4x1oahmx/n0InD6/LMnPiPiiis3m4hT4183EoAgw=; b=DzYD+nGoKFCueq8vXEpnNvt+ghXs56fXWGrPtc3l+6M3t5Z2G2ZN95dCrByyltwfk5 mbCqp5Bb5brTAfcH6jbMTNcRqZsMV833hn5JOQj6Y6z39o/9qsktr4u19QVvLoc564zi +NcpKORZJF3nhkQ+Xafo3rRGQuC3Jwam8kE9RyPbshB1H2D8nsjQef8bt2vx1llT+ou+ 9AR2IfCP4e3p6EBc25C+pqQrmLWzBvhJC3PAefY61uxsGtillolRdPcrnrJx/nD6glb8 9i3ohv+6iBfobYGD6VuuaEwsyCAl2I7omFe/1ZkV1flcI73S3uUWQA1zXDCACy2v0Spb ySuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777835523; x=1778440323; h=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=F9Y4x1oahmx/n0InD6/LMnPiPiiis3m4hT4183EoAgw=; b=hntb7bE7KeaO3vgojuyIYA15B9P5dlLs+ykcPaTtpjdd1cP02KeTP9B0L2oGAjiNDA FeR3SR6QW7ByISMBDG/Uhiy7KG7mu+YPHdE3PStJwvrjXmaz0cgTKZDYZJutxnC3Gnio KvueHwsQFMuWFr9q8yvXxgGNcCzuUIkay/xffmr5vLxoNp8lhL9oRUFadyzBjFRz12mh EwhWq5zrkBSk9UmzGSOipUI/2JEr5fBWh1h6A4J7PhhSIexs7Wdw+i5tYakYTMjyLfyZ Dm7CetQzw59fn4VJ6bcJwbQ10UCM0Mdbo8on6+sy0J+/C1auH6GC5kKfFtZnNGIFC0p3 JBjQ== X-Forwarded-Encrypted: i=1; AFNElJ+RfOd5N51u3NqSW3zg1F6qRc69a7oy3czRdxTiyXn7MxVOLbl0JnewTTFv5cecg7itkJR2glAqAcRJ@lists.postgresql.org X-Gm-Message-State: AOJu0Yw8zzAIuM6uzJ1AWZ1SwAQbw8RFx2zI2WY2YodMtTIADrt6H62p 2lberRhqp2aov150PESZAHBjCUJiYvHo1AN1Zqxp4F0a8HrDwqH6OhqTP6ISRPDdcBR6hvAmyE3 NqM9osAAGGFozgM7teepCUdZ0A2MmaCg= X-Gm-Gg: AeBDievHJ8nr10bmv7eFgyN8RRbrjJliBquL31PrUgsJXAScD83L5D2T091s1d7qwSw eiak093usVgsdI3KY736k6Cux/VU4P/WOUdv0KOw38wFZK4JUaNgsksUGt6HDh5zL49rXkcVp3/ topYo3ZX80rbZ2a8e7LjyOfwbor3cUO43k+uELQoXK/EBJT3VFyRYoG6nshjp8SLA2IkNOcOkZT trHuNkb0kppEwDYK0SW7dIsxkUC+iwr/P+OgB9NEziPVr47Vx7llR5ISMEg8oqjCvWOyuU5ThSh AFXCbgWop+5W9cqCukx/AmLc2aJemPYZ+ekObb/ZZjKN/lnPc9ckBr3zntWMQmfdW9IsFSabBJx tMMRhoH1XKxLIEWnMxPO84Wz4Py/CLyORXnpMKA== X-Received: by 2002:a05:6122:901:b0:56f:a3e2:66a4 with SMTP id 71dfb90a1353d-5750c4ab3afmr3115822e0c.1.1777835523396; Sun, 03 May 2026 12:12:03 -0700 (PDT) MIME-Version: 1.0 References: <19470-0a344a5b356fc1a8@postgresql.org> In-Reply-To: <19470-0a344a5b356fc1a8@postgresql.org> From: Srinath Reddy Sadipiralla Date: Mon, 4 May 2026 00:41:50 +0530 X-Gm-Features: AVHnY4LehgXaHqYFfABhvU-zImhq2JcXM0LBS0zHJBUx9w58W2WseBZAR2g0eOk Message-ID: Subject: Re: BUG #19470: PostgreSQL backend aborts (assert failure) when a prepared statement returns a composite type cast t To: haogangmao@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000d7590c0650ee969c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d7590c0650ee969c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Sat, May 2, 2026 at 1:27=E2=80=AFAM PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 19470 > Logged by: HaoGang Mao > Email address: haogangmao@gmail.com > PostgreSQL version: 18.3 > Operating system: Linux > Description: > > Reproduction steps (minimal): > BEGIN; > CREATE TYPE foo AS (a int, b text); > PREPARE p AS SELECT CAST(ROW(1, 'hello') AS foo)::text; > EXECUTE p; > ALTER TYPE foo ALTER ATTRIBUTE a TYPE VARCHAR(100); > EXECUTE p; > COMMIT; > > Expected: Error message (type modified while a prepared plan / expression > is > active) > Actual: Server connection dropped; backend aborts with SIGABRT due to > assertion failure > > Server log (trimmed): > TRAP: failed Assert("false"), File: "heaptuple.c", Line: 1417, PID: > ... heap_deform_tuple() > Thanks for reporting and the repro, I was able to reproduce this. The cause of this crash is a cache invalidation failure. When ALTER TYPE is executed, the cached plan for the prepared statement is not properly invalidated. So the executor uses a stale memory layout during the second execution. This causes tuple deformation to see type confusion, reading a 4-byte INT as a Varlena header. The system interprets the lowest byte of the integer as a TOAST pointer, reads the adjacent garbage memory as a TOAST tag, and triggers the Assert(false) in VARTAG_SIZE, replacing the assertion with an elog(ERROR) would prevent the hard crash, it only masks the main issue. I think the correct fix is that ALTER TYPE on a composite attribute correctly triggers a plan re-validation, thoughts? --=20 Thanks, Srinath Reddy Sadipiralla EDB: https://www.enterprisedb.com/ --000000000000d7590c0650ee969c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Sat, May 2, 2= 026 at 1:27=E2=80=AFAM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on = the website:

Bug reference:=C2=A0 =C2=A0 =C2=A0 19470
Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 HaoGang Mao
Email address:=C2=A0 =C2=A0 =C2=A0 haogangmao@gmail.com
PostgreSQL version: 18.3
Operating system:=C2=A0 =C2=A0Linux
Description:=C2=A0 =C2=A0 =C2=A0 =C2=A0

Reproduction steps (minimal):
=C2=A0 BEGIN;
=C2=A0 CREATE TYPE foo AS (a int, b text);
=C2=A0 PREPARE p AS SELECT CAST(ROW(1, 'hello') AS foo)::text;
=C2=A0 EXECUTE p;
=C2=A0 ALTER TYPE foo ALTER ATTRIBUTE a TYPE VARCHAR(100);
=C2=A0 EXECUTE p;
=C2=A0 COMMIT;

Expected: Error message (type modified while a prepared plan / expression i= s
active)
Actual:=C2=A0 =C2=A0Server connection dropped; backend aborts with SIGABRT = due to
assertion failure

Server log (trimmed):
=C2=A0 TRAP: failed Assert("false"), File: "heaptuple.c"= ;, Line: 1417, PID: <pid>
=C2=A0 ... heap_deform_tuple()

Thanks for reportin= g and the repro, I was able to reproduce this.
The cause of this crash i= s a cache invalidation failure. When ALTER TYPE is executed,
the cached = plan for the prepared statement is not properly invalidated. So the executo= r uses
a stale memory layout during the second execution. This causes tu= ple deformation to see type
confusion, reading a 4-byte INT as a Varlena= header. The system interprets the lowest byte
of the integer as a TOAST= pointer, reads the adjacent garbage memory as a TOAST tag,
and triggers= the Assert(false) in VARTAG_SIZE, replacing the assertion with an elog(ERR= OR)
would prevent the hard crash, it only masks the main issue. I think = the correct fix is that
ALTER TYPE on a composite attribute correctly tr= iggers a plan re-validation, thoughts?


--
Thanks,
Srinath Reddy Sadipiralla
EDB:=C2=A0https://www.enterprisedb.com/
--000000000000d7590c0650ee969c--