Commit c7f5ec3
committed
CREATE [UNIQUE] [CLUSTERED | NONCLUSTERED] INDEX … ON table (col [ASC | DESC] [, …]) [INCLUDE (cols)] [WHERE filter] [WITH (options)] + DROP INDEX [IF EXISTS] name ON table [, …] + sys.indexes / sys.index_columns catalog views — closes the largest remaining EF Migrations DDL gap. New
Storage/Index.cs (Name / ObjectId / IsUnique / IsClustered / IndexKeyColumn[] / IncludedColumns / Filter) and HeapTable.Indexes list; Simulation.CreateIndex.cs partial routes from the CREATE dispatch (Unique / Clustered / NonClustered / Index keywords) through modifier parsing, column resolution (Msg 1911 missing column), duplicate-name check against both Indexes + KeyConstraints (Msg 1913 with dbo.t qualification), and existing-data validation (Msg 1505 reusing the ALTER-bundle helper, filter-aware so excluded rows don't trigger). WITH (option = value) parsed parens-balanced and discarded (FILLFACTOR / IGNORE_DUP_KEY / ONLINE / etc all accepted, none honored). DROP INDEX routes ahead of the comma-list path in TryParseDrop (different grammar: name ON table), surfaces Msg 3701 St 6 / St 7 for missing-table / missing-index, Msg 3723 with PRIMARY KEY or UNIQUE constraint-kind word when targeting a PK/UQ-backing index, and supports IF EXISTS suppression for the does-not-exist paths only (probe-confirmed: 3723 fires regardless of IF EXISTS). UNIQUE enforcement extends both INSERT (EnforceUniqueIndexes in Simulation.Coerce.cs, called from Simulation.Insert.cs) and UPDATE / MERGE (EnforceUniqueIndexesForUpdate in Simulation.Update.cs, called from Simulation.Update.cs + Simulation.Merge.cs), raising Msg 2601 with the standard dbo.t qualification and key-tuple rendering. Filter-aware on both paths: an index with a WHERE filter only checks rows where the filter evaluates true on both the new row and the existing row being compared — false / UNKNOWN both skip, mirroring SQL Server's filtered-unique-index semantic. sys.indexes (24-column probe-confirmed shape) synthesizes one row per (table, index): PK at index_id=1 type_desc=CLUSTERED is_primary_key=1; tables without a PK emit index_id=0 type_desc=HEAP name=NULL; UQ constraints and user indexes share index_id 2+ in ObjectId order (matches SQL Server's declaration-order behavior); is_unique_constraint distinguishes UQ from CREATE UNIQUE INDEX. sys.index_columns (10-column probe-confirmed shape) emits per-column rows with key_ordinal 1..N for KEY columns and 0 for INCLUDE columns, is_descending_key from the per-column DESC flag, and column_id mapped back from storage ordinal via sys.columns-compatible full-column ordinal. Six new error factories: IndexAlreadyExists (Msg 1913), CannotFindObjectForCreateIndex (Msg 1088), CannotDropIndexDoesNotExist (Msg 3701 with state parameter), ExplicitDropIndexNotAllowed (Msg 3723), ViolationOfUniqueIndex (Msg 2601). 37 new CreateIndexTests cover grammar (UNIQUE / CLUSTERED / NONCLUSTERED / multi-column ASC / DESC / INCLUDE / WHERE filter / WITH options), error paths (1088 / 1505 / 1911 / 1913 / 3701 St 6+7 / 3723 on PK + UQ), filter-aware uniqueness (allows duplicates outside filter, rejects inside, UPDATE doesn't false-trigger across filter-excluded rows), Msg 2601 at INSERT + UPDATE, sys.indexes synthesis (HEAP for no-PK / CLUSTERED for PK / index_id assignment / is_unique_constraint vs is_unique distinction), and sys.index_columns shape. CLAUDE.md gains a trigger-phrase entry; new docs/claude/indexes.md documents the storage shape, enforcement loops, filter-aware semantic, catalog projection, and the four documented fidelity gaps (filter_definition always NULL, CLUSTERED keyword decorative, multiple-CLUSTERED silently accepted, WITH options ignored).1 parent 56175e6 commit c7f5ec3
16 files changed
Lines changed: 1593 additions & 2 deletions
File tree
- SqlServerSimulator.Tests
- SqlServerSimulator
- Errors
- Parser
- Simulation
- Storage
- docs/claude
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| |||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Lines changed: 15 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
741 | 741 | | |
742 | 742 | | |
743 | 743 | | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
744 | 781 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
263 | 339 | | |
264 | 340 | | |
265 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
0 commit comments