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 1s1gXE-00E2yj-6Q for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Apr 2024 06:00:12 +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 1s1gXA-004BRM-QB for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Apr 2024 06:00:09 +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 1s1gXA-004BRD-Dq for pgsql-hackers@lists.postgresql.org; Tue, 30 Apr 2024 06:00:09 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s1gX7-000j3g-Oh for pgsql-hackers@lists.postgresql.org; Tue, 30 Apr 2024 06:00:08 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2db6f5977e1so62121921fa.2 for ; Mon, 29 Apr 2024 23:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714456803; x=1715061603; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=n07POQQRu0zwkC6c09zAAXpsukGYiT7bRUuNW/GUEyM=; b=auQkIumLUjaFoMZJPQesk5tc2d8Ucnkeq9bZVjMAgkOKrgGbU9/R/zxTMG372M6edn Jh3cwwc13RoqZb/NHe4cJUgC0ZNg4eJGwj2obsSxf6JSk0EglFUdhdgVIbkxeNrrztC6 SJtBH3MOTJxT1BK4/As0sFwy3bfjZ8UaNGdNuavHXCm6vbUY7qkltmMYah0QYc3+vXJb 1wf3v9KIMQHhkQOPu4if907qpLIvzRfDUUwCVhRfPWMP4TCID3YbL5HC2I9BYV3ur66H QOlOgFPtFFSbO0RwmYkHbBXn35SJcn+YQiglcMWmtB28D2JIasqbR7W1vgnIzudq9lKD I3lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714456803; x=1715061603; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n07POQQRu0zwkC6c09zAAXpsukGYiT7bRUuNW/GUEyM=; b=ThLrc0cc5MJvO/OpTGrbSxu/IZQanPPts1hlyft6GYAuR7OaOsjdiDnIZ5UPFzCbS/ +cNU/Z5rLYJpC5+xBFzWaGi87gu7x9swq6Ic1g3B72xgW94b5rgHIJQEbm9Mry0aYAOl Sg2mD1F0WAI1PHwKo6Ts+ynfRow2F4q5+qQ5xZaUgxHuksURjnreQDGlA78cny0juwqk ZpKgHma3BfNgKX/9lmjXxqU38Wx4tGvBCNIF8dCHc5xB+3K15ROS9EGZYpyxSMUBtCrg vnry5aOUeiyNslL4eZyYYyNadgXxr37AsYl8a92taW0kITP24t+AFfZEOYAU0Dirbwmo YA9w== X-Forwarded-Encrypted: i=1; AJvYcCWx4cmYI6B6DqJW71XlsQyBOii6NQbcFy5/tjVmcWkfKeRqnx4nGaMeLdD6vRpQrBXeak2ia6UyUmwy+rxzfrgRv4t52BvK7XnhM+sAXoHQCr9P X-Gm-Message-State: AOJu0YxESmKCRkWjfdL+CFhLm/o59VTPpjxUWfJVWPIKmqPusMjOgiRA Q6Ul8wWjMd6Y/dzAtrrawc+Y/+VJSfN86n3Tm6sEEDfEwAmytJ9Q X-Google-Smtp-Source: AGHT+IGQQ6hbI0IypNu4iJUwxEgantrfrdeT4Y311YHkRbsJOrn+kcLtA50dYKnHPmz2CTYJBqBzPQ== X-Received: by 2002:a2e:a7cd:0:b0:2da:7af:e6a1 with SMTP id x13-20020a2ea7cd000000b002da07afe6a1mr1512878ljp.3.1714456802745; Mon, 29 Apr 2024 23:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.23.194]) by smtp.gmail.com with ESMTPSA id c19-20020a05651c015300b002d814bf6618sm3782811ljd.115.2024.04.29.23.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 23:00:01 -0700 (PDT) Message-ID: <0ed2cf02-e655-6ec7-a4fe-52fd8d572f65@gmail.com> Date: Tue, 30 Apr 2024 09:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Removing unneeded self joins Content-Language: en-US To: Alexander Korotkov , Andrei Lepikhov Cc: "Gregory Stark (as CFM)" , =?UTF-8?Q?Micha=c5=82_K=c5=82eczek?= , PostgreSQL Hackers References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru> <05469e80-454b-41d7-d04f-421f42bbd4a9@postgrespro.ru> <48c11b23-9c23-440e-9a3c-020e05196449@postgrespro.ru> <8800ccf2-ae82-461c-92a1-d4c0a22f8cf2@postgrespro.ru> <1bd80083-a13e-4e9f-a7ce-73c3faab521c@postgrespro.ru> <922623af-872e-4cdc-9238-129b18bee42d@postgrespro.ru> From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Alexander, 23.10.2023 12:47, Alexander Korotkov wrote: > I think this patch makes substantial improvement to query planning. > It has received plenty of reviews. The code is currently in quite > good shape. I didn't manage to find the cases when this optimization > causes significant overhead to planning time. Even if such cases will > be spotted there is a GUC option to disable this feature. So, I'll > push this if there are no objections. I've discovered another failure, introduced by d3d55ce57. Please try the following: CREATE TABLE t (a int unique, b float); SELECT * FROM t NATURAL JOIN LATERAL  (SELECT * FROM t t2 TABLESAMPLE SYSTEM (t.b)) t2; With asserts enabled, it triggers TRAP: failed Assert("!bms_is_member(rti, lateral_relids)"), File: "initsplan.c", Line: 697, PID: 3074054 ExceptionalCondition at assert.c:52:13 create_lateral_join_info at initsplan.c:700:8 query_planner at planmain.c:257:2 grouping_planner at planner.c:1523:17 subquery_planner at planner.c:1098:2 standard_planner at planner.c:415:9 planner at planner.c:282:12 pg_plan_query at postgres.c:904:9 pg_plan_queries at postgres.c:996:11 exec_simple_query at postgres.c:1193:19 PostgresMain at postgres.c:4684:27 With no asserts, I get: ERROR:  failed to construct the join relation Please take a look at this. Best regards, Alexander