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 1wQMvY-001V6N-36 for pgsql-bugs@arkaria.postgresql.org; Fri, 22 May 2026 10:16:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wQMvW-00Cvm7-0j for pgsql-bugs@arkaria.postgresql.org; Fri, 22 May 2026 10:16:23 +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 1wQMvV-00Cvlz-2r for pgsql-bugs@lists.postgresql.org; Fri, 22 May 2026 10:16:22 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wQMvU-00000000sBS-2qyp for pgsql-bugs@lists.postgresql.org; Fri, 22 May 2026 10:16:22 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4903cbfad68so10481915e9.0 for ; Fri, 22 May 2026 03:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779444979; x=1780049779; darn=lists.postgresql.org; h=content-transfer-encoding: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=2KNHucSzsQi9Xl83/JTkUGfly+iCj2pVdI+FueqNdTs=; b=ohviV4fPPy/Z/HVEN/j5Tp6WRuYxFRZuyiebJu0Nll2Wmad8ufBevcqZWsVbONMSqI egg+Zmz8ZlBXVpzeLP4qGl7p44ancAJOpLh/RA0TXOH33J4YTnNxtg8KqM0uy53IRy7/ Ij76L+JJoHIIwgnteME0BKnZtPoahB7fHTxEE84AAuJs/E31WsdNJtXvXlIZ5wLBQ9jh Y+q1rgadL3m97OMBPk1ZIhxMzmM6fiZyAb3NkH6wgFjIxVhM7mgz+DZZt2ANh+S3JQRc eTeBBzXkptXKxYacJxLFcnkzY+AaaoUfEKmex9g6khf1LSrBEN2TejZkJv6K6V4WyQ0x SVsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779444979; x=1780049779; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2KNHucSzsQi9Xl83/JTkUGfly+iCj2pVdI+FueqNdTs=; b=h+Xo4H1kgMxe00bok4S4gqRo0SUbIAkG++KrN3qTduyxarykLH2/3hDlGFRvqiwAXD 5F4QrYwEtm9fROrZQQ/9oJwVid+tCR6rtqufJliDkNj3RqysvvlZVUeT7WJ2cXLO1vaq B+pgtRLchLr18I9UnHIW1kptD4ORtBDT4xK7tla5t7ZatercNUfkf8L1ZmdhSIhm9UcT +7E9ubuGEk/WZ8pBdVTUUGNL/c2uXHe0ka3LHRHPHnvdcU6zgpfysBvDPVW8UE4Y4kV6 VWbIsiBkMVxfcJ/HXa7OE9VXVQlaLQTbJSaDEnJ9rH4rPlgPKJJRr/grdNM9pYAM1++L Z0cA== X-Forwarded-Encrypted: i=1; AFNElJ9osSOqUjPwnWE5ppy4Iwq2nU18IDyjif+5+nt2vq1g+JSv0LadWwtyHy1KSbU9hmBXUa6/mtHsPTuk@lists.postgresql.org X-Gm-Message-State: AOJu0YzA3VFOXBGRnIK3HJ+6DWkv5dAzd0DDOAH76/WtrjK7XFy+xZ29 oEGRwqfVOf7ywnh1o8GnWIxkBBPc2WfsgntDZdvk+i50EiTCZ7aNBv9J X-Gm-Gg: Acq92OF9fAQlLLIZ0fPCylKkgl/NFLPk0cpritruJyyFxCzC+fswYu7rp58+ho+HfiI th+ZFnt7BNCSsAbMlxwYJzFEElAIShinJI/y57lacJDRuXIhWe4b2ycmzjzSsim8j7mF4vEdymT rvjs/IY8pClAU53oyyfb4qZQKwPUsWyrQoJwgqHzhe1flbLvbJV2sSfVIW9eAdlJ8tFzVwZEbTo uGkdGXz78fMYJr4G54Dy/Bpw8QO2K7TzGBmTS+FsYTOgA4VMO1Hh+J5HhxJamRrUtXxU3Jfe94Z jNXc8BnjjT9WSoL8x0IqMhodTNGVl0YI/JqAEbHEOajpz6GXa1TuyHqyRdLGy2o7IIN4LwN8beD +HvJX2VyDirT+KmGoc6Wl3ZRAy9kKbsIWQfAB7Wqfn1OGykEGQGF80qA8++LwHRslywEUwvQxBg qB7grKjOo5HDETv2gWby3k/uTY0xtMmrDki3S/tTH3mJmJDfY= X-Received: by 2002:a05:600c:3b07:b0:490:f7c:b19 with SMTP id 5b1f17b1804b1-490420f67f5mr31523155e9.0.1779444979069; Fri, 22 May 2026 03:16:19 -0700 (PDT) Received: from [192.168.15.82] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490454cfcaesm30615245e9.4.2026.05.22.03.16.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 May 2026 03:16:18 -0700 (PDT) Message-ID: <42e88e4b-0958-49a3-b32c-b61f9eec8da0@gmail.com> Date: Fri, 22 May 2026 12:16:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables To: Alexander Korotkov , Tender Wang Cc: Kirill Reshke , Fujii Masao , ammmkilo@163.com, pgsql-bugs@lists.postgresql.org References: <19435-3cc1a87f291129f1@postgresql.org> <5a039d60-d13b-4cf0-a807-9c7269f06831@gmail.com> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22/04/2026 17:10, Alexander Korotkov wrote: > On Fri, Mar 27, 2026 at 3:19 AM Tender Wang wrote: >>> but I'm unsure, in general, that this approach is conservative enough. >>> Maybe we shouldn’t change this logic and invent one more optimisation >>> ‘deduplication’ stage later, before the selectivity estimation stage. > > I have another approach about to deduplication of RestrictInfo's. The > field, which differs in this case, is outer_relids. AFAICS, > outer_relids and incompatible_relids serves as the restriction on what > we can do with RestrictInfo. So, what we can do is to ignore both > outer_relids and incompatible_relids during comparison, but compose a > union of their values for remaining RestrictInfo. That means that > remaining RestrictInfo will ancest all the restrictions, and that > should be safe. > > What do you think? Thank you for all the work you’ve put into de-duplicating clauses. I agree that using the union of outer_relids and incompatible_relids is the strictest common constraint. There shouldn’t be any issues, so this approach should work. However, the new function relies on a hand-picked list of "semantic" fields. If someone adds another field to RestrictInfo, this function could break without warning unless they remember to update it. We should add comment hooks that say, "If you add a field here, update analyzejoins.c too." Also, de-duplication happens in several places. If we change the logic in add_non_redundant_clauses, maybe we should review the update_eclasses() code as well. -- regards, Andrei Lepikhov, pgEdge