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 1wB0hI-000ePM-16 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 01:30:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wB0hG-008gfR-1K for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 01:30:11 +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 1wB0hG-008gfJ-0P for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 01:30:11 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wB0hF-00000000H6Z-07mM for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 01:30:10 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b980785a0bfso213324366b.3 for ; Thu, 09 Apr 2026 18:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775784602; cv=none; d=google.com; s=arc-20240605; b=aOYwy9utpTBO8HbqtW8d303ihJm3rppSMjyh+v7VtrpxqIf3flQ2eR8Gysoudcou80 veZ77OU1431tPYLiPdvg/uvY8tgeRaWJ5QM5GK24O3ApC5UjoZmO+IJkej30cw5YO82h J2ouIZ0EdhM02na85A7NCNPa6+oHZQAF3G5DrrUOdtjz9/NsKyvf54+/EVR6QaXrPhi/ PwMisxnbl2kENR6+UmJtIVPM4KHrwA+mr4KN5hkxK5lN5dsQEqbf4MPkMvyW+w1IgAiw Hk2+SAJf7hRAsTsNH3o69GzP7kjVQHJcNgmtoHYQwh8mx3PXQ0mxCx3+ZKZHIhFCZmdO vnVw== 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=qtJc7KhlPcszEzQsnrOaMiDYMC+0zAqKB3hPemasz4M=; fh=xJCJY1yj/SYzdEIhHhlf7nE521InIj2qCVgn5a5q7J8=; b=aELqVQGtGJWck06rJq0+kk++P15f9Aptr1QOn1u+dfgmjn6rQxMcz3aCwI9eVPLQ3V xnv8qmgzEg8COWAM+t4jgoL6LMxQTUxA9nd3Q7QH8B62WHVgUGr+vuNWXze9wG7no2lH TU+xngHVo9psGmVWmAQEnb11DejN4sH9nomFSFcooqDmBEjq0E1u0CpX+pbEe0tzT84E ZUN7eGeRGJn8M5Oh79MyrcP5iBk6+m1Id/Li2SRFm3C307b4j/wXkRBw/jkXfX4gE/IQ O38AoSl/Y9yL7LL/cTURLapryYeWBedCF4bm7Yuptcb6cNJXkhAG3gxoD8H2kna4Kocc bQvQ==; 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=1775784602; x=1776389402; 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=qtJc7KhlPcszEzQsnrOaMiDYMC+0zAqKB3hPemasz4M=; b=KAbyU7mrO1/75AWNy5GkxzJkeVqLhtvaLrNhwbKyOZgoGHpoltR1tLwXVI+noQ6b5J zpQF7rvPsMX3JpPuybtmtthRP458tdJAiC53kNKbptXMZxEU23uA/HCxztNr7vc+4JE+ v/DNyrEjDDEpvxPNRRD4HGQ6HJr/eUl5na/n8Yw78YJwjFjz3uINI9BQW7OFJHZgv2Iv RLoHXqpPGKCWE+XhNhUIGPNJ6oZTjzkhElBHzmHtY2LlP5AAWvUS5wUZh7hpbj+e8D1V pkvLY/K3bWW8ltGJQuCWmmzLoy9NmTF2P+hGDn/RTAp75WeTl8MD2ZsLqoXgzzo2rjjP /REw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775784602; x=1776389402; 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=qtJc7KhlPcszEzQsnrOaMiDYMC+0zAqKB3hPemasz4M=; b=hDuklDYex867G2WOov+1YsAnnBYLHMkNnMyGy7TjAWzN5PLzHw+VnfBHWQSir5EVcS LcRP+l2xGfje5O3EnsmKbhw5YVWiIgunbAnfVH8jI9CX0zqi1rhIzWTgBKRtc2YXvFxt q/KeSODnArWd9O00Kj+cw4VdB8ou3mMhXa3eHJaMeGEXYgWHK4IAvw6BqG6zmHgqYMRI CvnCxFOvcB9YyjtSVXJQIIyt5tQ8SorsinsmhiSqRrcgkAlRCeUUdCZNbceF3wxdi3we L/UCkxRX/pRhOAwJqCl9mD69Z8lFiqilrtLdvuYaWKA2IIfmOEwjS7lsmaY51VGromeW e3Sw== X-Gm-Message-State: AOJu0Yz54XfJ6DV2DNcWiR9qZEDnYx+yYfqnOa8vWWH180EPHa8vnKXh MPnqR23DIVz+xEctfG089dii1Nsj/+1iw91QWXuZyWHFW3UuJzm4Z63grkMRGt2eJ4PiG8Ts4Wm jdl7lRIQcdXbBtoQuWFmQSZg4sIAFlYU= X-Gm-Gg: AeBDiesaoXvGJS6Q0kjWfVZ0Ylk429DkUGe+7b4iYk27LxCprKOPa40u+qhDd/gY47L ZMEtD9pJ/K19dX3OFhC5A/hBk91AMBISDcUrw14ETHgjxGI6zGdcs40cBLjAFPPM+To0JFf1lvE A93vwrKeaLInMAFVCCiEvW+jRg4gcwa8/TY7JYGprYoLVXxaHshOILo/bSOxAvlK1JuHWYAOsfY RP1kJ7uybRze29QGZUY5i58hLyamq9p5Lr8t7umNUI8PFeUUmqcsIV5CHfl+wRrCwtlcCBGOkRj TkIQ+N7ZQ9SVhxiqZIo= X-Received: by 2002:a17:907:26ce:b0:b9c:2c55:338c with SMTP id a640c23a62f3a-b9d72661585mr68842266b.25.1775784602117; Thu, 09 Apr 2026 18:30:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Tender Wang Date: Fri, 10 Apr 2026 09:29:48 +0800 X-Gm-Features: AQROBzDDSdhTIkYCmtlE2Za1gCn3G0XD1jLN1YGmb66WHc1DKOxmN4mmDByLW3k Message-ID: Subject: Re: Bug: var_is_nonnullable() gives wrong results for old/new in RETURNING To: SATYANARAYANA NARLAPURAM Cc: PostgreSQL Hackers , Richard Guo 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 SATYANARAYANA NARLAPURAM =E4=BA=8E2026=E5=B9=B4= 4=E6=9C=8810=E6=97=A5=E5=91=A8=E4=BA=94 02:43=E5=86=99=E9=81=93=EF=BC=9A > > Hi hackers, > > It appears the optimizer incorrectly simplifies old. IS NULL to FALS= E in RETURNING clauses when the underlying column has a NOT NULL constraint= . > > The issue is that var_is_nonnullable() in clauses.c doesn't check Var.var= returningtype. It sees a NOT NULL column and concludes the Var can never be= NULL. > But this assumption is wrong for old.* and new.* references. Because the = old tuple doesn't exist on INSERT, and the new tuple doesn't exist on DELET= E > I am not super familiar with this area, so I attempted to fix this as in = the patch attached. Yes, the current var_is_nonnullable() ignores this case. The attached patch seems ok to me. Add Richard to the cc list. He may know more about this. --=20 Thanks, Tender Wang