Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs related to version 7 GUID generation #349

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions conceptual/EFCore.PG/modeling/generated-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

## GUID/UUID Generation

By default, for GUID key properties, a random GUID is generated client-side by the EF provider and sent to the database.
By default, for GUID key properties, a GUID is generated client-side by the EF provider and sent to the database. From version 9.0 and onwards, these GUIDs are sequential (version 7), which are more optimized for database indexes (before version 9.0, these GUIDs were random).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider emphasis on the word key.

I personally read over this without much realization, until I read the next paragraph.


To generate GUID's client-side for non-key properties, configure them as follows:
To have the provider generate GUIDs client-side for **non-key** properties, configure them as follows:

```c#
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<Blog>()
.Property(b => b.SomeGuidProperty)
.HasValueGenerator<GuidValueGenerator>();
.HasValueGenerator<NpgsqlSequentialGuidValueGenerator>();
}
```

Expand Down
25 changes: 25 additions & 0 deletions conceptual/EFCore.PG/release-notes/9.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 9.0 Release Notes

Npgsql.EntityFrameworkCore.PostgreSQL version 9.0 is under development; previews are available on [nuget.org](https://www.nuget.org/packages/Npgsql.EntityFrameworkCore.PostgreSQL).

## UUIDv7 GUIDs are generated by default

When your entity types have a `Guid` key, EF Core by default generates key values for new entities client-side - in .NET - before inserting those entity types to the database; this can be better for performance in some situations. Before version 9.0, the provider generated random GUIDs (version 4) by calling the .NET [`Guid.NewGuid()`](https://learn.microsoft.com/en-us/dotnet/api/system.guid.newguid?view=net-8.0#system-guid-newguid) function. Unfortunately, random GUIDs aren't ideal for database indexing and can cause performance issues.

Version 9.0 of the provider now generates the recently standardized version 7 GUIDs, which is a sequential GUID type that's more appropriate for database indexes and improves their performance. This new behavior is by default and will take effect simply by upgrading the provider version.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Was "this new behavior is by default" intended to read "this new behavior is on/enabled by default"?


See [this post](https://www.cybertec-postgresql.com/en/unexpected-downsides-of-uuid-keys-in-postgresql) for more details and performance numbers on random vs. sequential GUIDs.

Thanks to [@ChrisJollyAU](https://github.com/ChrisJollyAU) and [@Timovzl](https://github.com/Timovzl) for contributing this improvement!

## Contributors

A big thank you to all the following people who contributed to the 9.0 release!

### [Milestone 9.0.0](https://github.com/npgsql/efcore.pg/milestone/61?closed=1)

Contributor | Assigned issues
------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------
[@roji](https://github.com/roji) | [34](https://github.com/Npgsql/efcore.pg/issues?q=is%3Aissue+milestone%3A8.0.0+is%3Aclosed+assignee%3Aroji)
[@ChrisJollyAU](https://github.com/ChrisJollyAU) | [1](https://github.com/Npgsql/efcore.pg/issues?q=is%3Aissue+milestone%3A8.0.0+is%3Aclosed+assignee%3AChrisJollyAU)
[@Timovzl](https://github.com/Timovzl) | [1](https://github.com/Npgsql/efcore.pg/issues?q=is%3Aissue+milestone%3A8.0.0+is%3Aclosed+assignee%3ATimovzl)