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 1vsWjL-005Yqp-2l for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Feb 2026 01:51: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 1vsWjK-00DV0M-2h for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Feb 2026 01:51: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 1vsWjK-00DV0E-1e for pgsql-bugs@lists.postgresql.org; Wed, 18 Feb 2026 01:51:54 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vsWjH-0000000197q-2ZCn for pgsql-bugs@lists.postgresql.org; Wed, 18 Feb 2026 01:51:53 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-463d81452abso1686994b6e.0 for ; Tue, 17 Feb 2026 17:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771379511; cv=none; d=google.com; s=arc-20240605; b=a4UnDUd9Ip1vUx46gN2gseXzXTYNSqAstxhNeHXoSCLiqKZ2dsckekEu3ZvRxu8UC2 4P42SWBmzqnuULvLGXaaeESYrCohk4D3L0UwDVmFfz8oBDFst5d8/540CpaEzFC1+qC9 lA0icV/Jh6cATfMKZsPs1EsYENWCxudplyAnIQshVM74HiAPJJZAr7hF9nU2oYVVbPeM zSpAT5p9FJoapJx+QToDF5VLH+3cGALwiAcBK6PqXPdc6AJpADR734rzC65MGX9DRFrR z80/owr1Rbm0P8Ogqt7zPCwbCjwDYO5ao8e20UjQmkpI+Pso4vHQ1JlbShbha8iwU5yH pA9A== 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=5OykvBmQc2srloU773QDLuKHYUaPGJAvC6EsjELasPI=; fh=zErLeNZP36TOh02+NJjvWX2hL5ydtbQW9N5XP0BA13w=; b=YJBCLW7wX2CO8Zf3l7UPcMG4qw6BbKCeo7VGsLMvAqqBzAxsMqW313lNsP8Nwi1STZ iVhWp7tnU+xcZtm7fGcSzilJfgvFV8TWra4O7ak6rxThDGy2+Vz1tQKZ0XsRRRUTRbiD xpwiq9uVwEAiz3M2D4Cfx3slx/kXxqG975eKNqrfPIcxr1JtNlTSBZMdhpLdLH+Qhl0v dKX7uIujnXNkSllz1nwvhZthuDnXMhWrGf9BG8+aOxeM1vipiyEvtp2wjNyr6k05NFEz OuPSBmzOwWwntztFC57aSK4/K2zxOR7a4frUXUYlri9BqwjEFAxFd+gDAkuhAHi6v+1t qeXQ==; 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=20230601; t=1771379511; x=1771984311; 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=5OykvBmQc2srloU773QDLuKHYUaPGJAvC6EsjELasPI=; b=Ndc7gAneAKrhpwdXTHSbck1BCqnPh9SS95KmA+CMmyUcG2WSgqRplRXw7j6BOtAyDQ XzMfWNefzY+cosRQHzP/Zr9hZi6vCCOTOeWFjjLCf0RPpYmXgxMTTfoozYMwha9tqmWH pYskJrEXi4MFA2ZMxjtVdqslARUHPMO1VK9/1Gn0eeHBBJiUxcE570XbrBz02tR/90wd 8r/Ba8CBGJCZJIs8hrgSnNAUVlBXIkhsPCzywBb+P1YaGDEUHWKyRRJ206jR4FbtJAfR SoED9jzW2gW6DaXxsj9bxt2/8mhKMk+S9Fazuyfdz2PIE3j2/RF0O+4PZVdozqw8ERFH hoIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771379511; x=1771984311; 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=5OykvBmQc2srloU773QDLuKHYUaPGJAvC6EsjELasPI=; b=AEGeRkCyXjq8FqkQxDCFylLGSfdMd2NyVfQpKe/ntg7oueju7rcv2BEmaNeru8u6CD f5nfK0HrU7Zd5z87A7PPa8FmDA28tPg81aa5vjGCsF6oTa7+6TRYxlOCUqpZ/vxcopgR ctrtQrbtTooFTtmFWEV+NswS8N6iR+iDQ93D4XVe70Fd40R8mi4cuLS+0czabuY7kjn2 Czsdgq2xOKCm3vYqyeIOmqieXyC3qJ16FIanUZnWLSwomMXJgFZXeYzVx+iFf+EawA3w 1njloxv5ucd3xQqNyihPmDfTBKHjC2bhpdBau6mvlOq0avBPF/ce8Dw1s/dhUQ2bTw9c Tmrw== X-Forwarded-Encrypted: i=1; AJvYcCWFyX7xjsqa0CyqxupfrXZHSQ/p9+UrOyDdhGrrRiJ2ICSo++nCXnPf80wcQtISOpbFonM6HM2J0ho6@lists.postgresql.org X-Gm-Message-State: AOJu0Yw86yVg8y8eevWBsG8k7OBMkVxeyNMABncS96BLL4jGFav7p/c7 B3SDf8gADk/b9j2XKD+P1DIyFKqp7XgWejX9Y1SKpcoZGkWCFxLLXQ+/cEpcD/DgjqYPIF35OHX I99JfMMBxK1PjALcEWAwltM/7Pjnya8w= X-Gm-Gg: AZuq6aI578tjyxXvca60R6n0jCAOErnmkIfJp5mW6agSKL7Vj3lCCfQw8uK5iXDqi0v n4mliU4kJaTRUINQzZQ9FU5F+/vGyb9zxIDCBbwEFXixsjRA8t6TkWePbdUZhNDshRPS2HLZpnj v2SGmUvWlZK2RQ1kb4o4EtMytA/11XEaKUPJZT0KnS8jGbteQUBUojK6l1yQGk2U8eO7NCgdX0x /anyuR9tkCaa3+reDALheVicC0BElnhnEt8vbX0DOPrg7iTjFpi8JCo64TT/BahB1fWX10eZjwI So7oYkeMSQ== X-Received: by 2002:a05:6808:30a0:b0:463:96c7:cba0 with SMTP id 5614622812f47-46410d4c94cmr204442b6e.63.1771379511121; Tue, 17 Feb 2026 17:51:51 -0800 (PST) MIME-Version: 1.0 References: <19412-1d0318089b86859e@postgresql.org> In-Reply-To: From: Richard Guo Date: Wed, 18 Feb 2026 10:51:40 +0900 X-Gm-Features: AaiRm50aP7uDQXq8ZudX6Gk1thv1KpxhEMa_yp0CqulKd4tjWwpHjG243gIEzTg Message-ID: Subject: Re: BUG #19412: Wrong query result with not null constraint To: David Rowley Cc: s.shinderuk@postgrespro.ru, pgsql-bugs@lists.postgresql.org, 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 On Wed, Feb 18, 2026 at 7:54=E2=80=AFAM David Rowley = wrote: > On Wed, 18 Feb 2026 at 00:31, PG Bug reporting form > wrote: > > create table a (id int, x_id int, y_id int); > > insert into a values (1, 1, 1), (1, 2, 2), (1, 3, 3); > > create table x (id int, nm text, constraint pk_x_id primary key (id)); > > insert into x values (1, 'x1'), (2, 'x2'), (3, 'x3'); > > create table y (id int, nm text, constraint pk_y_id primary key (id)); > > insert into y values (1, 'y1'), (3, 'y3'), (4, 'y4'); > > > > select a.id, z.id > > from a > > join x on x.id =3D a.x_id > > left join y on y.id =3D a.y_id > > join lateral(select x.id > > union all > > select y.id) z on z.id is not null; > Thanks for the reproducer. > > I'd say that y.id Var in the lateral join should be getting marked as > nullable by the left join, but it's not being marked as nullable by > anything. Exactly. I think this is because when adjust_appendrel_attrs_mutator propagates the nullingrel bits from the parent rel's Var into the translated Var, it loses the translated Var's original bits. Instead of overwriting the translated Var's nullingrels, I think we should merge them. --- a/src/backend/optimizer/util/appendinfo.c +++ b/src/backend/optimizer/util/appendinfo.c @@ -291,8 +291,11 @@ adjust_appendrel_attrs_mutator(Node *node, var->varattno, get_rel_name(appinfo->parent_reloid)); if (IsA(newnode, Var)) { - ((Var *) newnode)->varreturningtype =3D var->varreturningtype; - ((Var *) newnode)->varnullingrels =3D var->varnullingrels; + Var *newvar =3D (Var *) newnode; + + newvar->varreturningtype =3D var->varreturningtype; + newvar->varnullingrels =3D bms_add_members(newvar->varnullingre= ls, + var->varnullingrels); } - Richard