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 1tKaqx-009bFY-8B for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Dec 2024 10:18:59 +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 1tKaqu-006tg4-Kx for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Dec 2024 10:18:57 +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 1tKaqu-006tfw-B4 for pgsql-hackers@lists.postgresql.org; Mon, 09 Dec 2024 10:18:57 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tKaqs-001rxq-UJ for pgsql-hackers@lists.postgresql.org; Mon, 09 Dec 2024 10:18:56 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-84198253281so286011539f.0 for ; Mon, 09 Dec 2024 02:18:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733739534; x=1734344334; 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=NZUi/apOdcEpBxxWnlNApsMF6WkpcazLhkTGCMVjQpo=; b=YvL6i28sA12bBA+srsP2+dV0LUasZ8t2UeIPaRlmakfXMmJM74b77OgaGv0BiOgRtU 4+dFSF9DU3XB/1xNzxk58NekQH4kKRqMA54ytkgq8kDSRGesjRuAL2Z5p0zqLsyhhxHh h6biYgMO3fHzEnXQh6I8+aLCgnwBIwBxuYHlOKxBKj35BDWnW4+W8V94vHpYXsWgEBbQ uLKRyTwwTD4zHNtpO2GRz9qC40vuNEf2WgRQJU/862MIQlg9/oRR761u1U2LE87qSvVc WhB785nGJMm3D6WbLP+ljEAu/ILVwKk1wPo33TsK5WzGVS8KpkY7YKgebgNXhJ/IZbsv 6YnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733739534; x=1734344334; 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=NZUi/apOdcEpBxxWnlNApsMF6WkpcazLhkTGCMVjQpo=; b=NOBJn2OWGVI90vIDv5JFdMQ4hV53Ekfbzq/BhXWYslzt6qsr9ktnT6CTUMKmUVZBIP 0eVj7QS32zWlnsYyEjfm6bGoAtVQpzBprlHm0PcvnNpOb+7n/xk47eSUaymiLPosv0kg DIvblvTN6JQImoEW66O8pEtXnL9dFw6LhdAoBFWB2K/wQTSeyV6LQkvO088+/B9xQ/5i BaTMhNndskVz7k46umDx7QjYHlq5fnRH7rUxJHXrVdv51/65TENCAz97NT8wkoO0CHv1 zXEdMwT7/4JtIGo4pUGmKwjYJU0gxrhdSXMSgkOos70O93ptyT98cJboMALqlaowHVvh Lvtw== X-Forwarded-Encrypted: i=1; AJvYcCW/Ylv8dwtxt3JCQhvrg8u1Z+mxt+JZhPTxkH72GrElj6t9pC1Wwup5dc24WVnVIWqu1zCm8BBa3HzpwCTe@lists.postgresql.org X-Gm-Message-State: AOJu0YyXMiSxzoXFXwLqrkX/ZI19A7OgCPbxKqMqct7PNPlpRUHVZnhS iyFULLJpQdjYOj3a9CSjAvk18f920pWNeqatSyCzKXXNUGuYl2MUuy1dkw== X-Gm-Gg: ASbGncs6clIaRkTeHWXEvHx/GgOwb3tHBFEbVy5SJrb9Vd7P5EWdrmsSTzmngiieJTo MybPq95wvK5ayjuS6Re+2guhxPKdt0XFD8acSsnRD1+6wcjtCxiCdtO7HA6x7nJySs9gTa5gGas JOJfi/9ZcqVpQjaZUD/UGMxC/VDjfde+XGnIGaS6p7cYa6NC9mYK+z1bwKAgdxn8IupToLnniAS 6+E2aLdsdM2mTAjDAHZTAKNnK//hlwQ+zjUbUwYduYcXVvbLZ9e9H52ZVq2f/Cpi3YkLjIx8Zuj 82njnfDngJ3nbP51EOq+I75Z0z8= X-Google-Smtp-Source: AGHT+IFP7a2Bhc7UC+9ZnuGMPijInVTR/7Vp0SLmPBZtykgWQbSff16RZofvxDdKvhMut+xEdHklgg== X-Received: by 2002:a17:903:41c9:b0:215:a97a:c6bb with SMTP id d9443c01a7336-21614d19f3cmr186044105ad.12.1733711761695; Sun, 08 Dec 2024 18:36:01 -0800 (PST) Received: from [192.168.1.45] (cm-27-145-178-18.revip12.asianet.co.th. [27.145.178.18]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21614fcfb7asm46373915ad.164.2024.12.08.18.35.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Dec 2024 18:36:00 -0800 (PST) Message-ID: <50b7ecd9-7512-479b-8096-2bda4e0e7ac1@gmail.com> Date: Mon, 9 Dec 2024 09:35:57 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Do not scan index in right table if condition for left join evaluates to false using columns in left table To: Andres Freund Cc: Tom Lane , =?UTF-8?B?0JjQu9GM0Y8g0JbQsNGA0LrQvtCy?= , pgsql-hackers@lists.postgresql.org, p.petrov@postgrespro.ru References: <3510224.1733609212@sss.pgh.pa.us> <3517444.1733613195@sss.pgh.pa.us> <07d035c5-0e40-45ee-9c78-60a5dc6e9fae@gmail.com> <19969d0d-769c-42df-9ae5-3ca4ef2f44d0@gmail.com> 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 8/12/2024 23:37, Andres Freund wrote: > On 2024-12-08 15:44:23 +0700, Andrei Lepikhov wrote: >> On 8/12/2024 09:52, Andres Freund wrote: >>>> I think avoiding touching a hash table and an index under MergeJoin can also >>>> be beneficial. >>> >>> How would you get significant wins for mergejoins? You need to go through both >>> inner and outer anyway? > >> In my mind, this trick can be designed for specific cases like sales tables, >> as illustrated before and used by well-rounded developers. > > I'm not saying that the optimization isn't useful, just that i don't think it > makes much sense for mergeoins. > > Besides, at least as far as I can see, fundamentally not optimizing mergejoins > in any substantial manner, it also just doesn't seem likely that queries where > this optimization would come up are likely to be planned as mergejoins. If you > have a leftjoin to a category-style table, you're very rarely going to scan > the "main" table with an ordered index scan on the category key, which would > be required for a merge join. And sorting the main table once for each > to-be-joined-category-table isn't a desirable path most of the time either. > > I don't know what it means that it's to be "used by well-rounded > developers". We have to write the implementation in way it works regardless of > what kind of developer is using postgres. I got it, thanks. I agree that the profit for MJ & HJ cases looks modest. When designing the prototype, I realised that it seemed more "symmetrical" and logical to separate such 'one-sided' clauses during the planning for all types of join. But I don't insist on this statement. It would be OK even in the case of NestLoop (remember, we should change the NL cost model too). >> I'm not sure that such optimisation would be profitable in general. > > Are you suggesting it would only be enabled by a GUC? No, such a feature probably won't generate much overhead; I don't see any reason to cover it under a GUC. -- regards, Andrei Lepikhov