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.96) (envelope-from ) id 1wUIZV-0014HQ-1h for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jun 2026 06:25:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUIZU-00D6HY-1R for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jun 2026 06:25:52 +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.96) (envelope-from ) id 1wUIZU-00D6HQ-0X for pgsql-hackers@lists.postgresql.org; Tue, 02 Jun 2026 06:25:52 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUIZS-00000000hXy-1tuP for pgsql-hackers@postgresql.org; Tue, 02 Jun 2026 06:25:51 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-490a76757e5so15804135e9.2 for ; Mon, 01 Jun 2026 23:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780381548; x=1780986348; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=al+4CRLDwxeaM17whmaYjj7zTiLoATHp+NCakZ/pUVQ=; b=DnDghZ1y0/HkhJWk5MzCXYxuLOYFH3gtTmaVx0PNXnF20rUWSHyQ90SHvwYd1XUXgp YWu3MpgquknFVmfkAYAXOx3PaS+HgqS+VS2Qgs43I/qFBvk1xB60MIv+9KsEEOEuifGS gMs8BTGjxoLn+mao0Qho5U+8a3gbbpBxKusGnkyJmYJVPZ272MSZ7SxoDdZtGQn+74Q1 IMtTb0zI+WFWJIZOUDKnmBCAXwC4m3B7va6FaMynyYYHo2p5FyM54mkJV+2eXpMV72CW 38i1ewY72UlTnSF52qKq84sO/BtgsERKfxllr1xQN6ZmyxK+P2aBqhZupzA0UZQoffe5 QU4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381548; x=1780986348; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=al+4CRLDwxeaM17whmaYjj7zTiLoATHp+NCakZ/pUVQ=; b=DbRcJ5CBTNIMOq+h6h2C8ri0OMqu+RXZ8lLMlybtNWQaWB/UwbSM49yRVXajvgkcuJ vhjcZ8aKMRAVhI9S0KiLZ829kujn2nbEHbk60FPXz/4NHfBB+w8gAn7T4VohSwlvhPEq Y87UA70xfQgP8Y7EfL3p385BMc+IItD+7eVlm4JfmnuqjUbdC/VPlxy+DTkrPOQ9MOma QyZ4qsLNV9L1pHo9sOhanrz1WhIVh+3+7xRosICm9uSZVDs09XgyziKAEWqSds9Ul7v7 GkWwonp4gO3u0+7W6h1L3BQSFIiWBVZFvVpuvEKZVuCMOrqsY0ocSDxkneCBJtcfgc34 GfAg== X-Forwarded-Encrypted: i=1; AFNElJ/SrC81fKUt7iMfZlmwvVo1oU6Gc9Hop2Lrx6XcqhW8dX6wDpkv4ccZ1rLLgjne4S1Gw0skdteF48E/B2Xz@postgresql.org X-Gm-Message-State: AOJu0YyMj91wa5+Ba7B0QXHmjgBudM4Ody8SGTfK0IuS/rmxxEexeV+4 N42q8jX8YfgQ3lYbK7aCPLpv8EZxhczk9eHSTyLugfNbXAejBPGw2ht1BRSzsp6C X-Gm-Gg: Acq92OGWn796EbRf9icyPmtDCNlq0e1aMbS1Y7ApeFUl4cJS2jEnT0Hv8nFwJOh7Gqh DYAIaAUzmO9HHuDJ2uNg7IWT+h8rT/qFq8EtGsuVQXxpLrrcXXbkrcstsQPmtc+1hTWFo7dkFwP K+EYY258+9kw7W2MabdVBLQyQxqvQuUuzEmCKF4CwrzsLwc9qtuAgedfJYNai+EvSD+yNmK9DXU dh5bMbKSb2PrLgM2aV5nzn7t6YYXp5takquHIfp+CfoYj0MmKE+rOJk5WEMCmp3YV0xpDKbEgw4 P6ORatgVLzfNCB12yYf2tZ7z8vHAQvy1B4/iXjiyAGR+z2uY9gInb6OsLe3EjdQljw1JqEJhUAO fhnEh2dbreXQPsfs7wukOmE/d7r8f2L0WWvBAJmWaUZjSU7Icke81ixcudgRwUEFrl9Kr5ctksZ EKc93mHzMVSotIn1BFBYuCrXyj0xtNhjZGUhsE6ivJl+fIBcCd25/KKvev5Yg= X-Received: by 2002:a05:600c:6098:b0:490:b1b8:95f5 with SMTP id 5b1f17b1804b1-490b1b89725mr29199605e9.15.1780381547870; Mon, 01 Jun 2026 23:25:47 -0700 (PDT) Received: from [192.168.15.251] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490b367577asm161975e9.10.2026.06.01.23.25.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Jun 2026 23:25:47 -0700 (PDT) Message-ID: <494586a2-fd9b-44ad-9bb5-4b6cc18bdf53@gmail.com> Date: Tue, 2 Jun 2026 08:25:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: hashjoins vs. Bloom filters (yet again) To: Tomas Vondra , PostgreSQL Hackers References: <5cd8c20c-14b5-4b0d-bedc-69bf714e87eb@vondra.me> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <5cd8c20c-14b5-4b0d-bedc-69bf714e87eb@vondra.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 30/05/2026 02:55, Tomas Vondra wrote: > Earlier, I mentioned the push-down happens in create_hashjoin_plan(). > Which means it happens *after* planning and costing. There are reasons > for that, but it has some unfortunate & annoying consequences. > > Ideally, we'd know about the filters when constructing the scan nodes, > so we'd have a chance to estimate how many tuples will be eliminated by > probing the filters (which is about the same thing as estimating the > join sizes). But we can't do that, because our planner works bottom-up. > When constructing the scan nodes we know which tables we'll join with, > but we have no idea which of the join algorithms we'll pick. > > We'll consider all three join types, and the scan node has no say which > of those will win. But the Bloom filter push-down is specific to hash > joins. So what should the scan node do? Either it can assume it's under > hash join (and set rows/cost as if there's a Bloom filter), or it can > set costs in a join-agnostic way (like now). > > The only "correct" way I can think of dealing with this in the bottom-up > world is having two sets of paths - one set for a hash join, one set for > other joins. But that's not just for scans. We'd need that for all > paths, and for different combinations of joins. For the query with 3 > joins, we'd end up with 2^3 combinations. That seems not great. I overlooked this part of your first message, so let me add a quick comment. In principle, the optimiser is not restricted to bottom-up planning. For example, in extension modules, I sometimes use the create_upper_paths_hook to add a 'Top-Down' iteration after 'bottom-up' planning [1]. This helps improve complex query plans, such as adding a Memoize node at the head of a subplan when the number of distinct input parameter values is expected to be low. It can also use the startup_cost-optimal subpaths in MergeJoin if histogram comparisons indicate that only a small portion of the input will be scanned. There are other possible cases involving LIMIT and sort propagation as well. I'm not sure whether this approach makes sense for the specific technique you develop, since it's already quite complex. Also, additional planning iteration is a pure overhead in most of cases except complex analytical queries. However, it might provide an idea for future improvement. [1] https://github.com/danolivo/conf/blob/main/2025-MiddleOut/MiddleOut.pdf -- regards, Andrei Lepikhov, pgEdge