fix: remove duplicate indexes in package_blob table (#12836)
Table `package_blob` has both unique indexes, and standard indexes, defined on each of its hash columns. This PR removes the standard indexes and leaves just the unique indexes, which will reduce disk space usage and improve performance on writing to the table. Manual testing: confirmed that the indexes are removed by inspecting the database table in my dev environment before and after the migration. I've reviewed other database tables for similar situations where a unique index is present and non-unique indexes are present but therefore not needed. I've found no other cases. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12836 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Copyright 2026 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package forgejo_migrations
|
||||
|
||||
import (
|
||||
"code.forgejo.org/xorm/xorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerMigration(&Migration{
|
||||
Description: "cleanup extra indexes on package_blob",
|
||||
Upgrade: cleanupPackageBlobIndexes,
|
||||
})
|
||||
}
|
||||
|
||||
func cleanupPackageBlobIndexes(x *xorm.Engine) error {
|
||||
for _, idx := range []string{
|
||||
"IDX_package_blob_hash_blake2b",
|
||||
"IDX_package_blob_hash_md5",
|
||||
"IDX_package_blob_hash_sha1",
|
||||
"IDX_package_blob_hash_sha256",
|
||||
"IDX_package_blob_hash_sha512",
|
||||
} {
|
||||
err := dropIndexIfExists(x, "package_blob", idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -30,11 +30,11 @@ func init() {
|
||||
type PackageBlob struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Size int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
HashMD5 string `xorm:"hash_md5 char(32) UNIQUE(md5) INDEX NOT NULL"`
|
||||
HashSHA1 string `xorm:"hash_sha1 char(40) UNIQUE(sha1) INDEX NOT NULL"`
|
||||
HashSHA256 string `xorm:"hash_sha256 char(64) UNIQUE(sha256) INDEX NOT NULL"`
|
||||
HashSHA512 string `xorm:"hash_sha512 char(128) UNIQUE(sha512) INDEX NOT NULL"`
|
||||
HashBlake2b string `xorm:"hash_blake2b char(128) UNIQUE(blake2b) INDEX"`
|
||||
HashMD5 string `xorm:"hash_md5 char(32) UNIQUE(md5) NOT NULL"`
|
||||
HashSHA1 string `xorm:"hash_sha1 char(40) UNIQUE(sha1) NOT NULL"`
|
||||
HashSHA256 string `xorm:"hash_sha256 char(64) UNIQUE(sha256) NOT NULL"`
|
||||
HashSHA512 string `xorm:"hash_sha512 char(128) UNIQUE(sha512) NOT NULL"`
|
||||
HashBlake2b string `xorm:"hash_blake2b char(128) UNIQUE(blake2b)"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user