Skip to content

chore: Align DocType indexes with their queries - #45

Merged
s-aga-r merged 1 commit into
developfrom
chore/doctype-indexes
Oct 28, 2026
Merged

s-aga-r merged 1 commit into
developfrom
chore/doctype-indexes

Conversation

@s-aga-r

@s-aga-r s-aga-r commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Drop unique indexes on fields that a DocType is named by (Region, DNS Zone, Mail Domain, Mail Account, Mail Group, Mailing List, Stalwart Cluster, Stalwart Node, Egress Gateway). They copy the primary key, and no query filters on them.
  • Replace single-column indexes with the composites their queries use: DNS Record (dns_zone, host), DMARC and TLS Report (tenant, date_range_end), Tenant Email (tenant, sent_at). Drop the unused DMARC Report Record source_ip index.
  • Index Suite Site by (region, status) and status. The pool claim (FOR UPDATE SKIP LOCKED) then locks only its region's ready sites, and the site crons do not scan the table.
  • Index Suite Tenant Request tenant and status, and Telemetry Alert status and (host_ip, alert_type), for the signup, expiry, resume and alert lookups.
  • Add a unique (dns_zone, label) constraint to Stalwart Cluster. Validation already enforced this rule; the database now enforces it too.

Test plan

  • migrate ran clean, and SHOW INDEX gives the expected layout on each changed table.
  • New suite_cloud/tests/test_indexes.py checks the expected indexes and that name fields have no second index.
  • run-tests --app suite_cloud: all 468 tests pass.
  • ruff check and ruff format --check pass.

Drop unique indexes on fields that DocTypes are named by, since they copy the primary key. Replace single-column indexes on DNS Record, DMARC Report, TLS Report and Tenant Email with the composites their queries filter and sort on, and drop the unused DMARC Report Record source_ip index.

Index Suite Site by region and status so the pool claim locks only its region's ready sites, and index the status and tenant lookups that the signup and alert crons scan. Enforce a unique cluster label per DNS zone in the database as well as in validation.
@s-aga-r
s-aga-r merged commit 4b51687 into develop Oct 28, 2026
12 of 13 checks passed
@s-aga-r
s-aga-r deleted the chore/doctype-indexes branch October 28, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant