Files
pgsql-jellyfin/scripts/sql/indexes/add_presentationuniquekey_index.sql
wjones 1abf61a05f Add PostgresSubprocessException and refactor database initialization logic
- Introduced PostgresSubprocessException to handle errors during PostgreSQL subprocess execution.
- Refactored PostgresDatabaseProvider to improve schema initialization script discovery.
- Enhanced error handling for psql command execution, including logging of output and errors.
- Implemented methods to find the schema initialization script and the psql executable path.
2026-07-08 11:53:36 -04:00

24 lines
911 B
SQL

-- PostgreSQL Performance Fix for Episode Queries
-- Run this script to add the missing index for PresentationUniqueKey
-- This will significantly speed up episode deduplication queries
\pset pager off
-- Create the index (CONCURRENTLY means it won't lock the table during creation)
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_baseitems_presentationuniquekey_episodes
ON library."BaseItems" ("PresentationUniqueKey", "TopParentId", "IsVirtualItem")
WHERE "Type" = 'MediaBrowser.Controller.Entities.TV.Episode' AND "PresentationUniqueKey" IS NOT NULL;
-- Verify the index was created
SELECT
schemaname,
tablename,
indexname,
indexdef
FROM pg_indexes
WHERE schemaname = 'library'
AND indexname = 'idx_baseitems_presentationuniquekey_episodes';
-- Check index size
SELECT
pg_size_pretty(pg_relation_size('library.idx_baseitems_presentationuniquekey_episodes'::regclass)) AS index_size;