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 1sfxzN-00DnHL-Jy for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Aug 2024 08:43: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 1sfxzL-00HRmB-Dg for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Aug 2024 08:43:44 +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 1sfxzL-00HRlq-03 for pgsql-hackers@lists.postgresql.org; Mon, 19 Aug 2024 08:43:43 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sfxzI-000NMB-LS for pgsql-hackers@lists.postgresql.org; Mon, 19 Aug 2024 08:43:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1724057017; bh=A6za96VZP3B/WHxZdVYDmxs+SJD38y+gZwW2lKRfKU8=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=n6S+fH1uV4+l7rNM+AzgpSPUDQPdeEx1V9Zbpc4QnHxkES+C7C/nPurf4WR3orBX5 8DsfufNcgObU27DdQdsR8IcKqCRRU2G7fCwiGvtfFo+RZfzsfTZFr4Fc16AJz2mMPq SxwD7btJcr7aSjq5uxd3K0AaGTpGo+mJFJ6If/htMYJuQuNYtMbOyY6AsudeZ+7btm LJMrme6bU+s75/AfvPHWeitcZlo1JhRXEsQGECqfgWL5NHcGpLbBeSlbWNuoPrcb2R QKDj2mUXolmLjKjRvKJWOWyIcl5dSfqnVblc2QA4h+JbgpCezLCsjVv7zvwPApiuJ/ 3A4ZpBpjMEWww== Received: from [172.30.33.218] (unknown [172.30.33.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 0CD07602A9; Mon, 19 Aug 2024 11:43:35 +0300 (MSK) Message-ID: <944ed18c-3e7d-42ef-816e-0afc41610e93@postgrespro.ru> Date: Mon, 19 Aug 2024 10:43:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Asymmetric partition-wise JOIN To: Alexander Korotkov Cc: Thomas Munro , KaiGai Kohei , sulamul@gmail.com, Alexander Pyhalov , Jaime Casanova , Aleksander Alekseev , pgsql-hackers@lists.postgresql.org, "a.rybakina" References: <163118104689.1167.8241611097516113795.pgcf@coridan.postgresql.org> <20210909153833.GA6514@ahch-to> <2c9caede-55c0-2042-e421-dd0021f28837@postgrespro.ru> <792d60f4-37bc-e6ad-68ca-c2af5cbb2d9b@postgrespro.ru> <88bc3c051d285653215393a56bdf3056@postgrespro.ru> <5c0e38e3-7ab5-4b10-a1bb-70ca69771ff0@postgrespro.ru> Content-Language: en-US From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2024/08/19 06:29:00 #26354273 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/8/2024 20:56, Alexander Korotkov wrote: > On Tue, Apr 2, 2024 at 6:07 AM Andrei Lepikhov > wrote: > Actually, the idea I tried to express is the combination of #1 and #2: > to build individual plan for every partition, but consider the 'Common > Resources'. Let me explain this a bit more. Thanks for keeping your eye on it! > My idea is to introduce a new property for paths selection. > 3) Usage of common resources. The common resource can be: hash > representation of relation, memoize over relation scan, etc. We can > exclude the cost of common resource generation from the path cost, but > keep the reference for the common resource with its generation cost. > If one path uses more common resources than another path, it could > cost-dominate another one only if its cheaper together with its extra > common resources cost. If one path uses less or equal common > resources than another, it could normally cost-dominate another one. The most challenging part for me is the cost calculation, which is bonded with estimations of other paths. To correctly estimate the effect, we need to remember at least the whole number of paths sharing resources. Also, I wonder if it can cause some corner cases where prediction error on a shared resource will cause an even worse situation upstream. I think we could push off here from an example and a counter-example, but I still can't find them. > However, I understand this is huge amount of work given we have to > introduce new basic optimizer concepts. I get that the main > application of this patch is sharding. If we have global tables > residing each shard, we can push down any joins with them. Given this > patch gives some optimization for non-sharded case, I think we > *probably* can accept its concept even that it this optimization is > obviously not perfect. Yes, right now sharding is the most profitable case. We can push down parts of the plan which references only some common resources: FunctionScan, ValueScan, tables which can be proved are existed everywhere and provide the same output. But for now it is too far from the core code, IMO. - So, I search for cases that can be helpful for a single instance. -- regards, Andrei Lepikhov Postgres Professional