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 1tmKDN-005p8w-QF for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Feb 2025 22:12:46 +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 1tmKDL-00DZhP-96 for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Feb 2025 22:12:43 +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 1tmKDK-00DZgK-Ta for pgsql-hackers@lists.postgresql.org; Sun, 23 Feb 2025 22:12:42 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tmKDI-000MmC-04 for pgsql-hackers@lists.postgresql.org; Sun, 23 Feb 2025 22:12:42 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4397dff185fso33238965e9.2 for ; Sun, 23 Feb 2025 14:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740348759; x=1740953559; 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=XIlJKT3/6Xp9/y2JqFZ6St43GFX8VSE+GoMLFIw96kU=; b=bJ+kGgvoC/3cOPn1xYDz4ceRRM/aqKRwE9TNjyIQNhb/0nCAmVSZ9fQtmADUtTQP0e DKOiMRPPSHH8CCDfUYlRF6Nme3LcjAykb1opIoxz8uPla9H+AfoQbvDsAiIL9lacqvkY 3+K27/+FdidzpBys5o1uAtLagYTOlczQ62nE0kx6S4U1PksX/nylVI4S1umwHgmq2rkP CPFtSY/HWDF9aXUU/Ywd+1srD41OPuD13vZtrvZc9KoZXd5+r3DGXjzIEDiTcFHIMIAu rFbgozcq0CNcQnfrboZTN6rTErlupgyBT1SJiDl6nv0nav4jW6pffBI/01bCMH/JKmgf pGZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740348759; x=1740953559; h=content-transfer-encoding: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=XIlJKT3/6Xp9/y2JqFZ6St43GFX8VSE+GoMLFIw96kU=; b=gFfXMlY0BdhupKpV2iUqle3lW4NY6JFXtwkn87pRIUa/FT9YY07BvaBi3ZG2xLfSZF dI//p9aCnzypSrA8ps1VQI0gY/HN3s/2YGSucBogDC21G01/9HDBQ9uUnNUFl0Bxko3Z q3SHTMOiFPgjBEXR1FwfrlfOZU0PFl+auqveJnVeN+AyN3W81XT8wQeCR7u4G0wTrg7p fFlqpPOX28cfp1fuP2fVbnGAzI02351iXuIYetVg6hNtJn6qiP3M+dLMEgW6OPIIRb/o omjIFqBBGnH0JBOGgIAj1jeYw3lKcInOEYqkkhv/bUvRUZVGpKyIDjFAiNgRA7Aqq8K9 kqig== X-Forwarded-Encrypted: i=1; AJvYcCUXypb3EbXSk+9WJQvTT530l69nYQzBmCLlJe8DESukwcmM0YyyUGc6h2PeNHCHj2pqA29lmajDj7FRwiL1@lists.postgresql.org X-Gm-Message-State: AOJu0YynOOJh2e6K+gDX4zUfrnGJAbW75TJuSz2FfztVcjRp9zN3FmPT j4STCFLCkmxVSk1EiZMoO1EOd0z5+KqRzPfQOyirbSUYihJPHhcA X-Gm-Gg: ASbGncuYkjY8JbUL2T2jmfzwWheHZPx9m9OzLoeuAKRJT+n5ds7HiDJ7Vxkn79Ag+oI eUF4azSUzZxxmswT5uI3E8IJUKCWg0e+dPOcSqUOcC00DHb1tEvXr1XEOdqLRNDOUVeMYtp8j0k BZo+z29lKqGvSPi4e+2UBu1KEfJv4qFB7cOj0vv8IyI4Qjy4wLTfty6pRaCQ4scUZVMvaBObmPO Vd3UzSLlIL8zlfClWZ/KE5jZK2koeBvl0Odrl2/ZVRSFe+Ke8AO7q5YyQhY3KIRheCJfEw7Qr75 9rAI7iGEyQtsjwU51/wLGlb7d4SHtySflVyW0k/He1oddDgNnrSlTw9irbL13fIk0dy8RYLnVrg Qor1iJ7Jj5ZvC8BAiQfM= X-Google-Smtp-Source: AGHT+IHZVVNJEc7HGOv2gCUSP8bfivjUZSlsI9x0FazrxrnG4Hjh+W+8rJJAX8xcU6bWbXMxg+adgg== X-Received: by 2002:a05:600c:348f:b0:439:84f8:60d7 with SMTP id 5b1f17b1804b1-439b5be9481mr77078155e9.10.1740348758662; Sun, 23 Feb 2025 14:12:38 -0800 (PST) Received: from ?IPV6:2a0c:5a81:b804:e00:8518:1fc1:cc21:36be? ([2a0c:5a81:b804:e00:8518:1fc1:cc21:36be]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f25915785sm30717763f8f.58.2025.02.23.14.12.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Feb 2025 14:12:37 -0800 (PST) Message-ID: Date: Sun, 23 Feb 2025 23:12:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Removing unneeded self joins To: Alexander Korotkov , Tom Lane Cc: Alena Rybakina , PostgreSQL Hackers , Robert Haas , Richard Guo , Alexander Lakhin , "Gregory Stark (as CFM)" , =?UTF-8?Q?Micha=C5=82_K=C5=82eczek?= , Dean Rasheed References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru> <3622801.1715010885@sss.pgh.pa.us> <5934ce1e-be02-4640-904c-f7fec3962784@gmail.com> <914330.1740330169@sss.pgh.pa.us> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 23/2/2025 22:15, Alexander Korotkov wrote: > There is my attempt to implement this approach. Getting rid of local > variable (and computation of the same value other way) required to > change arguments of remove_rel_from_eclass() as well. I'm going to > further polish this tomorrow. I passed through the patch. It works correctly. Multiple ifs in a single routine is not ideal. I have thought about it already, and it seems the remove_rel_from_query needs refactoring: when I first reused it for self-join removal, we didn't have the 'ojrelid' machinery, and it was implemented smoothly. Right now, this code contains multiple places where we need to remove the outer join relid and separating the removal code for the baserel and outer join may simplify the logic and make it safer. But the way to do it is not apparent now. May be if we implement a new technique of query tree reduction, the approach will become more evident. -- regards, Andrei Lepikhov