Fix DatabaseMetaData.getIndexInfo() CachedRowSet invalid cursor position exception #2763
+82
−53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR updates DatabaseMetaData.getIndexInfo() to address an issue where calling ResultSet.next() after exhaustion could throw an invalid cursor position exception.
The fix removes the use of CachedRowSet for combining sp_statistics and columnstore index results, and instead uses a
UNION ALL
query. This ensures standard JDBC cursor behavior while keeping columnstore index support intact.Problem Description
The current implementation uses
CachedRowSet
to merge results fromsp_statistics
and Columnstore index queries. However,CachedRowSet
has stricter cursor validation thanSQLServerResultSet
:This causes SQLException: Invalid cursor position when next() is called after the ResultSet has been fully enumerated, which differs from standard JDBC behavior where such calls should simply return false.
Root Cause
Columnstore index support was first added in #2598
to address missing indexes in sp_statistics results. That implementation relied on CachedRowSet to merge sp_statistics output with additional Columnstore index query results, which in turn caused the cursor positioning issue.
Solution
This eliminates intermediate result set handling and ensures consistent behavior across environments.
Testing
Closes #2758