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 1qiyy9-008mmT-Hk for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Sep 2023 15:18:26 +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 1qiyy7-000qVl-Uf for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Sep 2023 15:18:23 +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 1qiyy7-000qVF-Fj for pgsql-hackers@lists.postgresql.org; Wed, 20 Sep 2023 15:18:23 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qiyy3-005e5R-Lh for pgsql-hackers@lists.postgresql.org; Wed, 20 Sep 2023 15:18:22 +0000 Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com [66.111.4.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id EE77EE20423; Wed, 20 Sep 2023 18:18:15 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1695223096; bh=pNLLZ63p8899YuPrict0K0XKFH/q07yH/LOaHPj3Eaw=; h=User-Agent:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:From; b=V9pk/50GdWWpNpT/diFoCqSmlTJAib2iUyNnFtZP/LIGpJwMOphS7DPSRE8URce+F DeuaH4JCT7bPfiXfDG+IZ7yU6bbZsSKjk1kKjUGLL8lOUSCkz/9l0jeoZUbdEcSR6v gX4LHl9ooUaavw4neRX53j/e06O8oyAsuDpYLPgibhPHivNsBBQRyXmQMQ4A3FVFyq lhfdPAkTvyYDzkX59MA3oF7rSOYxOUjD4DpGivsCe3UifVU0n3zSixlxX+JE69L9A/ HE2RyvlCh6TYOQAt+6AOTkk4sidg7fbRdhf3XOdiqqyruObR9aZjm9PC/k/3OUrnIC UJmI+mMRJ+qXg== Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 2610C27C005A; Wed, 20 Sep 2023 11:18:14 -0400 (EDT) Received: from imap44 ([10.202.2.94]) by compute1.internal (MEProxy); Wed, 20 Sep 2023 11:18:14 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekfedgkeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedfnfgv phhikhhhohhvucetnhgurhgvihdfuceorgdrlhgvphhikhhhohhvsehpohhsthhgrhgvsh hprhhordhruheqnecuggftrfgrthhtvghrnhepgfevveeuheehffekueejheffudduheef feelhfeukefhtdeihfeuleefgefhudeknecuffhomhgrihhnpehmihgtrhhoshhofhhtrd gtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgvphhikhhhohhvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqddufeelge ehudejhedvqdeftddtiedtkeefvddqrgdrlhgvphhikhhhohhvpeepphhoshhtghhrvghs phhrohdrrhhusehfrghsthhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ie8b149e1:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3847936A0077; Wed, 20 Sep 2023 11:18:13 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-761-gece9e40c48-fm-20230913.001-gece9e40c MIME-Version: 1.0 Message-Id: In-Reply-To: References: <0d3f9971e82d2d969a5f@zeyos.com> <379b65d3-fde4-a9b4-1ea9-4eaa3936e729@postgrespro.ru> Date: Wed, 20 Sep 2023 22:17:46 +0700 From: "Lepikhov Andrei" To: "David Rowley" Cc: "Benjamin Coutu" , "PostgreSQL Hackers" , "Tom Lane" , "Robert Haas" , "Peter Geoghegan" Subject: Re: disfavoring unparameterized nested loops Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Sep 20, 2023, at 4:49 PM, David Rowley wrote: > On Wed, 20 Sept 2023 at 19:56, Andrey Lepikhov > wrote: >> What could you say about a different way: hybrid join? In MS SQL Server, >> they have such a feature [1], and, according to their description, it >> requires low overhead. They start from HashJoin and switch to NestLoop >> if the inner input contains too small tuples. It solves the issue, Isn't it? > > A complexity which you may not be considering here is that Nested Loop > joins always preserve the tuple order from the outer side of the join, > whereas hash joins will not do this when multi-batching. My idea here is the same as MS SQL guys did: prefetch from the HashJoin inner some predefined number of tuples and, if the planner has made a mistake and overestimated it, move hash join inner to NestLoop as an outer. The opposite strategy, "underestimation" - starting with NestLoop and switching to HashJoin looks more difficult, but the main question is: is it worthwhile to research? > I've no idea how the SQL Server engineers solved that. >> [1] >> https://techcommunity.microsoft.com/t5/sql-server-blog/introducing-batch-mode-adaptive-joins/ba-p/385411 -- Regards, Andrei Lepikhov