Skip to content

Fix NON_UNIQUE value inconsistency in DatabaseMetaData.getIndexInfo() - #2773

Merged
Ananya Garg (Ananya2) merged 1 commit into
mainfrom
user/anagarg/issue#2771
Sep 15, 2025
Merged

Fix NON_UNIQUE value inconsistency in DatabaseMetaData.getIndexInfo()#2773
Ananya Garg (Ananya2) merged 1 commit into
mainfrom
user/anagarg/issue#2771

Conversation

@Ananya2

@Ananya2 Ananya Garg (Ananya2) commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

Problem

DatabaseMetaData.getIndexInfo() was returning incorrect NON_UNIQUE values due to inconsistent handling between sp_statistics and sys.indexes result sets.

  • sp_statistics: NON_UNIQUE with 1 = not unique, 0 = unique
  • sys.indexes: is_unique with 1 = unique, 0 = not unique

The method was merging results from both sources without properly converting the sys.indexes.is_unique values to the expected JDBC NON_UNIQUE format, causing the same index to appear as both unique and non-unique.

Solution

  • Added proper conversion logic: CASE WHEN i.is_unique = 1 THEN 0 ELSE 1 END AS NON_UNIQUE
  • Applied consistent NON_UNIQUE value mapping across all index queries
  • Ensured compatibility with both regular SQL Server and Azure Synapse Analytics

Testing

  • Verified correct NON_UNIQUE values for unique and non-unique indexes

Closes #2771

@codecov

codecov Bot commented Sep 15, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.32%. Comparing base (02ee86c) to head (29724fb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2773   +/-   ##
=========================================
  Coverage     52.32%   52.32%           
- Complexity     4140     4151   +11     
=========================================
  Files           149      149           
  Lines         34241    34241           
  Branches       5718     5718           
=========================================
+ Hits          17915    17916    +1     
- Misses        13830    13838    +8     
+ Partials       2496     2487    -9     

☔ 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.

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() return wrong NON_UNIQUE value

4 participants