-- Standalone updated_at DESC indexes for ORDER BY without temp B-tree sort.
-- The existing composite indexes (project_id, updated_at) only help when
-- filtering by project first.
CREATE INDEX IF NOT EXISTS idx_issues_updated_at_desc
    ON issues(updated_at DESC);

CREATE INDEX IF NOT EXISTS idx_mrs_updated_at_desc
    ON merge_requests(updated_at DESC);

-- Covering index for correlated subquery: unresolved discussion count per issue.
-- MRs already have idx_discussions_mr_resolved (migration 006).
CREATE INDEX IF NOT EXISTS idx_discussions_issue_resolved
    ON discussions(issue_id, resolvable, resolved);

INSERT INTO schema_version (version, applied_at, description)
VALUES (19, strftime('%s', 'now') * 1000, 'List performance indexes');
