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

Add composite index for executions #4872

Closed
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
10 changes: 10 additions & 0 deletions flyteadmin/pkg/repositories/config/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,16 @@
return tx.AutoMigrate(&Execution{})
},
},
//Add composite index for executions table on execution_project, execution_domain, phase, created_at and state
{
ID: "2024-02-09-executions-composite-idx",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{})
},
Rollback: func(tx *gorm.DB) error {
return tx.Migrator().DropIndex("execution_project_domain_phase_created_at_state_idx")

Check failure on line 1190 in flyteadmin/pkg/repositories/config/migrations.go

View workflow job for this annotation

GitHub Actions / compile

not enough arguments in call to tx.Migrator().DropIndex
},
},
}

var Migrations = append(LegacyMigrations, NoopMigrations...)
Expand Down
10 changes: 5 additions & 5 deletions flyteadmin/pkg/repositories/models/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

// Execution primary key
type ExecutionKey struct {
Project string `gorm:"primary_key;column:execution_project" valid:"length(0|255)"`
Domain string `gorm:"primary_key;column:execution_domain" valid:"length(0|255)"`
Project string `gorm:"primary_key;column:execution_project;index:execution_project_domain_phase_created_at_state_idx,priority:1" valid:"length(0|255)"`
Domain string `gorm:"primary_key;column:execution_domain;index:execution_project_domain_phase_created_at_state_idx,priority:2" valid:"length(0|255)"`
Name string `gorm:"primary_key;column:execution_name" valid:"length(0|255)"`
}

Expand All @@ -26,13 +26,13 @@ type Execution struct {
LaunchPlanID uint `gorm:"index"`
WorkflowID uint `gorm:"index"`
TaskID uint `gorm:"index"`
Phase string `valid:"length(0|255)"`
Phase string `gorm:"index:execution_project_domain_phase_created_at_state_idx,priority:3" valid:"length(0|255)"`
Closure []byte
Spec []byte `gorm:"not null"`
StartedAt *time.Time
// Corresponds to the CreatedAt field in the Execution closure.
// Prefixed with Execution to avoid clashes with gorm.Model CreatedAt
ExecutionCreatedAt *time.Time `gorm:"index:idx_executions_created_at"`
ExecutionCreatedAt *time.Time `gorm:"index:idx_executions_created_at;index:execution_project_domain_phase_created_at_state_idx,priority:4"`
// Corresponds to the UpdatedAt field in the Execution closure
// Prefixed with Execution to avoid clashes with gorm.Model UpdatedAt
ExecutionUpdatedAt *time.Time
Expand Down Expand Up @@ -60,7 +60,7 @@ type Execution struct {
// This is also stored in the spec but promoted as a column for filtering.
User string `gorm:"index" valid:"length(0|255)"`
// GORM doesn't save the zero value for ints, so we use a pointer for the State field
State *int32 `gorm:"index;default:0"`
State *int32 `gorm:"index;default:0;index:execution_project_domain_phase_created_at_state_idx,priority:5"`
// The resource type of the entity used to launch the execution, one of 'launch_plan' or 'task'
LaunchEntity string
// Tags associated with the execution
Expand Down
Loading