Skip to content

Backport: Fix DatabaseMetaData.getIndexInfo() CachedRowSet invalid cursor position exception (#2763)#2780

Merged
Ananya2 merged 1 commit intorelease/13.2from
hotfix-release-13.2-pr-2763
Sep 23, 2025
Merged

Backport: Fix DatabaseMetaData.getIndexInfo() CachedRowSet invalid cursor position exception (#2763)#2780
Ananya2 merged 1 commit intorelease/13.2from
hotfix-release-13.2-pr-2763

Conversation

@Ananya2
Copy link
Copy Markdown
Contributor

@Ananya2 Ananya2 commented Sep 23, 2025

This PR backports the fix from #2763 into the release/13.2 branch.

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 from sp_statistics and Columnstore index queries. However, CachedRowSet has stricter cursor validation than SQLServerResultSet:

if (cursorPos < 0 || cursorPos >= numRows + 1) {
    throw new SQLException("Invalid cursor position");
}

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

  • SQL Server: Replaced CachedRowSet merging with a single UNION ALL query (INDEX_INFO_COMBINED_QUERY) that combines sp_statistics results with Columnstore index data from sys.indexes.
  • Azure Synapse DW: Execute sp_statistics separately and combine with sys.indexes via UNION ALL ensuring comprehensive index coverage including columnstore indexes.

This eliminates intermediate result set handling and ensures consistent behavior across environments.

Testing

  • Validated cursor behavior on both SQL Server and Azure Synapse DW.
  • Added comprehensive JUnit tests for ResultSet navigation patterns.
  • Verified Columnstore indexes are properly included.
  • Confirmed sp_statistics compatibility maintained.

…ion exception (#2763)

* Fix DatabaseMetaData.getIndexInfo() CachedRowSet invalid cursor position exception

* removed unused imports

* Fix ADO getIndexInfo test failures

* Reverted INDEX_QUALIFIER to return table name instead of database name as per sp_statistics official documentation

* Fix catalog switching in getIndexInfo to handle cross-database queries and fix ADO regression test failure

* Fix Azure DW getIndexInfo to include columnstore indexes via UNION ALL

* Fix getIndexInfo ORDER BY clause to match sp_statistics server implementation
@Ananya2 Ananya2 self-assigned this Sep 23, 2025
@Ananya2 Ananya2 merged commit 531bbd2 into release/13.2 Sep 23, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants