Skip to content

Add row streaming support#127

Merged
SeanTAllen merged 1 commit intomainfrom
row-streaming
Feb 15, 2026
Merged

Add row streaming support#127
SeanTAllen merged 1 commit intomainfrom
row-streaming

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

Implement windowed batch delivery using the extended query protocol's Execute(max_rows) + PortalSuspended mechanism. Unlike execute() which buffers all rows before delivery, streaming enables pull-based paged result consumption with bounded memory.

New public API:

  • StreamingResultReceiver interface (pg_stream_batch, pg_stream_complete, pg_stream_failed)
  • Session.stream(query, window_size, receiver) — starts streaming
  • Session.fetch_more() — requests next batch
  • Session.close_stream() — ends streaming early

Uses Flush (not Sync) to keep the portal alive between batches. Sync is sent only on completion, error, or early close. A _completing flag guards against fetch_more/close_stream sending messages after on_command_complete has already sent Sync — the receiver may call fetch_more() in response to the final pg_stream_batch before ReadyForQuery arrives.

Only PreparedQuery and NamedPreparedQuery are supported — streaming requires the extended query protocol.

Design: #72

@SeanTAllen SeanTAllen added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Feb 15, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 15, 2026
Streaming queries use the extended query protocol with Execute(max_rows)
to deliver results in windowed batches via PortalSuspended, rather than
buffering all rows in memory. The client controls flow through
fetch_more() and close_stream() on Session, receiving batches via
pg_stream_batch on StreamingResultReceiver.

Adds _StreamingQueryInFlight query sub-state with _completing and _error
guards to prevent duplicate Sync and post-completion Execute messages.
Dispatch for fetch_more/close_stream uses match on concrete type in
_SessionLoggedIn rather than the _QueryState interface.

Design: #125
@SeanTAllen SeanTAllen merged commit 412f1cc into main Feb 15, 2026
8 checks passed
@SeanTAllen SeanTAllen deleted the row-streaming branch February 15, 2026 19:10
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - added Automatically add "Added" CHANGELOG entry on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants