Skip to content

Database Index Audit

Controller (Postgres)

tasks_task

Column Index Exists Reason
status Django default Filtered in every list view, monitor queries
created_at Django default (ordering) ORDER BY in list views, time-range queries
dispatcher_id Django FK index JOIN for dispatcher dashboard
project_id Django FK index Tenant scoping
guid Unique index External identifier lookups
slug Unique index URL routing
agent_key MISSING — add index Dispatcher agent check-in lookup (hot path)
dispatched_at MISSING — add index Time-range filtering in dashboards

skills_skill

Column Index Exists Reason
slug Unique index URL routing, brief assembly lookups
organization_id Django FK index Tenant scoping
category MISSING — add index Category filtering in gallery

workflows_workflowinstance

Column Index Exists Reason
status MISSING — add index Instance list filtering
template_id Django FK index Template-scoped queries
temporal_workflow_id Unique index Signal routing
project_id Django FK index Tenant scoping

workflows_workflowstageexecution

Column Index Exists Reason
workflow_instance_id + stage_id + attempt_number Unique together Composite lookup
task_id Django FK index Callback → stage execution resolution

Dispatcher (Postgres)

tasks

Column Index Exists Reason
task_id Unique index All task lookups
agent_key Should have index Agent check-in (hot path)
status Should have index Monitor active task scan, list queries
created_at Should have index Pagination cursor

Recommendations

  1. Add db_index=True to Task.agent_key (Controller) — currently unindexed, queried on every agent check-in
  2. Add index on WorkflowInstance.status — list views filter by status
  3. Add index on Task.dispatched_at — dashboard time-range queries
  4. Add composite index on tasks (status, created_at) in Dispatcher — monitor pagination uses both
  5. Skill.category gets enough queries in gallery view to warrant an index