Skip to content

fix: skip redundant fetches for complete direct results - #539

Merged
vuanhphung merged 8 commits into
mainfrom
fix/cloudfetch-direct-results
Nov 14, 2026
Merged

vuanhphung merged 8 commits into
mainfrom
fix/cloudfetch-direct-results

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Skip the redundant Thrift FetchResults when direct results explicitly report hasMoreRows=false. Unknown or true flags still fetch normally. For complete CloudFetch and Arrow direct results, this matches Python, JDBC, and Node.

Preserve existing cleanup and error behavior: failed best-effort cleanup after a complete read leaves sql.Rows.Err() clear, while explicit early close still reports its error. Paginated results and Arrow iterator ownership retain their existing behavior.

For large_results_0005mb, timed RPCs change from ExecuteStatement → FetchResults → CloseOperation to ExecuteStatement → CloseOperation.

Client time in milliseconds, measured before rebase at 9101d3b against main at 95d97b3: medians from four measured pairs after warm-up, subtracting server duration. The paired delta is the median of within-round differences.

Dashboard case Base Fix Paired delta
large_results_0005mb 768.9 683.6 -111.9
large_results_0010mb 846.9 821.7 -88.5
large_results_0025mb 961.0 977.7 -33.6
large_results_0050mb 1201.0 1139.5 -32.3
large_results_0100mb 1781.0 1592.1 -217.5
extended_types_array_inline 192.5 192.6 +0.4
low_latency_select_1 86.6 90.7 +4.3
low_latency_limit_0 91.3 85.5 -3.4

Validation after rebasing onto 9cc305f: go test -race ./... and repository lint pass. Public database/sql tests verify unchanged close/error semantics. Public Arrow tests cover complete inline and CloudFetch direct results through both batches and IPC streams, checking all records, EOF, zero fetches, and one close RPC. The pre-rebase live comparison matched checksums on all eight cases above and the separate 1 GB case; two 1 GB timing rounds returned 6,491,176 rows for both versions and retained the needed page fetches.

@vuanhphung
vuanhphung marked this pull request as ready for review November 11, 2026 08:52

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Low

Looks good, with one low-severity API-shape concern. The change is correct: direct-result HasMoreRows=false now skips the extra FetchResults, and rows.Close() with closeOnce closes the operation and runs the telemetry callback exactly once. One related gap is outside this diff: in the GetArrowBatches/IPC path, the iterator's release() still issues CloseOperation itself and drops its error, so in that path Rows.Close() telemetry reports about 0 ms latency and no close error.

@vuanhphung
vuanhphung force-pushed the fix/cloudfetch-direct-results branch from 2333012 to 2405a68 Compare November 12, 2026 04:39

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Low

Looks good overall, with one low concern. Honoring HasMoreRows=false and moving the operation close into a once-only Rows.Close() is correct for database/sql callers, and the new lifecycle and error tests cover that path well. The concern is that GetArrowBatches/GetArrowIPCStreams still close the operation early and drop the error, so close telemetry on those paths is wrong.

Comment thread internal/rows/rows.go Resolved

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Low

Looks good overall, with one low-severity concern. Honoring a direct-results HasMoreRows=false and moving operation cleanup into a sync.Once-guarded rows.Close() is correct, and the new lifecycle and error-reporting tests are thorough. The remaining concern is that the IPC-stream iterator path no longer closes the operation when it is drained.

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Medium · 1 Low

Looks good overall. Honoring HasMoreRows=false from direct results and moving cleanup to Rows.Close() is correct and well tested for row and IPC iteration. One medium concern: the GetArrowBatches iterator still closes the operation itself and drops the error, which defeats the close-error and telemetry handling this PR adds.

Comment thread rows/rows.go Resolved

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Medium · 1 Low

Mostly sound, with one medium gap: the GetArrowBatches record iterator still closes the operation itself, which bypasses the new Rows.Close() error reporting and telemetry. The sync.Once close, the hasMoreRows short-circuit and the test de-flaking look correct.

Comment thread rows/rows.go Resolved

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Low

