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 1wfdML-005YEM-29 for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jul 2026 12:51:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfdMJ-007Tqo-0g for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jul 2026 12:51:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfdMI-007Tqf-2h for pgsql-hackers@lists.postgresql.org; Fri, 03 Jul 2026 12:51:06 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wfdMF-00000001SOi-0hwa for pgsql-hackers@postgresql.org; Fri, 03 Jul 2026 12:51:05 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso583721a91.1 for ; Fri, 03 Jul 2026 05:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783083060; x=1783687860; darn=postgresql.org; h=in-reply-to:references:to:from:subject:message-id:date:content-type :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Bj8T2rEO6BByhFWFrMwxSRV8WYQ7h8LSgu2GGNoUe+o=; b=PQbq/4zx+bTT7/OBLGtHxMpplZ4AchFKzbVE+b2cmVbBq64nab40oUGgjLjx++nYLO pxUxC1b0/u+FpQ/P/i4uCtjW4rMeavu6dieTpIL/veep6Af5E83TIIFLfbbQpq7Xrlh/ 7vPrOEFAv9X9ggc1Hjs8o3YWslE5Z5VsGun7gmj1nmBfzjfcIfBPvUG1LAN02Dmp0oWF sYWTvw31I5engRRLK9u/fxXG86k6X8upu01Tc+JVEcoV/i6nLgIHZjcUviAsvl12DZpH mqdWiFu3k+xN5WPSLnK16eLyZ446ttxoiF1il2oaJSzebfj8ROHY9BPgLcEW4SkyL4Fd cMpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783083060; x=1783687860; h=in-reply-to:references:to:from:subject:message-id:date:content-type :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to:content-type; bh=Bj8T2rEO6BByhFWFrMwxSRV8WYQ7h8LSgu2GGNoUe+o=; b=SPaPnOUKuj2o5axWk5s5m0SH8WauXcVdKkfEkoGkkCaelQa6+w/QTdBqRAwKJDhqmF DCXZx3Mgt0QF8SRB2C6FHoPuEZ4AazIAXigcgM6Sd8CyBIj5vWk8LUGOrhWBVzT3QNJ9 QgEKcJoAAfBxchhy/ewkYx4YFO7hvWGBwAjwM+lTKl00bKlAdED775/F+D5K87BGuYKS vuPV+k0Dg+XJHFSCikqt9GsuPmq/mbTGQJfYwYGqg97Yy1QISqgBQXHwX/e+bal+R/gl +OwrKmldJumOLgJNcSRmEk+dBDb3NYilsjnxmGogkgUkbjjyKboU9Y0ug2O3MA8LcQRR kf5Q== X-Forwarded-Encrypted: i=1; AHgh+RriAXygqjqQXJXDdUejPtMHb5ItfGkK24+Sk1PDGkI+n9GMHIYjZ9qREuW+LQKlpjn52eMXITPp579mk5/v@postgresql.org X-Gm-Message-State: AOJu0Yzb9NHMFJdIlN4OGdAX2O7FIgKqEqU/mwJB/xibTq7t8jrerzyl V+s9rLUD8THM8+SJaAhhao4KJtMuOV5+NswnTuHb3+l/5U1ioi34m7FX X-Gm-Gg: AfdE7clfF6PXUP+n8syPuYPo98WzX33hz/g/AK+6BLX48T8OYXC/wcme9Jh/4ffcZH4 m33Nzm1luGiLMvytRFAGX7zssUtrDurss2z6xD+5JssoCvBU0bDVELMXBwj8d04WR2eMnwb46/R j6V8CUhBNPYtJySlXT1fDKbcajzuhScQak7NTOeX46//BELLvxm6fRCcBRjg0abOJIRdRf0BnEk MJ37f+J1cvxh9ChHGTj9QgwMy259522kuXXBJyfOePUcc/qrodcSGXDmoJrmRgBoJyhSo2LVLL9 Ld3fz33bEw57Lg2W5mdgqHrxxX9EIMwbUjQLKr7r/sHlF2iUT6pZChmB8KPBmxWqkGb1CbM4Fsl /kyBR+jgaotzU5A8TgFmBoT83qKnwdQBbc5QGNeyoCxyIJlCgvEjioPe9U7mnrglcUiLLOoBQdT OINu9fdTWfODhdXB5LaQBmfdTt3k02ZBmjf48= X-Received: by 2002:a17:90b:350a:b0:380:f389:4477 with SMTP id 98e67ed59e1d1-380f3894634mr7078663a91.6.1783083060247; Fri, 03 Jul 2026 05:51:00 -0700 (PDT) Received: from localhost ([2804:14d:32a7:4273:61fb:58e7:12b4:7a37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30f0b7b9a1bsm20886960eec.3.2026.07.03.05.50.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jul 2026 05:50:59 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 03 Jul 2026 09:50:57 -0300 Message-Id: Subject: Re: hashjoins vs. Bloom filters (yet again) From: "Matheus Alcantara" To: "Tomas Vondra" , "Andrew Dunstan" , "PostgreSQL Hackers" X-Mailer: aerc 0.21.0 References: <5cd8c20c-14b5-4b0d-bedc-69bf714e87eb@vondra.me> <12d255f1-533f-414f-8caa-9867759cfce9@dunslane.net> <2f9a99ef-4857-4d4c-8544-30078a38dfa1@vondra.me> In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri Jul 3, 2026 at 7:10 AM -03, Tomas Vondra wrote: >> I'm wondering if the adaptive probing can mess the execution of the >> choose plan. Let's say that a plan was chosen with bloom filters to >> pushdown because it would reduce e.g 50% of the rows, what if at >> runtime the bloom filter is proved to not be effective and it get >> disabled making the scan node to produce 100% of the rows to the node >> above that is not expecting? Do we end up with the same issue "expected >> x actual rows"? >>=20 >> I think that if we keep using the unnefective bloom filter the scan node >> will still produce more rows than expected, but perhaps this is easier >> to understand? >>=20 > > Yes. If we pick a filter expecting it to eliminate 99% of tuples, but > then find it does not eliminate any tuples, that'll affect the counts in > explain. But that's simply how misestimates work, it's not specific to > filter pushdown. It may happen for WHERE clauses etc. > > The estimate would hit us at some point anyway - it's the selectivity of > the join, so even without the pushdown the cardinality would be off > above the join. > > Also, what else could we do? I don't think we can do planning assuming > the estimates are off - we have to assume the estimates are OK. We might > consider how "safe" a given estimate is, and then maybe not push down > filters for "risky" ones, but we don't have any such capability. > Yeah, I was just worried about this may add more confusing, but after more thinking it does not seems to be the case. I was imagining a scenario where the expected x actual rows is not very accurate and it could be hard to know if it was because outdated stats or because the adaptive probing decided to turn off the filter pushdown but I think that in the end it's all the same problem: The adaptive probing may turn off the filter because it's not very effective but this can happen because of outdated stats that make the planner think that the push down filters would help but it's not. > >>> I haven't incorporated the two patches posted by Andrew: >>> >>> 1) making it work with CustomScans >>> >>> 2) supporting per-key filters >>> >>> 3) allow eager creation of filters (disable delayed Hash build) >>> >>> I agree those seem like a worthwhile improvements, and the patches >>> seemed to be OK too, but I was focusing on reworking the planning. Base= d >>> on some off-list discussion, Andrew (or one of his colleagues) should b= e >>> able to adjust those for this v3 patch. >>> >>=20 >> I'm attaching a new v4 patchset incorporating Andrew patches with test >> cases. 0001 and 0002 are your v3 untouched, 0003 is some tests added to >> exercice the CustomScan path and 0004 is the Andrew changes with a few >> changes required from v3 version: >>=20 >> Unlike the v1 PoC that pushed filters down in create_hashjoin_plan >> (where it could simply walk the finished plan tree and accept any scan >> node), the filters are now decided during bottom-up path construction, >> so a scan only receives a filter if a filter-bearing path was generated >> for its base relation. So the main change is teaching path generation >> about the custom scan. >>=20 > > Thanks, I'll take a look early next week. My plan is to create a branch > carrying all the pieces, and then gradually refine that. > Good, thanks. > One thing I'm a bit concerned about is the CustomScan support. We don't > have a single module in the tree, so how would we test the changes? I > think it might be necessary to introduce a minimal CustomScan module, so > that we can test the new pieces. > On 0003 I've created a new test extension that register a CustomScan method. It also expose some sql functions to assert some behaviours of filter pushdown. I think that it's still on early stage but it may help. Let me know what do you think. -- Matheus Alcantara EDB: https://www.enterprisedb.com