Skip to content

Commit 58897c4

Browse files
committed
adjusted the prefix length for indexable fields
Signed-off-by: kaikaila <[email protected]>
1 parent 15ec1d9 commit 58897c4

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

backend/src/apiserver/model/experiment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package model
1616

1717
type Experiment struct {
1818
UUID string `gorm:"column:UUID; not null; primaryKey;"`
19-
Name string `gorm:"column:Name; not null; uniqueIndex:idx_name_namespace; type:varchar(255);"`
19+
Name string `gorm:"column:Name; not null; uniqueIndex:idx_name_namespace; type:varchar(128);"`
2020
Description string `gorm:"column:Description; not null;"`
2121
CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null;"`
2222
LastRunCreatedAtInSec int64 `gorm:"column:LastRunCreatedAtInSec; not null;"`

backend/src/apiserver/model/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
type Pipeline struct {
3434
UUID string `gorm:"column:UUID; not null; primaryKey;"`
3535
CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null;"`
36-
Name string `gorm:"column:Name; not null; uniqueIndex:namespace_name; type:varchar(191);"` // Index improves performance of the List ang Get queries
36+
Name string `gorm:"column:Name; not null; uniqueIndex:namespace_name; type:varchar(128);"` // Index improves performance of the List ang Get queries
3737
DisplayName string `gorm:"column:DisplayName; not null"`
3838
Description string `gorm:"column:Description; type:text;"` // Use type:longtext instead of size to ensure sufficient capacity
3939
// TODO(gkcalat): this is deprecated. Consider removing and adding data migration logic at the server startup.

backend/src/apiserver/model/pipeline_version.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,21 @@ const (
3131
type PipelineVersion struct {
3232
UUID string `gorm:"column:UUID; not null; primaryKey;"`
3333
CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null; index;"`
34-
// Explicitly specify type:varchar(255) to ensure MySQL can create index on this column.
34+
// Explicitly specify varchar(127) and varchar(64) for PipelineId & Name
35+
// so that the combined index (PipelineId + Name) do not exceed 767 bytes in utf8mb4,
36+
// which ensures MySQL can create composite index on this column.
3537
// In GORM v1, omitting type still allowed index creation due to default behavior.
3638
// However, GORM v2 requires explicit type declaration for indexed string fields,
3739
// otherwise it may default to longtext, which is not indexable in MySQL.
38-
Name string `gorm:"column:Name; not null; type:varchar(255); uniqueIndex:idx_pipelineid_name;"`
40+
Name string `gorm:"column:Name; not null; type:varchar(127); uniqueIndex:idx_pipelineid_name;"`
3941
DisplayName string `gorm:"column:DisplayName; not null"`
4042
// TODO(gkcalat): this is deprecated. Consider removing and adding data migration logic at the server startup.
4143
Parameters string `gorm:"column:Parameters; not null; type:text;"` // deprecated
4244
// PipelineVersion belongs to Pipeline. If a pipeline with a specific UUID
4345
// is deleted from Pipeline table, all this pipeline's versions will be
4446
// deleted from PipelineVersion table.
4547
// nolint:staticcheck // [ST1003] Field name matches upstream legacy naming
46-
PipelineId string `gorm:"column:PipelineId; not null; index; uniqueIndex:idx_pipelineid_name;"`
48+
PipelineId string `gorm:"column:PipelineId; not null; index; uniqueIndex:idx_pipelineid_name;type:varchar(64)"`
4749
Pipeline Pipeline `gorm:"foreignKey:PipelineId;references:UUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"` // This 'belongs to' relation replaces the legacy AddForeignKey constraint previously defined in client_manager.go
4850
Status PipelineVersionStatus `gorm:"column:Status; not null;"`
4951
// Code source url links to the pipeline version's definition in repo.

0 commit comments

Comments
 (0)