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 1wDHPD-002oBC-1n for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2026 07:44:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDHPC-004h9k-2t for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2026 07:44:54 +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 1wDHPC-004h9b-1d for pgsql-bugs@lists.postgresql.org; Thu, 16 Apr 2026 07:44:54 +0000 Received: from mail-vk1-xa2f.google.com ([2607:f8b0:4864:20::a2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wDHPA-00000001HPr-1dQD for pgsql-bugs@lists.postgresql.org; Thu, 16 Apr 2026 07:44:53 +0000 Received: by mail-vk1-xa2f.google.com with SMTP id 71dfb90a1353d-56a86f0a23bso7755666e0c.0 for ; Thu, 16 Apr 2026 00:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776325492; cv=none; d=google.com; s=arc-20240605; b=BJgsRNGJA9Mx8uikVsbRCb9meSRuM+di99nfBxl9JtW9+eK4mtUBDdgtXqbXm7Owez unUQ8AcHP2lhn1Zp1Kc3A0xyOyJPD3h1CsvcY4PJwZxqUyn7YaL50Sp1+wWYvgLDUwUw 9xq1rWIlKdNw2YhJLYgHeaItGuxPUJVJN5uJDbbA7aQVektTDWPBgpNE4UioXGacwZrL OUMNLUK/U5cpDwMGdQ7x1VolgcHDvHEUUgLOVPdFjyNd2zWSFcTBORcdytGtz9sFd08W L7CArgLT9oF88hcrv2Kp0YSjunXffCr9WDZFV3TAkYbLeJ6VTTDGsUowAL1DJLCDnRT0 BZyA== 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=BdUa3sdqSs0NgGGS+Mtt4mk3PTl7S2ed1MFlv+UHQC4=; fh=DgUpuILcC4wEg44xZQWWIFpNQ7i8idsJuK5DTB8Lx7U=; b=gcbun4sSIbVHKwyIWeoUFSjyukeOBBWN2WGORDBAyQqXCd2ARauhqUqVLn3jqXbbv1 kYqsyhlNBH35zp8XOq7D+Xw3RC9B/7JZ0l1rqJBO6gjf7misaUnlpxwIbuse3o/rirYz MrjafsIr89u0PKSR5b0lRY/pkrthKLS/7czfp8qg+mM0KGNQsewgu5vnLx0keAKzoGNW cOOcPQBYAtKTPRnLYQkLh0xom93ZQjbwvSpLEc3lxokYkwC7rBOGo5p9zuSWmGfT5+3Q BHUmiXIgqkZQGvwbQHhFNR3AlNOt6WPDdpb0LjhqdJIS1Qv6b9Zt1sV5h3s03R8kX5Ie ruww==; 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=1776325492; x=1776930292; 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=BdUa3sdqSs0NgGGS+Mtt4mk3PTl7S2ed1MFlv+UHQC4=; b=qLGNbGT5mWs6vw0vyvTlhiXu2r0+D7eDYxEsYUU6Dszffbawx1MIkHmRziHpi62NL1 D2kh6tE6seyajrynLu1jOU0cYQDAqPmNp9SVB6UQ5QvbPu8S4vAyqdibBUt0Sn61g5EU iM0L68AzeO5/S1DwiH6S+240YAO+TZvtDPXHgLg72QTg9+kAKBXycUAi+QIAnzWWjNDn +wo7ykzaCmPejR0v0lSvYQBax+oTXpKwOSBGb9QCGRLT3OpuiiThBBWsIN9VVxSShikx xZi4t86O93HSjIrLH2/WiKJqXJ/Wuv2c6dZ/NstITS7AjPkXhIWc9we6DCrV1LAwP2TD yJlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776325492; x=1776930292; 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=BdUa3sdqSs0NgGGS+Mtt4mk3PTl7S2ed1MFlv+UHQC4=; b=YDffanVW8RAWMo1w7V+4TUvpYYqclK8WbrzwldTwf9tObYewXq8XdQiRgpwnoJNHtv FruQ8h5N66XSub2CEi+kg/0Txrrw4Mbl8Y+/akuewEqZ1s5vjIjQZwaFxM8Q/agvgfvS K7fV2udLpyCmoLniKT+dvsXvtuNE6w4lEhfRqtPk/noSe/Zuh1kVZN6b+HUWEjLU3xtE VHsf/6YfLTTObfkd4Csr5+GFNA71jtLzJLgh4nL4tOEcxtqNgVS5+NLqPQsWVQ0gSUwb GrfjkPZEqgOBkExTBdJrR3JxP8D7vbQLiS423BKXGBaY69vH9dAujakY4werdnQebhMe bNuA== X-Gm-Message-State: AOJu0YykZoAB2geiKBa9hYOtXLGfs5pPT9OGNo7Fe6XxM6LgGa81aw+/ YHSI2SBWK4ts7I1mGFIDHMF5RSPr7zTDPbVSUM6kL1wZllNJ78oiCGzM5TPHIafkSdhV8Qwk5Am 6ZpBDcR19l+ANUks8DxPkGimiAHuiJx0= X-Gm-Gg: AeBDievv4ozBnUPrclkdh0+c6X7gURiok8acUomZOtL3mVF2H3Ipfx/QlpfBkV4Rer/ vL06PHX7wB2tfQYHLSwjBKNCc+jfC3Dgcm18rVKhHUaKNjRfddwc//fMhOOYpX124cygqPSi543 8Psg8BfyGI14ICfMJd26Laq7vBweS6cC4oprPVjZIaZ8iKQeaBBIttM6bzIuOi0mpgvx2r2Odrr RmLkAdMPhPAu0vTUkUFZpSV+WERkJvTPCAra9UBKJgeTjsg/1mA/on7skVUKk8TV/YiRLttLM5K YvGaFYJfFTELEo1z991TVGI70rlrjRCxz/+5KkdpS3r8thcwAtUI9CEAq97js/XVMKQ3D2XjAXA pMQyOQ4huVhxDSuAkD4MLPvFA3kE= X-Received: by 2002:a05:6102:604d:b0:608:94e3:bd8a with SMTP id ada2fe7eead31-609fedc66f6mr10487513137.8.1776325491808; Thu, 16 Apr 2026 00:44:51 -0700 (PDT) MIME-Version: 1.0 References: <20260415105718.tomuncfbmlt67oel@poseidon.home.virt> In-Reply-To: <20260415105718.tomuncfbmlt67oel@poseidon.home.virt> From: Srinath Reddy Sadipiralla Date: Thu, 16 Apr 2026 13:14:39 +0530 X-Gm-Features: AQROBzBGBKv9ZuTcu5mTdGi1rh1OVRndnQ8QHL_Of6R78VL0RU6EHZMVAcvv_M4 Message-ID: Subject: Re: Bug in CREATE TABLE .. LIKE .. INCLUDING STATISTICS? To: Julien Tachoires , dgrowleyml@gmail.com Cc: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000f1dd57064f8f0124" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f1dd57064f8f0124 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Julien, On Wed, Apr 15, 2026 at 7:47=E2=80=AFPM Julien Tachoires wrote: > Hi, > > One of our customer is experiencing an issue when executing CREATE TABLE > .. LIKE .. INCLUDING ALL; on 14, the following kind of error happens: > ERROR: cache lookup failed for attribute X of relation ZZZZZZ > > It seems to come from generateClonedExtStatsStmt(): get_attname() > appears to be called with an attribute number (attnum) that does not > exist. > yeah, i was able to reproduce and also check the flow which is the same as you mentioned. > > Please find attached 2 patches for the master branch, the first one adds > a test that triggers the problem, the 2nd one is an attempt to fix it. > I think it's better to write a 4 column test, with this it covers both cases of lookup either returning the wrong column name or errors out when the attnum does not exist in the child, thoughts? something like this .... CREATE TABLE parent_like_stats (a int, b int, c int, d int); ALTER TABLE parent_like_stats DROP COLUMN b; CREATE STATISTICS s_parent ON a, c FROM parent_like_stats; CREATE TABLE child_like_stats (LIKE parent_like_stats INCLUDING STATISTICS)= ; other than this patches LGTM. --=20 Thanks, Srinath Reddy Sadipiralla EDB: https://www.enterprisedb.com/ --000000000000f1dd57064f8f0124 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0Julien,

On W= ed, Apr 15, 2026 at 7:47=E2=80=AFPM Julien Tachoires <julien@tachoires.me> wrote:
Hi,

One of our customer is experiencing an issue when executing CREATE TABLE .. LIKE .. INCLUDING ALL; on 14, the following kind of error happens:
ERROR: cache lookup failed for attribute X of relation ZZZZZZ

It seems to come from generateClonedExtStatsStmt(): get_attname()
appears to be called with an attribute number (attnum) that does not
exist.

yeah, i was able to reproduce=C2=A0and also= check the flow which is the same
as you mentioned.
=C2=A0

Please find attached 2 patches for the master branch, the first one adds a test that triggers the problem, the 2nd one is an attempt to fix it.
<= /blockquote>

I think it's better to write a 4 column test, with= this it covers both
cases of lookup either returning the wrong column n= ame or errors
out when the attnum does not exist in the child, thoughts?=

something like this ....

CREATE TABLE parent_like_stats (a i= nt, b int, c int, d int);
ALTER TABLE parent_like_stats DROP COLUMN b;CREATE STATISTICS s_parent ON a, c FROM parent_like_stats;
CREATE TABL= E child_like_stats (LIKE parent_like_stats INCLUDING STATISTICS);

ot= her than this patches LGTM.

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