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

Set index length limit for MySQL #14500

Merged
merged 4 commits into from
Oct 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<int> CreateAsync()
SchemaBuilder.AlterIndexTable<DashboardPartIndex>(table => table
.CreateIndex("IDX_DashboardPart_DocumentId",
"DocumentId",
nameof(DashboardPartIndex.Position))
"Position")
);

_contentDefinitionManager.AlterPartDefinition("DashboardPart", builder => builder
Expand All @@ -56,7 +56,7 @@ public int UpdateFrom2()
SchemaBuilder.AlterIndexTable<DashboardPartIndex>(table => table
.CreateIndex("IDX_DashboardPart_DocumentId",
"DocumentId",
nameof(DashboardPartIndex.Position))
"Position")
);

return 3;
Expand Down
3 changes: 0 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public int Create()
.Attachable()
.WithDescription("Provides a way to define custom aliases for content items."));

// NOTE: The Alias Length has been upgraded from 64 characters to 767.
// For existing SQL databases update the AliasPartIndex tables Alias column length manually.
// INFO: The Alias Length is now of 735 chars, but this is only used on a new installation.
Copy link
Member

@jtkech jtkech Oct 12, 2023

Choose a reason for hiding this comment

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

As said in #14491 (comment)

... DocumentId (26) is wrong as it is at most a bigint (size = 8 bytes = 2 chars size), the 2 booleans may not share the same bytes but one char size (4 bytes) for both is sufficient, anyway we kept a margin of 4 bytes.

Not so important to assume one "char" per boolean, but at least comment DocumentId (2) which here will allow Alias(738), and if we want to keep a margin of 4 bytes => Alias(734).

Then the following comments could be removed, and maybe revert back MaxAliasLength to its original value, from memory it was 1024, but maybe too much, I don't know, just for info.

// Maximum length that MySql can support in an index under utf8mb4 collation is 768,
// minus 2 for the `DocumentId` integer (bigint size = 8 bytes = 2 character size),
// minus 26 for the `ContentItemId` and 1 for the 'Published' and 'Latest' bools.
// minus 4 to allow at least to add a new integer column.
public const int MaxAliasLength = 735;
public string Alias { get; set; }

Same remark for other indexes.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jtkech thanks for pointing out the seize of DocumentId I know it was long but assumed it was a char :). Anyway, I update it.

SchemaBuilder.CreateMapIndexTable<AliasPartIndex>(table => table
.Column<string>("Alias", col => col.WithLength(AliasPart.MaxAliasLength))
.Column<string>("ContentItemId", c => c.WithLength(26))
Expand Down
21 changes: 10 additions & 11 deletions src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using OrchardCore.ArchiveLater.Models;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data.Migration;
using YesSql.Sql;

Expand All @@ -25,20 +24,20 @@ public int Create()
.WithDescription("Adds the ability to schedule content items to be archived at a given future date and time."));

SchemaBuilder.CreateMapIndexTable<ArchiveLaterPartIndex>(table => table
.Column<string>(nameof(ArchiveLaterPartIndex.ContentItemId))
.Column<DateTime>(nameof(ArchiveLaterPartIndex.ScheduledArchiveDateTimeUtc))
.Column<bool>(nameof(ArchiveLaterPartIndex.Published))
.Column<bool>(nameof(ArchiveLaterPartIndex.Latest))
.Column<string>("ContentItemId")
.Column<DateTime>("ScheduledArchiveDateTimeUtc")
.Column<bool>("Published")
.Column<bool>("Latest")
);

SchemaBuilder.AlterIndexTable<ArchiveLaterPartIndex>(table => table
.CreateIndex($"IDX_{nameof(ArchiveLaterPartIndex)}_{nameof(ContentItemIndex.DocumentId)}",
.CreateIndex("IDX_ArchiveLaterPartIndex_DocumentId",
"Id",
nameof(ContentItemIndex.DocumentId),
nameof(ArchiveLaterPartIndex.ContentItemId),
nameof(ArchiveLaterPartIndex.ScheduledArchiveDateTimeUtc),
nameof(ArchiveLaterPartIndex.Published),
nameof(ArchiveLaterPartIndex.Latest))
"DocumentId",
"ContentItemId",
"ScheduledArchiveDateTimeUtc",
"Published",
"Latest")
);

return 1;
Expand Down
14 changes: 7 additions & 7 deletions src/OrchardCore.Modules/OrchardCore.AuditTrail/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public int Create()
SchemaBuilder.AlterIndexTable<AuditTrailEventIndex>(table => table
.CreateIndex("IDX_AuditTrailEventIndex_DocumentId",
"DocumentId",
nameof(AuditTrailEventIndex.EventId),
nameof(AuditTrailEventIndex.Category),
nameof(AuditTrailEventIndex.Name),
nameof(AuditTrailEventIndex.CorrelationId),
nameof(AuditTrailEventIndex.UserId),
nameof(AuditTrailEventIndex.NormalizedUserName),
nameof(AuditTrailEventIndex.CreatedUtc)
"EventId",
"Category",
"Name",
"CorrelationId",
"UserId",
"NormalizedUserName",
"CreatedUtc"
),
collection: AuditTrailEvent.Collection
);
Expand Down
Loading