Skip to content

Robust predicate transfer - #2430

Draft
leborchuk wants to merge 15 commits into
apache:mainfrom
leborchuk:rpt
Draft

leborchuk wants to merge 15 commits into
apache:mainfrom
leborchuk:rpt

Conversation

@leborchuk

Copy link
Copy Markdown
Contributor

That the last part for working with bloom filters. It's based on #2359 and #1942. Discussion - #1963.

Original article - https://vldb.org/pvldb/vol19/p1278-qiao.pdf. DuckDB implementation - https://github.com/embryo-labs/dynamic-predicate-transfer

Work is experimental. The only known to me implementation is DuckDB, but DuckDB is in-memory database, while Cloudberry run on multiple machines with network exchange layer to transfer data between them.

We have Anser that could transfer bloom filters from bottom to top and filter out rows using bloom filters. The main idea is to add special forward phase to transfer rows from top to bottom to filter out rows even further.

Main goal - do not produce huge intermediate result and so save compute/disk resources for query processing.

The full description is in README

What we do in one sentence - create bloom filters for each tables and transfer it to the each table where it could be applied. Stack multiple bloom filters.

Good working example with bridge query gives us such numbers:

Optimizer RPT off Forward only Backward only Full RPT
PostgreSQL 783.442 ms 694.808 ms 786.770 ms 471.149 ms
GPORCA 2,604.943 ms 876.686 ms 2,044.376 ms 816.806 ms

TPC-DS 1TB:

gongxun0928 and others added 3 commits November 25, 2026 17:15
This optimization pushes down Bloom Filter conditions for runtime filters
to the Pax Table AM layer.

By applying the filter earlier than the SeqNext() function, it eliminates
the overhead of converting data from columnar format to TableTupleSlot,
resulting in faster query execution

(cherry picked from commit e0abc24)
after calculating the null_counts array in advance, there is no need to call
GetColumnDatum to continue updating null_counts. We can directly read the datum.

(cherry picked from commit 6bc5d05)
Runtime filter pushdown hashes a key as the bytes of its Datum and
compares the min/max range as int64.  Only the low bytes of a narrow
Datum carry the value: heap tuples sign-extend an int2 or int4, AOCO
zero-extends it.  A negative key could therefore hash differently on
the build and the probe side and be dropped by the Bloom filter, and a
zero-extended build key became a large positive number in the min/max
range pushed into the table AM, so PAX could skip groups holding rows
that join.

Normalize narrow keys to one canonical form on both sides: the value
sign-extended to int64.  The same value then hashes the same whatever
produced it, equal integers of different widths hash the same, which
matters because int4 = int8 is accepted, and the range is taken from
the canonical value.

gp_enable_runtime_filter's RuntimeFilter node has the same problem: it
puts raw integer Datums from the Hash node into its Bloom filter and
probes it with the outer side's.  It now records each key's width and
normalizes both sides the same way.  So does PAX's row filter, which
probes the Bloom filters it was handed with the values it reads.

test_bloomfilter checks the canonical form.  PAX's gp_runtime_filter
test joins negative int4 and int8 keys from an AOCO build side,
co-located with the PAX probe so the Hash node sees AOCO's Datums, and
compares the result multiset with pushdown on and off, then checks the
RuntimeFilter node on the same join.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:45
@leborchuk
leborchuk marked this pull request as draft November 25, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Predicate sampling can violate SQL short-circuiting and security ordering, allowing non-leakproof functions to access RLS-protected values and potentially expose them through notices or errors.

6 open issues
What changed in this PR

This PR adds experimental Robust Predicate Transfer over Anser to reduce intermediate join results in Cloudberry’s distributed execution engine.

Changes:

  • Adds forward reducer execution, backward filter placement, extension packaging, and CI integration.
  • Extends Bloom filtering with adaptive probing, smaller Anser filters, canonical key handling, and scan-level integration.
  • Adds regression coverage, fault tests, benchmark diagnostics, documentation, and attribution.
File Description
src/​test/​regress/​sql/​gp_runtime_filter.sql Tests nullable-side filter safety.
src/​test/​regress/​expected/​gp_runtime_filter.out Records expected outer-join results.
src/​test/​modules/​test_bloomfilter/​sql/​test_bloomfilter.sql Invokes probing and normalization tests.
src/​test/​modules/​test_bloomfilter/​expected/​test_bloomfilter.out Records Bloom test output.
src/​Makefile.global.in Exposes the RPT build option.
src/​include/​utils/​sync_guc_name.h Synchronizes the rejection threshold.
src/​include/​utils/​guc.h Declares the rejection threshold.
src/​include/​nodes/​execnodes.h Tracks scan filters and key widths.
src/​include/​lib/​bloomfilter.h Exposes sizing, probing, and normalization APIs.
src/​include/​executor/​nodeSeqscan.h Updates the scan-probing interface.
src/​include/​executor/​nodeDynamicSeqscan.h Exposes dynamic-scan filter installation.
src/​backend/​utils/​misc/​guc_gp.c Defines adaptive probing configuration.
src/​backend/​lib/​bloomfilter.c Implements adaptive probing and configurable minimum sizes.
src/​backend/​executor/​nodeSeqscan.c Orders probes and refreshes filters on rescan.
src/​backend/​executor/​nodeRuntimeFilter.c Normalizes probe keys by width.
src/​backend/​executor/​nodeHashjoin.c Restricts unsafe filter descent through joins.
src/​backend/​executor/​nodeHash.c Normalizes build keys and installs late filters.
src/​backend/​executor/​nodeDynamicSeqscan.c Maps filters to partitions and accumulates statistics.
src/​backend/​commands/​explain_gp.c Limits worker-status markers to text output.
NOTICE Adds transfer-graph attribution.
licenses/​LICENSE-mit-duckdb-rpt.txt Includes the adapted code’s license.
LICENSE Lists licensed RPT source files.
gpcontrib/​robust_predicate_transfer/​test/​survey_test.py Tests benchmark survey accounting.
gpcontrib/​robust_predicate_transfer/​test/​forward_walk_test.cpp Tests plan walking and channel identity.
gpcontrib/​robust_predicate_transfer/​test/​diagnose_rpt_test.py Tests diagnostic instrumentation and watchdog behavior.
gpcontrib/​robust_predicate_transfer/​src/​rptinject.cpp Constructs the distributed reducer InitPlan.
gpcontrib/​robust_predicate_transfer/​src/​rptbackwardplan.cpp Selects and costs backward transfers.
gpcontrib/​robust_predicate_transfer/​src/​rptbackward.cpp Installs backward producers and consumers.
gpcontrib/​robust_predicate_transfer/​sql/​rpt_regions.sql Tests transfer-region boundaries.
gpcontrib/​robust_predicate_transfer/​sql/​rpt_key_types.sql Tests rejection of incompatible equality semantics.
gpcontrib/​robust_predicate_transfer/​sql/​rpt_graph.sql Tests transfer graphs and join safety.
gpcontrib/​robust_predicate_transfer/​sql/​rpt_forward_faults.sql Tests forward-transfer failures and cancellation.
gpcontrib/​robust_predicate_transfer/​scripts/​README.md Documents diagnostic and benchmark tools.
gpcontrib/​robust_predicate_transfer/​scripts/​diagnose_forward.py Provides a diagnostic compatibility entry point.
gpcontrib/​robust_predicate_transfer/​scripts/​compare_tpcds_results.py Compares exact results across filter modes.
gpcontrib/​robust_predicate_transfer/​scripts/​collect_bridge_example.sql Collects bridge-query plans and timings.
gpcontrib/​robust_predicate_transfer/​robust_predicate_transfer.control Defines extension metadata.
gpcontrib/​robust_predicate_transfer/​robust_predicate_transfer--1.0.sql Registers the restricted diagnostic function.
gpcontrib/​robust_predicate_transfer/​Makefile Builds, installs, and tests RPT.
gpcontrib/​robust_predicate_transfer/​include/​rptqual.h Defines safe reducer qualification functions.
gpcontrib/​robust_predicate_transfer/​include/​rptlocal.h Declares local filter handoff APIs.
gpcontrib/​robust_predicate_transfer/​include/​rptinject.h Shares scan-stack injection state.
gpcontrib/​robust_predicate_transfer/​include/​rptchannel.h Assigns forward and backward channel identities.
gpcontrib/​robust_predicate_transfer/​expected/​rpt_regions.out Records region-boundary expectations.
gpcontrib/​robust_predicate_transfer/​expected/​rpt_key_types.out Records custom-equality expectations.
gpcontrib/​robust_predicate_transfer/​expected/​rpt_forward_faults.out Records fault-recovery expectations.
gpcontrib/​robust_predicate_transfer/​.gitignore Excludes test binaries and local notes.
gpcontrib/​Makefile Includes RPT in optional builds.
gpcontrib/​anser/​test/​Makefile Adds real Bloom sizing tests.
gpcontrib/​anser/​test/​ansersize_test.c Tests sizing, serialization, and saturation.
gpcontrib/​anser/​test/​anserplanwalk_test.c Tests in-place filter target discovery.
gpcontrib/​anser/​test/​ansernormalize_test.c Tests adaptive probing and storage eligibility.
gpcontrib/​anser/​test/​anserfold_test.c Adds constructor stubs for fold tests.
gpcontrib/​anser/​test/​.gitignore Excludes the sizing-test binary.
gpcontrib/​anser/​src/​anserplanexec.c Adds adaptive probes and qualification fallback.
gpcontrib/​anser/​src/​anserinit.c Registers in-place execution hooks and settings.
gpcontrib/​anser/​src/​anserfilter.c Uses the smaller Anser bitset minimum.
gpcontrib/​anser/​sql/​anser_test.sql Updates sizing boundary cases.
gpcontrib/​anser/​sql/​anser_runtime_filter.sql Isolates exchange tests and adjusts pruning checks.
gpcontrib/​anser/​sql/​anser_multijoin.sql Disables in-place filtering for exchange tests.
gpcontrib/​anser/​sql/​anser_faults.sql Keeps fault tests on exchanged filters.
gpcontrib/​anser/​README.md Documents adaptive and in-place filtering.
gpcontrib/​anser/​Makefile Builds and tests in-place filtering.
gpcontrib/​anser/​include/​anserplanutils.h Tightens scan-variable validation.
gpcontrib/​anser/​include/​anserplan.h Exposes filter integration APIs.
gpcontrib/​anser/​include/​anserfilter.h Defines the 8 KiB bitset minimum.
gpcontrib/​anser/​include/​anserbloom.h Adds normalized adaptive probing.
gpcontrib/​anser/​include/​anser.h Exposes the in-place filter setting.
gpcontrib/​anser/​expected/​anser_test.out Updates expected filter sizes.
gpcontrib/​anser/​expected/​anser_runtime_filter.out Updates exchange plans and pruning expectations.
gpcontrib/​anser/​expected/​anser_multijoin.out Reflects exchange-only test setup.
gpcontrib/​anser/​expected/​anser_faults.out Reflects exchange-only fault setup.
gpcontrib/​anser/​anser_test/​anser_test.c Adjusts helpers for smaller filters.
contrib/​pax_storage/​src/​cpp/​storage/​orc/​orc_group.cc Handles nulls before reading column values.
contrib/​pax_storage/​src/​cpp/​storage/​micro_partition_row_filter_reader.h Declares unified filter evaluation helpers.
contrib/​pax_storage/​src/​cpp/​storage/​micro_partition_row_filter_reader.cc Evaluates Bloom and SQL filters during reads.
contrib/​pax_storage/​src/​cpp/​storage/​filter/​pax_sparse_pg_path.cc Clarifies sparse-filter handling in comments.
contrib/​pax_storage/​src/​cpp/​storage/​filter/​pax_row_filter.h Adds filter sampling and ordering state.
contrib/​pax_storage/​src/​cpp/​storage/​filter/​pax_row_filter.cc Builds and orders runtime row filters.
contrib/​pax_storage/​src/​cpp/​storage/​filter/​pax_filter.h Extends row-filter initialization parameters.
contrib/​pax_storage/​src/​cpp/​storage/​filter/​pax_filter.cc Passes runtime keys into row filtering.
contrib/​pax_storage/​src/​cpp/​storage/​filter/​pax_filter_test.cc Tests filter ordering and rejection accounting.
contrib/​pax_storage/​src/​cpp/​comm/​cbdb_api.h Imports the core Bloom API.
contrib/​pax_storage/​src/​cpp/​access/​pax_scanner.cc Supplies scan keys to PAX row filters.
configure.ac Adds RPT configuration and dependency checks.
configure Includes generated RPT configuration support.
.github/​workflows/​build-cloudberry.yml Adds the RPT integration-test job.

Review effort: Balanced

Comment thread gpcontrib/anser/src/anserplanexec.c Resolved
Comment thread src/backend/executor/nodeHash.c Resolved
leborchuk and others added 12 commits November 25, 2026 18:34
A table AM that takes runtime filter keys keeps copies of them: PAX
turns the min/max range keys into its sparse filter and the Bloom keys
into its row filter, and then turns executor-side checking off.  When
the hash join above is rescanned and rebuilds its hash table,
ResetRuntimeFilter drops the old filters and builds new ones, but
table_rescan() hands the AM no new keys and PAX's rescan ignores them.
The scan then kept filtering with the previous build's keys, losing
rows that join with the new one.

ExecReScanSeqScan() now ends a scan that handed runtime filters to the
table AM, turns executor-side checking back on, and lets the next
SeqNext() begin a new scan with the current filters.  Scans that did
not hand filters to the AM rescan as before.

Filters that arrive after the scan has started, because the join
fetched an outer tuple before building its hash table, cannot reach
the AM any more.  Where the AM took the earlier filters and turned
executor-side checking off, PushdownRuntimeFilter() now leaves those
with the AM and checks only the new ones at the executor.

PAX's gp_runtime_filter test runs a LATERAL nested loop whose hash
table is rebuilt from a different set of keys on every iteration,
checks that the plan has that shape, and compares the result multiset
with pushdown on and off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FindTargetNodes() walks down a hash join's outer side through other
hash joins to find the scan to filter, without looking at their join
types.  Below the outer side of a right or full join, a row the filter
drops does not vanish: its partner comes out NULL-extended instead.  A
NULL-tolerant condition above then matches it.  ORCA plans IS NOT
DISTINCT FROM with a plain = in the hash clauses and the null test in
hashqualclauses, so such a join is eligible for a runtime filter, and
the query returned NULL-extended rows that should not exist.

Only descend through joins whose output carries their outer rows'
values unchanged: inner, left, semi and anti joins.

gp_runtime_filter covers the IS NOT DISTINCT FROM case with ORCA.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sample non-null runtime Bloom probes and stop probing filters with
low rejection rates. Rank sampled scan keys by their rejection rate
and reuse PAX row-filter ordering and short-circuiting. Cover the
cutoff and ordering in the backend and PAX tests.
A runtime Bloom filter that rejected too few keys in its first sample
was disabled for good.  When a table is loaded in key order, the first
rows can all pass a filter that rejects most of the rest, and the
filter is then lost for the whole scan.

bloom_runtime_probe() now counts probes in windows of 1024.  A window
that rejects fewer than gp_runtime_filter_min_reject_pct percent (new
developer GUC, default 5, 0 keeps filters on) disables the filter;
bloom_runtime_probe_skip() lets rows pass and starts a new window after
1024 skipped rows, doubling the gap while the filter stays ineffective,
up to 64M rows.  A window that rejects enough turns the filter back on
and resets the gap.  An enabled filter is re-evaluated every window as
well.  Ranking uses the last full window.  A useless filter now costs a
few thousand probes per hundred million rows.

test_bloomfilter covers the re-check schedule and the 0% threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A hash join whose probe scan runs in the join's own slice needs no
exchange: each segment's Hash node already receives every key its
scanned rows can match.  The coordinator skips the exchange for such
joins, and every segment re-runs the same eligibility check
(AnserInplaceEligible) on the plan at executor start, wraps the Hash
node's child to collect normalized keys into a Bloom filter, and
installs an Anser scan qual on the probe SeqScan.  The filter holds
only the keys left after the build side's joins and predicates, the
scan never waits for it, and probes go through the adaptive
bloom_runtime_probe_skip.

No core plan node, flag or EXPLAIN change is needed, and nothing
depends on gp_enable_runtime_filter_pushdown: every key type Anser
accepts works.  anser.runtime_filter and anser.runtime_filter_inplace
are synced to segments so both sides decide alike.  Full-width keys
of exchanged filters fall back to the Anser qual when core's scan-key
path is off.  Consumers probe adaptively too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A SeqScan handed its runtime filters to the table AM, and checked them
itself, only while gp_enable_runtime_filter_pushdown was on.  That GUC
decides whether hash joins create runtime filters; the scan does not
need to ask it again.  Filters only reach a scan because something put
them there, and an extension that does so -- Anser hands its exchanged
Bloom filters to the probe scan -- had them ignored with the GUC off.

The scan now applies whatever filters it has, outside MPP parallel
mode as before, passing them to an AM that supports runtime filters,
such as PAX, when the scan starts.  With the GUC off and no extension
adding filters, the list is empty and nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An exchanged filter reached a PAX probe only as an Anser-owned scan
qual, which PAX drops when its row filter rebuilds the scan's qual
from the plan, so on PAX the consumer had to probe every row itself.
Hand the filter to the scan as an SK_BLOOM_FILTER key instead, for
keys of every width: PAX then checks it in its row filter before it
loads the other columns, and other scans check it in SeqNext.  The
scan takes keys without gp_enable_runtime_filter_pushdown now.