Looks good: one low concern about close errors now showing up in sql.Rows.Err() after a clean read. The lifecycle refactor looks correct: closeOnce makes repeated Close() and the telemetry callback idempotent, GetArrowBatches still closes from its own iterator, the HasMoreRows=false short-circuit is limited to direct results, and the new tests cover the paginated, complete and unknown cases plus the database/sql path.

Comment thread internal/rows/rows.go Resolved
@vuanhphung vuanhphung changed the title fix: honor CloudFetch end-of-results before closing operations fix: skip redundant fetches for complete direct results Nov 12, 2026
@vuanhphung
vuanhphung force-pushed the fix/cloudfetch-direct-results branch from 735f911 to 9101d3b Compare November 12, 2026 06:10

@oss-reviewer-bot oss-reviewer-bot Bot 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.

✅ No issues identified by the review bot.

@aakash-saravanan-db aakash-saravanan-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Pagination completion is correctly kept separate from server-side closure, and the change preserves the existing EOF, early-close, and fetch-error behavior.

Non-blocking: could we add complete direct-result (HasMoreRows=false) cases through GetArrowBatches and GetArrowIPCStreams? The new database/sql matrix covers the row path well; these tests would also verify that the public Arrow APIs consume all direct data, reach EOF without FetchResults, and still close the server operation.

vuanhphung added a commit that referenced this pull request Nov 13, 2026
TestCloudFetchIterator_CloseReleases* ran bi.Next() on a goroutine and
called bi.Close() from the test goroutine without waiting for it, so
-race reported both goroutines touching the iterator's link and task
queues. Production never overlaps them: the iterator has one owner, and
database/sql serializes driver Next and Close through Rows.closemu.

Wait for the foreground Next before Close (the same hunks as #539), and
add a database/sql test that closes rows from another goroutine while
Next is blocked on a CloudFetch download.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
@vuanhphung
vuanhphung force-pushed the fix/cloudfetch-direct-results branch from 9101d3b to 456ed56 Compare November 13, 2026 23:41
@vuanhphung

Copy link
Copy Markdown
Collaborator Author

@aakash-saravanan-db added the requested coverage in 456ed56: both public Arrow APIs with complete inline and CloudFetch direct results (HasMoreRows=false, no server-side close). Each case consumes both direct batches/links, verifies EOF without FetchResults, and checks exactly one CloseOperation even after iterator and parent cleanup. Rebased onto current main, preserved its Arrow v18 migration and changelog entries, and passed go test -race ./... plus lint.


This comment was generated with GitHub MCP.

@oss-reviewer-bot oss-reviewer-bot Bot 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.

✅ No issues identified by the review bot.

@vuanhphung
vuanhphung force-pushed the fix/cloudfetch-direct-results branch from 456ed56 to ec754e7 Compare November 14, 2026 00:15

@oss-reviewer-bot oss-reviewer-bot Bot 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.

Verdict: 1 Nit

Looks good: I found no correctness issues. The new Close() in HasNext() does nothing on the paths that already closed the operation, because closedOnServer is already set there. It runs at the same point where the dropped final fetch used to trigger cleanup, and the public sql.Rows and Arrow tests cover the new short-circuit, including close errors.

Other findings

  • ⚪ Nit — The new comment in internal/rows/rows.go above closedOnServer ("CloudFetch may deliver all links without closing the server operation") replaced a comment about what closedOnServer means. It now explains why hasMoreRows is needed instead. It would be clearer to keep a short note on closedOnServer and put the CloudFetch rationale next to the hasMoreRows extraction.

@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Nit: move the CloudFetch rationale next to the hasMoreRows extraction and separately describe closedOnServer.

The existing sentence explains why pagination completion and server closure need separate state, so it sits above the two related inputs. The directResults.CloseOperation != nil assignment already states when the server operation is closed. Keeping this wording unchanged in the rebase; no correctness issue is involved.


This comment was generated with GitHub MCP.

@vuanhphung
vuanhphung enabled auto-merge November 14, 2026 00:21
@vuanhphung
vuanhphung added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit e84b38e Nov 14, 2026
14 checks passed
@vuanhphung
vuanhphung deleted the fix/cloudfetch-direct-results branch November 14, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants