From 9b567fa6f45efa53e2e100be5af589bb03e55671 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:53:29 +1000 Subject: [PATCH] Exclude null values from image studio id index (#5335) --- pkg/sqlite/database.go | 2 +- pkg/sqlite/migrations/68_image_studio_index.up.sql | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 pkg/sqlite/migrations/68_image_studio_index.up.sql diff --git a/pkg/sqlite/database.go b/pkg/sqlite/database.go index eed335f09..0510d7baf 100644 --- a/pkg/sqlite/database.go +++ b/pkg/sqlite/database.go @@ -34,7 +34,7 @@ const ( cacheSizeEnv = "STASH_SQLITE_CACHE_SIZE" ) -var appSchemaVersion uint = 67 +var appSchemaVersion uint = 68 //go:embed migrations/*.sql var migrationsBox embed.FS diff --git a/pkg/sqlite/migrations/68_image_studio_index.up.sql b/pkg/sqlite/migrations/68_image_studio_index.up.sql new file mode 100644 index 000000000..3bb354e73 --- /dev/null +++ b/pkg/sqlite/migrations/68_image_studio_index.up.sql @@ -0,0 +1,7 @@ +-- with the existing index, if no images have a studio id, then the index is +-- not used when filtering by studio id. The assumption with this change is that +-- most images don't have a studio id, so filtering by non-null studio id should +-- be faster with this index. This is a tradeoff, as filtering by null studio id +-- will be slower. +DROP INDEX index_images_on_studio_id; +CREATE INDEX `index_images_on_studio_id` on `images` (`studio_id`) WHERE `studio_id` IS NOT NULL; \ No newline at end of file