Rebuild indexes when altering sparse SQL Server columns - #38765
Open
AndriySvyryd with Copilot wants to merge 4 commits into
Open
Rebuild indexes when altering sparse SQL Server columns#38765AndriySvyryd with Copilot wants to merge 4 commits into
AndriySvyryd with Copilot wants to merge 4 commits into
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unable to make a column sparse with an index
Rebuild indexes when altering sparse SQL Server columns
Aug 7, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates SQL Server migration SQL generation so that altering a column’s SPARSE setting will drop/recreate dependent indexes around ALTER COLUMN, avoiding SQL Server failures when indexes reference the altered column (fixing #38760).
Changes:
- Treat
SPARSEannotation changes similarly to narrowing/type changes for index rebuild purposes inSqlServerMigrationsSqlGenerator. - Generate
DROP INDEX ...beforeALTER TABLE ... ALTER COLUMN ... SPARSE ...andCREATE INDEX ...afterward. - Add a SQL Server functional migration test covering converting an indexed column to sparse.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs | Triggers index rebuilds when the SPARSE annotation changes during AlterColumn. |
| test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs | Adds regression coverage asserting index drop/recreate around sparse column alteration. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
AndriySvyryd
marked this pull request as ready for review
August 7, 2026 22:02
AndriySvyryd
enabled auto-merge (squash)
August 7, 2026 22:03
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs:325
- The newly added
sparseChangedlines contain stray carriage-return characters (shown asin the file view), which introduces mixed line endings in this LF file. Please normalize these lines to the repository’s standard line endings to avoid noisy diffs and potential style checks failing.
var sparseChanged = ((bool?)operation[SqlServerAnnotationNames.Sparse] ?? false)
!= ((bool?)operation.OldColumn[SqlServerAnnotationNames.Sparse] ?? false);
AndriySvyryd
reviewed
Aug 7, 2026
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
auto-merge was automatically disabled
August 7, 2026 23:27
Head branch was pushed to by a user without write access
Member
|
@cincuranet "Hide whitespace" when reviewing |
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.
Altering a column to
SPARSEfails when SQL Server indexes depend on that column. Migrations now recreate affected indexes around the column alteration.ALTER COLUMNand recreate them afterward.