Skip to content

Lazily load spooled result set segments#597

Merged
wendigo merged 1 commit into
masterfrom
user/serafin/oom-lazy
Apr 13, 2026
Merged

Lazily load spooled result set segments#597
wendigo merged 1 commit into
masterfrom
user/serafin/oom-lazy

Conversation

@wendigo
Copy link
Copy Markdown
Contributor

@wendigo wendigo commented Apr 7, 2026

When using the spooling protocol, TrinoQuery.fetch() materializes all segments into a single list, causing out-of-memory errors on large result sets. Return SegmentIterator directly so rows are decoded on demand, keeping memory usage constant regardless of result set size.

Supersedes #590

Description

Non-technical explanation

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot Bot added the cla-signed label Apr 7, 2026
@wendigo wendigo force-pushed the user/serafin/oom-lazy branch from a806f32 to a913889 Compare April 7, 2026 11:08
@wendigo wendigo requested review from ebyhr and hashhar April 7, 2026 11:09
@wendigo wendigo force-pushed the user/serafin/oom-lazy branch 2 times, most recently from c94a245 to ee3d343 Compare April 7, 2026 11:16
Comment thread trino/client.py
# because we cannot cheaply check iterator length.
while not self.finished and not self.cancelled and self._result.rows == []:
new_rows = self.fetch()
if isinstance(new_rows, list):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we also need this check in columns?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why? I don't think we do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread tests/development_server.py
Comment thread trino/client.py
Comment thread trino/client.py
Copy link
Copy Markdown
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

LGTM % comment

When using the spooling protocol, TrinoQuery.fetch() materializes all
segments into a single list, causing out-of-memory errors on large
result sets. Return SegmentIterator directly so rows are decoded on
demand, keeping memory usage constant regardless of result set size.
@wendigo wendigo force-pushed the user/serafin/oom-lazy branch from ee3d343 to 0aa81e7 Compare April 13, 2026 11:14
@wendigo wendigo merged commit a2a1001 into master Apr 13, 2026
12 checks passed
@hashhar hashhar deleted the user/serafin/oom-lazy branch April 14, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants