Re: hashjoins vs. Bloom filters (yet again)

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: hashjoins vs. Bloom filters (yet again)
Date: 2026-07-23 12:02:08
Message-ID: c7faaeaf-e7ad-4227-a2ae-bdf83e19ca3e@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/21/26 18:24, Tomas Vondra wrote:
> ...
>
> FWIW I'm running some tests on TPC-H, to see which queries would benefit
> from this, how much, if there are issues, etc. Should have some numbers
> later this week.
>
Here's some results for TPC-H scale 10 and 50 (so relatively small, but
manageable on my test systems). I used the same schema/indexes as usual.
There may be a better schema, but what matters is the impact of enabling
Bloom filters.

The PDF shows results for the 22 TPC-H queries, for combinations of a
couple parameters:

- scale: 10GB vs. 50GB
- cold vs. warmed-up
- buffered I/O vs. direct I/O
- 0 vs. 4 parallel workers

The last four columns compare the runs with filters enabled vs.
disabled. Green = good/faster.

Overall, the results are pretty good. There's 5-6 queries with ~25%
speedup, Q9 gets ~5x faster (10x with direct I/O). There's a bit of
difference depending on the scale, direct I/O, etc.

Of course, this mostly ignores the planning overhead. It's analytics
benchmark, with multi-second queries, and the queries are relatively
simple, so there's not that many possible filters.

But overall it seems like a good result for a WIP patch. There are no
visible regressions - it's all within noise, considering there was a
single run per query / parameters.

While working on this, I noticed a couple more issues in handling paths
with filters - matching then to joins. I noticed because it caused weird
plan changes in initial benchmark runs - the plan changed, but the new
plan did not have any Bloom filters. I'm attaching Q9 plan as an example
(notice the second plan has lower cost, but no filters).

The reason is we ended up with "unresolved" filters, which however do
affect the cardinality/cost. The result is still correct, but the plan
is inefficient (just like after misestimate).

Patches 0010-0012 should address those (but there may be more issues).

0010 - add_partial_path keeps the paths sorted by total path, so that
code can do linitial() to get cheapest total path, but this needs to be
without filter. 0002 broke that, so e.g. Gather might used paths with
filters. That'd trip an assert, but there may be other callers.

0011 - compute_join_expected_filters was not handling filters built on
joins correctly (per my earlier report)

0012 - adds some checks paths don't have bogus filters (that should have
been resolved or discarded earlier), and fixes another bug in
compute_join_expected_filters this found

Other that that, there are no differences compared to v6. There may be
more bugs in compute_join_expected_filters, I think it needs a bit of
cleanup / rework after allowing filters on joins.

These fixes might reduce the number of paths we keep propagating, and
thus reduce the planning time a little bit, but I guess it's not enough
to solve the path explosion problem.

regards

--
Tomas Vondra

Attachment Content-Type Size
q9.sql application/sql 2.2 KB
q9.log text/x-log 14.1 KB
v7-0001-PoC-hashjoin-bloom-filter-pushdown.patch text/x-patch 272.9 KB
v7-0005-Add-tests-for-CustomScan-filter-pushdown.patch text/x-patch 23.1 KB
v7-0004-Make-sure-Gather-nodes-don-t-have-filters.patch text/x-patch 1.8 KB
v7-0006-Allow-a-CustomScan-to-consume-a-pushed-down-hashj.patch text/x-patch 20.1 KB
v7-0007-Properly-plan-filters-built-on-joins.patch text/x-patch 47.5 KB
v7-0008-Add-GUCs-for-limiting-join-enumaration.patch text/x-patch 7.7 KB
v7-0009-Allow-filters-built-for-queries-with-LATERAL-join.patch text/x-patch 15.5 KB
v7-0011-Fix-filters-on-joins-in-compute_join_expected_fil.patch text/x-patch 2.2 KB
v7-0012-Add-assert-to-prevent-partial-filters.patch text/x-patch 3.2 KB
v7-0010-Fix-handling-of-filters-in-add_partial_path.patch text/x-patch 3.5 KB
v7-0003-Skip-paths-with-filters-in-get_cheapest_path_for_.patch text/x-patch 29.4 KB
v7-0002-Check-expected-filters-even-for-partial-paths.patch text/x-patch 9.2 KB
tpc-h-bloom-filters-ryzen.pdf application/pdf 67.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rafia Sabih 2026-07-23 13:19:01 Re: tablecmds: Deadlock caused by Attach Partition
Previous Message Nisha Moond 2026-07-23 11:56:43 Re: Support EXCEPT for TABLES IN SCHEMA publications