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.94.2) (envelope-from ) id 1usLBg-003gRB-1V for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Aug 2025 13:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1usLBe-00FRCU-Pf for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Aug 2025 13:00:07 +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.94.2) (envelope-from ) id 1usLBe-00FRCL-AB for pgsql-hackers@lists.postgresql.org; Sat, 30 Aug 2025 13:00:07 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1usLBc-002Wor-1H for pgsql-hackers@lists.postgresql.org; Sat, 30 Aug 2025 13:00:06 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3d1bf79d758so479600f8f.1 for ; Sat, 30 Aug 2025 06:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756558803; x=1757163603; darn=lists.postgresql.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SC0Sjx4mOJjqf/Vso8WfPQsi4rnGLrA10fIrXRmgY28=; b=bszs2ogRHIACVGiJ/e2Lc6qGFqQS77HjkarohwPpnmJ3i7OYH5TM7qbZwpyoAtoDxD IsRWLmwii1nGIMNCrcOyrmUHbOSY9M57bBZfqTN8CYpzI3kPLK844JEvyO9qrUE/zZhP qHocNn21mIUNcRJsHOvp3iYFRUy9EWTxx4IM4628bjZ05fUlL2tqaPBLsQS6ZGWwG/ur vnFc/el72v6wXm7ID7wjesRHNSZJuFUfiWi7myLvzeuC4AgYQgYKSoo0SobtmV7uVcx3 oKKUG8ZYxzFt6clugYbT5FJ3oFf1wUOyqZmncRyXLId+evHZbk14nwdSoaGyT/dV/mPH JCBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756558803; x=1757163603; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=SC0Sjx4mOJjqf/Vso8WfPQsi4rnGLrA10fIrXRmgY28=; b=B/NOU2/koH1pOdkDza1kybRVTaCUznOfsKO9lEraLO+ERNfosTPQ2InTAHGZYBTdph e1dRHspsBFpFHVfvpvzPJ34fTXcQCxB72JE/0+v4I99DYguKNzp7l3+iXRo3JmL/xDO6 JyVHek/HeFBFx3xQBkBY5sBechOljSGi5QSzzUUA5s8PsVAhee0LObdKFvRKjpa8B4r5 jA7p1AJnCC4+tyGvXKL6W37a1fjrOpOEdBnHwuLAb3ClF3ns3a9ajuN9no9mWdUQpS/y F4E8foSShz72SDKCQ+Xboktb3zHVn7ZBmyCz3LwpWtcnD08au2eab4y8+PGQhKl/g2oN bMFg== X-Forwarded-Encrypted: i=1; AJvYcCXa1Bm3KdUBzXlwXnI1h3w1wKt3Qi3dqDTK4j+i6Im2zCJuv5djp+8n3pAJ7tabvzbeojuQW7HGVB+8nkzi@lists.postgresql.org X-Gm-Message-State: AOJu0Ywru9bSVED68AhwGonINAB35Qj5m9P1eq+0sRCd73DOFaCTo35n rojtSK7f8V7Scsqkh4Fo/fNRwwOdeeryJa7Kl6R+NRfpBnGlSDgaOa0h X-Gm-Gg: ASbGncv/GmsRQW6TZ4X2v9uG9BqeCsyMsJvnncdbSHZXEgpmDOJuVxqx/9JTUDwpeQe SDVmoYx23XSo5vFD/d75j3SwGHXFlBYtTwBkOMRzsbeGamypjYJyZDh5G7l6qIYQHn6tLU1OKIm MkHhwJ8ocmxeff8zRReLTTj/a94IHOMwujhCQiAXrt5X/gHwM8VJMimqsrCFZMlK4dEubnVacyU YSPxo8Y8NMhPY1I7sejOZIZJUzz3GUbi5gcZ/QxttYw/oFYuzwyAF/R0qx22rWYKLjL5+c3lWBE fbQNe4hfLPkvZ8wG4n9u4MiubOFvGBwHFaTC4LztuiFlyTnT5Qs/+OUUMnsfmvjkuJdT+NsViHo evNLSoL0V7XU0rifeKYGA8Ivxtg== X-Google-Smtp-Source: AGHT+IGJtWuPumH4CmRiPcQJmEASYbBSv1MtU989OQCZmkrha26fXEy75KW7voof8qRidbXhkFsKSg== X-Received: by 2002:a5d:5888:0:b0:3ca:ca52:adb8 with SMTP id ffacd0b85a97d-3d1dfcfb9a8mr1393772f8f.36.1756558803238; Sat, 30 Aug 2025 06:00:03 -0700 (PDT) Received: from [192.168.0.50] ([89.149.120.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3d1052db1f0sm5719461f8f.23.2025.08.30.06.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Aug 2025 06:00:02 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------0PMfUN0Nj31EFVbUEIQtaIQr" Message-ID: <9b10b847-067e-45cf-bbf7-7802b6303fc0@gmail.com> Date: Sat, 30 Aug 2025 16:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Correction of RowMark Removal During Sel-Join Elimination To: Alexander Korotkov , Andrei Lepikhov Cc: Greg Sabino Mullane , PostgreSQL Hackers References: <18c6bd6c-6d2a-419a-b0da-dfedef34b585@gmail.com> Content-Language: en-US From: Alexander Lakhin In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------0PMfUN0Nj31EFVbUEIQtaIQr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Alexander, 24.08.2025 03:44, Alexander Korotkov wrote: > Thank you for catching this. And thank you for the fix. I think it > worth separating fix and refactoring. This helps to understand what > exactly the fix is by looking at the patch. I also edited commit > message. I'm going to push this if no objections. Please try the following script: create table t1(i1 int primary key); create table t2 (i2 int, check (i2 is not null)); set constraint_exclusion = 'on'; select 1 from t1 right join t2 on i1 = i2 where (select true); which triggers (starting from 5f6f951f8): Core was generated by `postgres: law regression [local] SELECT                                       '. Program terminated with signal SIGSEGV, Segmentation fault. #0  0x000058dd6a7b6014 in var_is_nonnullable (root=0x58dd78d505f8, var=0x58dd78d75610, use_rel_info=false) at clauses.c:4242 4242                    if (rte->inh && rte->relkind != RELKIND_PARTITIONED_TABLE) (gdb) bt #0  0x000058dd6a7b6014 in var_is_nonnullable (root=0x58dd78d505f8, var=0x58dd78d75610, use_rel_info=false) at clauses.c:4242 #1  0x000058dd6a7b4f74 in eval_const_expressions_mutator (node=0x58dd78d75590, context=0x7fff875a9f00) at clauses.c:3556 #2  0x000058dd6a7b2935 in eval_const_expressions (root=0x58dd78d505f8, node=0x58dd78d75590) at clauses.c:2272 #3  0x000058dd6a7c857d in get_relation_constraints (root=0x58dd78d505f8, relationObjectId=16385, rel=0x58dd78d738e0, include_noinherit=true, include_notnull=true, include_partition=true) at plancat.c:1419 #4  0x000058dd6a7c8fdb in relation_excluded_by_constraints (root=0x58dd78d505f8, rel=0x58dd78d738e0, rte=0x58dd78c6b968) at plancat.c:1808 #5  0x000058dd6a73675e in set_rel_size (root=0x58dd78d505f8, rel=0x58dd78d738e0, rti=2, rte=0x58dd78c6b968) at allpaths.c:364 #6  0x000058dd6a73664c in set_base_rel_sizes (root=0x58dd78d505f8) at allpaths.c:322 #7  0x000058dd6a73631e in make_one_rel (root=0x58dd78d505f8, joinlist=0x58dd78d74a90) at allpaths.c:183 ... Discovered with SQLsmith. Best regards, Alexander --------------0PMfUN0Nj31EFVbUEIQtaIQr Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Alexander,

24.08.2025 03:44, Alexander Korotkov wrote:
Thank you for catching this.  And thank you for the fix.  I think it
worth separating fix and refactoring.  This helps to understand what
exactly the fix is by looking at the patch.  I also edited commit
message.  I'm going to push this if no objections.

Please try the following script:
create table t1(i1 int primary key);
create table t2 (i2 int, check (i2 is not null));

set constraint_exclusion = 'on';

select 1 from t1 right join t2 on i1 = i2 where (select true);

which triggers (starting from 5f6f951f8):
Core was generated by `postgres: law regression [local] SELECT                                       '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000058dd6a7b6014 in var_is_nonnullable (root=0x58dd78d505f8, var=0x58dd78d75610, use_rel_info=false) at clauses.c:4242
4242                    if (rte->inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
(gdb) bt
#0  0x000058dd6a7b6014 in var_is_nonnullable (root=0x58dd78d505f8, var=0x58dd78d75610, use_rel_info=false) at clauses.c:4242
#1  0x000058dd6a7b4f74 in eval_const_expressions_mutator (node=0x58dd78d75590, context=0x7fff875a9f00) at clauses.c:3556
#2  0x000058dd6a7b2935 in eval_const_expressions (root=0x58dd78d505f8, node=0x58dd78d75590) at clauses.c:2272
#3  0x000058dd6a7c857d in get_relation_constraints (root=0x58dd78d505f8, relationObjectId=16385, rel=0x58dd78d738e0, include_noinherit=true, include_notnull=true, include_partition=true) at plancat.c:1419
#4  0x000058dd6a7c8fdb in relation_excluded_by_constraints (root=0x58dd78d505f8, rel=0x58dd78d738e0, rte=0x58dd78c6b968) at plancat.c:1808
#5  0x000058dd6a73675e in set_rel_size (root=0x58dd78d505f8, rel=0x58dd78d738e0, rti=2, rte=0x58dd78c6b968) at allpaths.c:364
#6  0x000058dd6a73664c in set_base_rel_sizes (root=0x58dd78d505f8) at allpaths.c:322
#7  0x000058dd6a73631e in make_one_rel (root=0x58dd78d505f8, joinlist=0x58dd78d74a90) at allpaths.c:183
...

Discovered with SQLsmith.

Best regards,
Alexander
--------------0PMfUN0Nj31EFVbUEIQtaIQr--