-- Stonks Oracle - Dedupe support indexes

-- Index on canonical_url for cross-source deduplication lookups.
-- The dedupe module queries documents by canonical_url to detect
-- the same article ingested from different source types.
CREATE INDEX idx_documents_canonical_url ON documents(canonical_url)
    WHERE canonical_url IS NOT NULL;

-- Unique constraint on document_company_mentions to prevent duplicate
-- company links when cross-source dedupe links an existing document
-- to an additional company.
CREATE UNIQUE INDEX idx_doc_mentions_unique
    ON document_company_mentions(document_id, company_id);
