mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-25 01:54:29 +00:00

get instance by domain cannot provide an instance id because it is not known at that time. This causes a full table scan on the fields table because current indexes always include the `instance_id` column. Added a specific index for this query. If a system has many fields and there is no cache hit for the given domain this query can heaviuly influence database CPU usage, the newly added resolves this problem. (cherry picked from commit f320d18b1a24b97b67500d471c11068fd09b6c39)
41 lines
946 B
Go
41 lines
946 B
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"fmt"
|
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
var (
|
|
//go:embed 43/cockroach/*.sql
|
|
//go:embed 43/postgres/*.sql
|
|
createFieldsDomainIndex embed.FS
|
|
)
|
|
|
|
type CreateFieldsDomainIndex struct {
|
|
dbClient *database.DB
|
|
}
|
|
|
|
func (mig *CreateFieldsDomainIndex) Execute(ctx context.Context, _ eventstore.Event) error {
|
|
statements, err := readStatements(createFieldsDomainIndex, "43", mig.dbClient.Type())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, stmt := range statements {
|
|
logging.WithFields("file", stmt.file, "migration", mig.String()).Info("execute statement")
|
|
if _, err := mig.dbClient.ExecContext(ctx, stmt.query); err != nil {
|
|
return fmt.Errorf("%s %s: %w", mig.String(), stmt.file, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mig *CreateFieldsDomainIndex) String() string {
|
|
return "43_create_fields_domain_index"
|
|
}
|