Skip to content

Conversation

@burmecia
Copy link
Member

What kind of change does this PR introduce?

This PR is to refactor ClickHouse FDW data scan to use async streaming.

What is the current behavior?

Currently, the ClickHouse FDW uses fetch_all() to read the whole result data set from ClickHouse to local memory, and then convert them to Postgres rows. This approach doesn't limit memory usage and it will exhaust local memory if the result data set is large.

What is the new behavior?

Refactored the data scan to use async worker based streaming. The result data set is asynchronously read from ClickHouse by a dedicate thread, and then converted and transmit to Postgres through a buffered sized-limited (1024 by default) channel. By using this streaming approach, the local memory usage will be restricted by the size of channel, thus memory exhaustion will be prevented.

Additional context

N/A

@burmecia burmecia added the clickhouse Clickhouse related issues label Oct 28, 2025
@burmecia burmecia requested a review from imor October 28, 2025 06:48
@burmecia burmecia merged commit 36ce529 into main Oct 28, 2025
6 checks passed
@burmecia burmecia deleted the bo/fix/clickhouse-streaming branch October 28, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clickhouse Clickhouse related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants