perf: add GIN indexes for pg_trgm fuzzy search optimization
Add GIN indexes with gin_trgm_ops for text fields used in fuzzy search: - author, title, series, genre, language fields These indexes significantly improve performance of word_similarity() queries used in the unified search implementation. pg_trgm extension must already be enabled for these indexes to function. Performance impact: O(n) sequential scans become O(log n) index scans for fuzzy text search operations.
This commit is contained in:
@@ -145,6 +145,18 @@ ALTER TABLE media_items ADD COLUMN IF NOT EXISTS contributors_search TEXT[];
|
|||||||
CREATE INDEX IF NOT EXISTS idx_media_items_tags_search ON media_items USING GIN (tags_search);
|
CREATE INDEX IF NOT EXISTS idx_media_items_tags_search ON media_items USING GIN (tags_search);
|
||||||
CREATE INDEX IF NOT EXISTS idx_media_items_contributors_search ON media_items USING GIN (contributors_search);
|
CREATE INDEX IF NOT EXISTS idx_media_items_contributors_search ON media_items USING GIN (contributors_search);
|
||||||
|
|
||||||
|
-- Add GIN indexes for pg_trgm fuzzy search performance
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_media_items_author_trgm
|
||||||
|
ON media_items USING GIN (author gin_trgm_ops);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_media_items_title_trgm
|
||||||
|
ON media_items USING GIN (title gin_trgm_ops);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_media_items_series_trgm
|
||||||
|
ON media_items USING GIN (series gin_trgm_ops);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_media_items_genre_trgm
|
||||||
|
ON media_items USING GIN (genre gin_trgm_ops);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_media_items_language_trgm
|
||||||
|
ON media_items USING GIN (language gin_trgm_ops);
|
||||||
|
|
||||||
-- Create reading_progress table
|
-- Create reading_progress table
|
||||||
CREATE TABLE IF NOT EXISTS reading_progress (
|
CREATE TABLE IF NOT EXISTS reading_progress (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
|||||||
Reference in New Issue
Block a user