You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance index management in SQL ingestion scripts for improved performance
- Added new indexes on the `notes`, `note_comments`, and `note_comment_texts` tables to optimize query performance for monitoring and analytics.
- Removed redundant indexes to streamline database operations, ensuring that existing primary keys and spatial indexes are utilized effectively.
- Introduced partial indexes for recent updates and quality checks to enhance data retrieval efficiency for specific use cases.
- Updated comments to clarify the benefits and usage of each index, improving maintainability and understanding of the database schema.
-- Benefits: Monitoring (covering index includes all columns needed for common queries, avoids table access)
92
+
-- Used by: Common monitoring queries that need status, time, duration, and notes_processed without accessing table
44
93
CREATEINDEXIF NOT EXISTS idx_processing_log_covering
45
94
ON processing_log(status, execution_time DESC, duration_seconds, notes_processed);
46
95
END IF;
47
96
END $$;
48
97
49
98
-- Hash index for duplicate detection (if needed)
99
+
-- Index: idx_notes_note_id_hash (note_id) - HASH
100
+
-- Benefits: Monitoring (duplicate detection), Ingestion (quick note_id existence checks, though PK already exists)
101
+
-- Used by: Duplicate detection queries, fast note_id lookups (though PK already provides this)
50
102
CREATEINDEXIF NOT EXISTS idx_notes_note_id_hash ON notes USING HASH(note_id);
51
103
52
104
-- Partial index for quality checks
105
+
-- Index: idx_notes_quality_check (id) - Partial Index
106
+
-- Benefits: Monitoring (data_quality.sql - identifies notes with data quality issues)
107
+
-- Used by: Quickly finding notes with missing coordinates or inconsistent timestamps (latitude IS NULL OR longitude IS NULL OR updated_at < created_at)
53
108
CREATEINDEXIF NOT EXISTS idx_notes_quality_check
54
109
ON notes(id)
55
110
WHERE latitude IS NULLOR longitude IS NULLOR updated_at < created_at;
0 commit comments