Skip to content

SQL Server: a filter or INCLUDE entry naming a column in another case is not moved out of the way of ALTER COLUMN (Msg 5074) #189

Closed

Description

@CaffeinatedCoder

Found by a sweep of release/5.x @ d28c938 for base operations the differs do not account for (the shape of #182); reproduced in a scratch MigrationHarness.SqlServerDiff test. Not applied to a live server; the failure is SQL Server's Msg 5074 for a column a filtered index reads, which AlterColumnUnderIndexTests.SqlServer_alter_filter_column_under_index (#156) already pins.

Problem

On SQL Server, an unchanged complex index is moved out of the way of an ALTER COLUMN only when its filter or INCLUDE list spells the column in exactly the column's case. SQL Server reads identifiers case-insensitively under its default collation, so a filter [note] IS NULL on a column Note depends on it. The differ does not see that, emits no drop or create, and the ALTER COLUMN fails at apply (Msg 5074).

ColumnsReadBy and ColumnsNamedIn (CustomMigrationsModelDiffer.cs:651–669) collect the columns an index reads with StringComparer.Ordinal and text.Contains(name, StringComparison.Ordinal). The SQL Server checks columns.Contains(alter.Name) and filterColumns.Contains(rename.NewName) (SqlServerComplexIndexMigrationsModelDiffer.cs:67, :75) inherit that. Meanwhile ValidateIncludedColumns accepts an INCLUDE entry in another case on purpose, because it compares with IndexNameComparer, which ignores case on SQL Server. The package's own validation approves a spelling that its recreation check cannot see.

Model: members with Note (HasMaxLength(200)) and

b.HasComplexIndex(x => x.Email, isUnique: true, filter: "[note] IS NULL", indexName: "ux_members_email_without_note");
// or
b.HasComplexIndex(x => x.Email, ix => ix.HasName("ix_members_email").IncludeProperties("note"));

Narrow Note to HasMaxLength(100). The operations are AlterColumnOperation alone. Had the filter said [Note], the index would be dropped before it and created after, which is #84.

Traced, not run: a case-only column rename (Note → NOTE) under the filter [note] IS NULL misses the filterColumns check of #182 the same way, and sp_rename fails.

Placeholder filters ({Note}) and property-path INCLUDE entries resolve to the exact column name and are not affected.

Change

Compare column names in ColumnsReadBy and ColumnsNamedIn with the provider's identifier comparison: IndexNameComparer or a sibling virtual. That is case-insensitive on SQL Server and SQLite and ordinal on PostgreSQL. Ignoring case is the safe direction: at worst it costs a needless rebuild on a case-sensitive collation.

The migration fails at apply today, so no database holds its result. The fix changes what this model scaffolds, and it ships on release/5.x.

Tests

  • SqlServerDiff tests for both models above: the index is dropped before the AlterColumnOperation and created after it.
  • A case-only column rename under the filter: the index is rebuilt around the RenameColumnOperation.
  • A PostgreSQL counterpart where case matters: a filter naming "note" against a column Note is a different column, and nothing is rebuilt.

Activity

  1. added this to the 5.6.0 milestone on Oct 23, 2026
  2. added
    bug
    severity/low
    package/core
    package/sqlserver
    area/indexes
    area/migrations
    on Oct 23, 2026
  3. CaffeinatedCoder commented on Oct 23, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Fixed on release/5.x by #194, shipping in 5.6.0. Closed by hand: Closes acts only on merges into main.

    The columns an index reads now compare under the provider's identifier rule (IndexNameComparer): on SQL Server a filter's [note] or an INCLUDE entry note reads the column Note, so the index is moved out of the way of an ALTER COLUMN or rename of it. PostgreSQL still compares exactly.

  4. added a commit that references this issue on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/indexesarea/migrationsbugpackage/corepackage/sqlserverseverity/low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions