-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs on SQL Server-specific index config (#2600)
- Loading branch information
Showing
7 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: Microsoft SQL Server Database Provider - Indexes - EF Core | ||
description: Index features specific to the Entity Framework Core SQL Server provider | ||
author: roji | ||
ms.author: shrojans | ||
ms.date: 9/1/2020 | ||
uid: core/providers/sql-server/indexes | ||
--- | ||
# Index features specific to the Entity Framework Core SQL Server provider | ||
|
||
This page details index configuration options that are specific to the SQL Server provider. | ||
|
||
## Clustering | ||
|
||
Clustered indexes sort and store the data rows in the table or view based on their key values. Creating the right clustered index for your table can significantly improve the speed of your queries, as data is already laid out in the optimal order. There can be only one clustered index per table, because the data rows themselves can be stored in only one order. For more information, see [the SQL Server documentation on clustered and non-clustered indexes](/sql/relational-databases/indexes/clustered-and-nonclustered-indexes-described). | ||
|
||
By default, the primary key column of a table is implicitly backed by a clustered index, and all other indexes are non-clustered. | ||
|
||
You can configure an index or key to be clustered as follows: | ||
|
||
[!code-csharp[ClusteredIndex](../../../../samples/core/SqlServer/Indexes/ClusteredIndexContext.cs?name=ClusteredIndex)] | ||
|
||
## Fill factor | ||
|
||
> [!NOTE] | ||
> This feature is introduced in EF Core 5.0. | ||
The index fill-factor option is provided for fine-tuning index data storage and performance. For more information, see [the SQL Server documentation on fill factor](/sql/relational-databases/indexes/specify-fill-factor-for-an-index). | ||
|
||
You can configure an index's fill factor as follows: | ||
|
||
[!code-csharp[IndexFillFactor](../../../../samples/core/SqlServer/Indexes/IndexFillFactorContext.cs?name=IndexFillFactor)] | ||
|
||
## Online creation | ||
|
||
The ONLINE option allows concurrent user access to the underlying table or clustered index data and any associated nonclustered indexes during index creation, so that users can continue to update and query the underlying data. When you perform data definition language (DDL) operations offline, such as building or rebuilding a clustered index; these operations hold exclusive locks on the underlying data and associated indexes. For more information, see [the SQL Server documentation on the ONLINE index option](/sql/relational-databases/indexes/perform-index-operations-online). | ||
|
||
You can configure an index with the ONLINE option as follows: | ||
|
||
[!code-csharp[IndexOnline](../../../../samples/core/SqlServer/Indexes/IndexOnlineContext.cs?name=IndexOnline)] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace SqlServer.Indexes | ||
{ | ||
public class Blog | ||
{ | ||
public int BlogId { get; set; } | ||
public string Url { get; set; } | ||
public DateTime PublishedOn { get; set; } | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace SqlServer.Indexes | ||
{ | ||
public class ClusteredIndexContext : DbContext | ||
{ | ||
public DbSet<Blog> Blogs { get; set; } | ||
|
||
#region ClusteredIndex | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Blog>().HasIndex(b => b.PublishedOn).IsClustered(); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace SqlServer.Indexes | ||
{ | ||
public class IndexFillFactorContext : DbContext | ||
{ | ||
public DbSet<Blog> Blogs { get; set; } | ||
|
||
#region IndexFillFactor | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Blog>().HasIndex(b => b.PublishedOn).HasFillFactor(10); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace SqlServer.Indexes | ||
{ | ||
public class IndexOnlineContext : DbContext | ||
{ | ||
public DbSet<Blog> Blogs { get; set; } | ||
|
||
#region IndexOnline | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Blog>().HasIndex(b => b.PublishedOn).IsCreatedOnline(); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains 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