fix: honor maxRowCount in Druid JDBC Statement (setMaxRows) - #19946
fix: honor maxRowCount in Druid JDBC Statement (setMaxRows)#19946waterWang wants to merge 1 commit into
Conversation
Ordinary JDBC Statement.setMaxRows() was ignored because DruidJdbcStatement.execute() hardcoded Long.MAX_VALUE instead of forwarding the maxRowCount parameter. Additionally, ResultFetcher only marked a frame complete when the underlying yielder was exhausted, so reaching the row limit produced empty non-terminal frames indefinitely. - DruidJdbcStatement: pass maxRowCount through to DruidJdbcResultSet - DruidJdbcResultSet.ResultFetcher: mark frame done when the limit is reached - Add tests verifying maxRowCount limits rows in single and multiple frames Fixes apache#19918
FrankChen021
left a comment
There was a problem hiding this comment.
| Severity | Findings |
|---|---|
| P0 | 0 |
| P1 | 1 |
| P2 | 0 |
| P3 | 0 |
| Total | 1 |
Reviewed 3 of 3 changed files.
Validation: git diff --check passed; no builds or tests were run.
This is an automated review by Codex GPT-5.6-Luna(max)
| } | ||
|
|
||
| final Meta.Frame result = new Meta.Frame(offset, yielder.isDone(), rows); | ||
| final Meta.Frame result = new Meta.Frame(offset, yielder.isDone() || offset >= limit, rows); |
There was a problem hiding this comment.
[P1] Row-limit completion checks the pre-fetch offset
When the current frame reaches the configured limit, offset has not yet been incremented, so done remains false and the client must request an extra empty frame before the result set terminates. Check offset + rowCount >= limit, or increment before checking, so the final frame is terminal.
|
Disclosure first: I have an open PR for the same issue (#19941), so please read this as an interested party's report rather than a neutral review. Everything below is reproducible. Neither of the two new tests has run yet, because On this branch as-is (0867233), JDK 25 on macOS: The same error repeats at 392 and 399. Merged with current master there is a second failure on top of that one. Once it compiles, both new tests fail. I changed only the three Both failures are the |
Problem
Statement.setMaxRows()was ignored for ordinary JDBC Statements becauseDruidJdbcStatement.execute()hardcodedLong.MAX_VALUEinstead of forwarding themaxRowCountparameter. Additionally,ResultFetcheronly marked a frame complete when the underlying yielder was exhausted, so reaching the row limit produced empty non-terminal frames indefinitely.See issue #19918 for the full analysis.
Changes
maxRowCountthrough toDruidJdbcResultSetinstead ofLong.MAX_VALUEdonewhen the row limit is reached (offset >= limit), not only when the yielder is exhaustedtestMaxRowCountDirect(single frame) andtestMaxRowCountOverMultipleFramesDirect(cross-frame limit)Key insight
The
maxRowCountwas already correctly threaded through the PreparedStatement path (DruidJdbcPreparedStatement). The bug was specific to the ordinary Statement path (DruidJdbcStatement.execute()).Fixes #19918