Core and PAX probe such a key in core's canonical form, sign-extended
to 64 bits, so Anser now hashes narrow keys that way on both sides
too (it used to zero-extend them); the two forms are equally
storage-independent.  The Anser qual remains for scans that cannot
take a key -- MPP parallel mode, or an AM that took earlier keys and
has started -- and the consumer still probes by itself on AOCO and
on AMs that take runtime filters.

anser_runtime_filter checks that negative keys are pruned at the scan
on heap and AOCO probes with core pushdown on and off, and, where PAX
is installed, that a PAX probe takes the filter with and without its
row filter and returns the same rows, exchanged or in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mix matching and unmatched keys and disable adaptive backoff while
asserting that both PAX paths reject rows. Adaptive probing is covered
separately by the weak-filter fixture.
gpexplain_formatSlicesOutput() remembers the output position of a
slice's text line and later overwrites that byte with 'X' or '_' to
mark failed workers.  In JSON, YAML and XML output no such line is
written, so the position is the string's terminating NUL, and the
overwrite corrupted the output whenever a slice reported a worker
summary.  Write the flag only for text output, and take the error
count from the same dispatch summary as the message beside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bloom_create() never makes a bitset smaller than 1 MiB.  That suits
the backend's own one-off filters, but an extension that ships
filters between processes, like Anser, pays for a 1 MiB payload per
filter even when the build side has a few hundred keys.

Add bloom_create_with_minimum() and
bloom_create_from_bitset_with_minimum(), which take the floor as a
power of two of at most 512 MiB.  bloom_create() and
bloom_create_from_bitset() call them with 1 MiB, so existing callers
are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prepare Anser for an extension that plans its own runtime filter
exchanges, robust_predicate_transfer, and shrink small filters.

Filters now start at an 8 KiB bitset instead of core's 1 MiB floor,
through bloom_create_with_minimum(), so a few hundred build keys no
longer cost a 1 MiB payload per producer.  ansersize_test checks the
sizing against the real core constructor.

New entry points:

- AnserApplyRuntimeFilterFallback() runs the injection pass without
  the anser.runtime_filter gate, for statements the extension leaves
  to Anser.
- AnserApplyInplaceRuntimeFilters() and AnserVisitInplaceCandidates()
  report the joins that would get in-place filters, skipping a probe
  key that already has an Anser consumer.  The plan is not changed.
- AnserSetInplaceRequest() lets the extension tell segments to build
  in-place filters when anser.runtime_filter is off.
- AnserRegisterFilterScanMethods() lets the extension's identity
  filter nodes be looked through when an in-place filter's scan is
  sought, as Anser's own are.
- AnserBloomConsumerKey() returns a consumer's key position.

Exchanged filters are now sized from all producers' rows.  A scan's
plan_rows is what one segment reads, but the coordinator folds every
producer's part into one filter, so a filter sized from plan_rows
alone filled up and was given up on large clusters.  Replicated
tables are not multiplied.

Where coordinator and segments could disagree about a join, it gets
two filters or none, which never changes the answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add gpcontrib/robust_predicate_transfer (RPT+), which plans runtime
Bloom filter transfers over Anser for whole join graphs rather than
one hash join at a time.  The transfer plan algorithm is ported from
the RPT+ artifact (MIT, Stichting DuckDB Foundation; see
licenses/LICENSE-mit-duckdb-rpt.txt).

After planning, on the coordinator, the extension:

- finds transfer regions, the connected join graphs over base scans,
  and groups join keys into equivalence classes;
- builds the forward stage as reducer InitPlans that chain filters
  through the graph, sized and admitted by a cost model;
- injects backward-stage consumers only where a plan-order check
  proves they cannot deadlock waiting for a producer;
- uses in-process local filters for hops within one process, Anser
  exchanges across Motions, and Anser in-place filters for the
  remaining same-slice joins;
- falls back to Anser's own pass where it places nothing.

rpt.enable turns it on; rpt.forward and rpt.backward select the
stages.  rpt_transfer_plan(text) reports the transfer decisions
without running the query.  rpt.enable and rpt.backward are synced
to segments, which build the in-place filters.

Build with --with-rpt.  Unit tests run with make unitcheck; the
regression suite needs Anser preloaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants