perf: optimize reconciliation candidate lookup

This commit is contained in:
plx
2026-08-14 12:56:03 +00:00
parent 89017f71a6
commit 07dc9db198
8 changed files with 373 additions and 31 deletions

View File

@@ -0,0 +1,21 @@
-- Structured lookup paths used by opportunity-detail reconciliation candidates.
-- Existing opportunity, NIF and source/external indexes are intentionally reused.
CREATE INDEX IF NOT EXISTS idx_reconciliation_customer_id
ON reconciliation_items(customer_id)
WHERE customer_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_reconciliation_customer_email_lower
ON reconciliation_items(lower(customer_email))
WHERE customer_email IS NOT NULL AND customer_email <> '';
CREATE INDEX IF NOT EXISTS idx_reconciliation_customer_name_lower
ON reconciliation_items(lower(customer_name))
WHERE customer_name IS NOT NULL AND customer_name <> '';
CREATE INDEX IF NOT EXISTS idx_commercial_documents_opportunity_number
ON commercial_documents(opportunity_id, document_number)
WHERE document_number IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_commercial_documents_opportunity_external
ON commercial_documents(opportunity_id, external_id)
WHERE external_id IS NOT NULL;