fix(clickhouse): implement re_scan for nested loop joins #546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
PostgreSQL uses Nested Loop joins when joining foreign tables. During a Nested Loop join, the inner (right) table is scanned multiple times - once for each row of the outer table. The FDW framework calls
re_scan()to restart the inner scan for each outer row.The ClickHouse FDW was using the default no-op
re_scan()implementation, which caused joins to return incomplete results because after the first scan:is_scan_completewas stilltruerow_receiverchannel was exhaustedThis fix implements
re_scan()to restart the async streaming by:Test plan
clickhouse_join_testthat verifies inner, left, and right joins return correct resultscargo pgrx test pg16)cargo clippypasses with no warningscargo fmtpassesThe test creates two foreign tables with values (1, 2, 3) each and verifies: