perf: optimise la query des auteurs — single pass + index GIN

- Remplace les 5 CTEs + double query (données + count) par une seule
  requête avec COUNT(*) OVER() pour le total
- Calcule book_count et series_count directement depuis UNNEST, sans
  re-JOIN sur les tables
- Ajoute des index GIN sur books.authors et series_metadata.authors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-27 10:20:48 +01:00
parent f5139b3598
commit 1af565bf29
2 changed files with 29 additions and 75 deletions

View File

@@ -0,0 +1,8 @@
-- GIN index for efficient array lookups on books.authors
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_books_authors_gin ON books USING GIN (authors);
-- Index on author column for legacy single-author field
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_books_author ON books (author) WHERE author IS NOT NULL AND author != '';
-- GIN index on series_metadata.authors
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_series_metadata_authors_gin ON series_metadata USING GIN (authors);