Skip to content

Conversation

Ananya2
Copy link
Contributor

@Ananya2 Ananya2 commented Sep 10, 2025

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: Used a dedicated query (INDEX_INFO_QUERY_DW) against sys.indexes to avoid temp table limitations and lack of sp_statistics support.

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.

Closes #2758

@Ananya2 Ananya2 self-assigned this Sep 10, 2025
@Ananya2 Ananya2 added this to the 13.2.1 milestone Sep 10, 2025
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.32%. Comparing base (02ee86c) to head (74e9554).

Files with missing lines Patch % Lines
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 71.42% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2763   +/-   ##
=========================================
  Coverage     52.32%   52.32%           
- Complexity     4140     4142    +2     
=========================================
  Files           149      149           
  Lines         34241    34238    -3     
  Branches       5718     5717    -1     
=========================================
+ Hits          17915    17916    +1     
- Misses        13830    13832    +2     
+ Partials       2496     2490    -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ananya2 Ananya2 force-pushed the user/anagarg/issue#2758 branch from fc4c9f7 to 38b8252 Compare September 12, 2025 07:25
…e as per sp_statistics official documentation
@Ananya2 Ananya2 modified the milestones: 13.2.1, 13.3.0 Sep 15, 2025
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.

DatabaseMetaData.getIndexInfo() now returns a ResultSet that throws when next() is called after it previously returned false
4 participants