Skip to content

Fix collation conflict in getIndexInfo() UNION ALL with different server/database collations - #2867

Merged
Ananya Garg (Ananya2) merged 1 commit into
mainfrom
user/anagarg/issue#2856
Dec 29, 2025
Merged

Fix collation conflict in getIndexInfo() UNION ALL with different server/database collations#2867
Ananya Garg (Ananya2) merged 1 commit into
mainfrom
user/anagarg/issue#2856

Conversation

@Ananya2

@Ananya2 Ananya Garg (Ananya2) commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Summary

Fixes GitHub Issue #2856 - collation conflicts in SQLServerDatabaseMetaData.getIndexInfo() when SQL Server instance and database have different collations.

Problem

The INDEX_INFO_COMBINED_QUERY performs UNION ALL operations between sp_statistics results and sys.indexes metadata. When the SQL Server instance collation differs from the database collation, this causes collation conflict errors in the ORDER BY clause:
Cannot resolve collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Finnish_Swedish_CI_AS" in UNION ALL operator occurring in ORDER BY statement column 3.

Root Cause

The UNION ALL combines: sp_statistics results (using server/system collation context) and sys.indexes query results (using database collation context).
When ORDER BY processes column 3 (TABLE_NAME), SQL Server cannot resolve the collation difference between the two result sets.

Solution

Added COLLATE DATABASE_DEFAULT to all string columns (NVARCHAR/VARCHAR) in INDEX_INFO_COMBINED_QUERY to prevent collation conflicts when SQL Server instance and database have different collations. 
This fixes UNION ALL ORDER BY failures in mixed collation environments while maintaining comprehensive index coverage.

Closes #2856

@Ananya2 Ananya Garg (Ananya2) self-assigned this Dec 22, 2025
@codecov

codecov Bot commented Dec 22, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.46%. Comparing base (303aeb9) to head (c31a6cf).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 71.42% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2867      +/-   ##
============================================
+ Coverage     56.44%   56.46%   +0.01%     
- Complexity     4559     4569      +10     
============================================
  Files           151      151              
  Lines         34560    34564       +4     
  Branches       5768     5769       +1     
============================================
+ Hits          19508    19517       +9     
- Misses        12418    12427       +9     
+ Partials       2634     2620      -14     

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

@machavan Mahendra Chavan (machavan) added this to the 13.3.1 milestone Dec 23, 2025
@Ananya2

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@Ananya2
Ananya Garg (Ananya2) merged commit ce88330 into main Dec 29, 2025
19 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.

SQLServerDatabaseMetaData getIndexInfo collation error.

3 participants