Implement database-level sorting with composite indexes for efficient date and tag queries. Add pagination metadata support and optimize tag count queries using batch processing.
16 lines
665 B
SQL
16 lines
665 B
SQL
-- Add composite indexes for search performance optimization
|
|
-- This migration addresses N+1 query issues and enables database-level sorting
|
|
|
|
-- Covering index for date-sorted queries (supports ORDER BY + pagination)
|
|
-- Enables efficient date-based sorting without loading all files into memory
|
|
CREATE INDEX IF NOT EXISTS idx_image_exif_date_path
|
|
ON image_exif(date_taken DESC, file_path);
|
|
|
|
-- Optimize batch tag count queries with GROUP BY
|
|
-- Reduces N individual queries to a single batch query
|
|
CREATE INDEX IF NOT EXISTS idx_tagged_photo_count
|
|
ON tagged_photo(photo_name, tag_id);
|
|
|
|
-- Update query planner statistics to optimize query execution
|
|
ANALYZE;
|