Fix collation conflict in getIndexInfo() UNION ALL with different server/database collations - #2867
Merged
Merged
Conversation
…ver/database collations
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Mahendra Chavan (machavan)
approved these changes
Dec 29, 2025
Muskan Gupta (muskan124947)
approved these changes
Dec 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes GitHub Issue #2856 - collation conflicts in
SQLServerDatabaseMetaData.getIndexInfo()when SQL Server instance and database have different collations.Problem
The
INDEX_INFO_COMBINED_QUERYperforms UNION ALL operations betweensp_statisticsresults andsys.indexesmetadata. 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_statisticsresults (using server/system collation context) andsys.indexesquery 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_DEFAULTto 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