NAME
DBIO::MSSQL::Diff::Index - Diff operations for MSSQL indexes
VERSION
version 0.900007
DESCRIPTION
Index-level diff operations for MSSQL. MSSQL supports CREATE INDEX, DROP INDEX, and CREATE INDEX ... DROP_EXISTING. Built on DBIO::Diff::Op (the nested walk). A definition change is a drop-then- create pair. Index column order is significant, so the column list is compared as an order-preserving dim field (not the order-independent default of "changed_index_fields" in DBIO::Diff::Compare).
A unique constraint is not an index. The model flags the entries that are constraints (is_unique_constraint, from sys.indexes), the kind "install_ddl" in DBIO::MSSQL::DDL writes for a unique declaration of the result class. The diff creates one the same way, as ALTER TABLE ... ADD CONSTRAINT <name> UNIQUE (...), and removes it with ALTER TABLE ... DROP CONSTRAINT: the server refuses DROP INDEX on a constraint (Msg 3723). A unique index (a declared mssql_indexes or idx entry with unique) stays CREATE UNIQUE INDEX / DROP INDEX. Being a constraint is part of what an entry is: a change from one to the other is a drop-then-create pair.
A filtered index (CREATE INDEX ... WHERE <predicate>, the filter of the model entry, read from sys.indexes.filter_definition) is a different index from the unfiltered one over the same columns: adding, removing or changing the filter is a drop-then-create pair, like any other definition change. The server hands the predicate back in a form of its own (a = 1 as ([a]=(1))), so two filters are compared through "normalize_filter", not as written. A target that declares no filter against a live index that has one is a change (the filter is part of the definition, not a field the desired state may leave open).
METHODS
diff
my @ops = DBIO::MSSQL::Diff::Index->diff(
$source, $target, $source_tables, $target_tables);
The optional $source_tables / $target_tables hashrefs are the tables sections of the two models (threaded in by DBIO::MSSQL::Diff). They detect tables that are being dropped in this same diff pass: MSSQL's DROP TABLE already removes that table's own indexes, so emitting a standalone DROP INDEX ... ON <table> for one of them would fail once the table is gone and abort the deploy. When these arguments are absent (e.g. direct unit-test calls) the set is empty and no drops are suppressed, preserving the original two-argument behaviour.
normalize_filter
my $key = DBIO::MSSQL::Diff::Index->normalize_filter($predicate);
Returns a comparison key for the predicate of a filtered index; undef and blank give the empty string (no filter). Outside of string literals, which are kept exactly: case is folded, whitespace collapsed and dropped around operators, parentheses and commas, [name] becomes name, parentheses around a number ((1), (-1)) go, and so do the parentheses that wrap the whole predicate. The server's ([a]=(1)) and ([a] IN ((1), (2), (3))) and the a = 1, a IN (1,2,3) a declaration says then come out the same (forms measured on MSSQL 2022). The key is for comparing only, never written as SQL.
as_sql
summary
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.