Skip to content

Database Indexes

Controller (Postgres)

tasks_task

Column Index Notes
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 Add index Dispatcher agent check-in lookup (hot path)
dispatched_at Add index Time-range filtering in dashboards

skills_skill

Column Index Notes
slug Unique index URL routing, brief assembly lookups
organization_id Django FK index Tenant scoping
category Add index Category filtering in gallery

workflows_workflowinstance

Column Index Notes
status 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 Notes
workflow_instance_id + stage_id + attempt_number Unique together Composite lookup
task_id Django FK index Callback to stage execution resolution

Dispatcher (Postgres)

tasks

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

Recommendations

  1. Task.agent_key (Controller) -- Currently unindexed, queried on every agent check-in. Add db_index=True.
  2. WorkflowInstance.status -- List views filter by status. Add index.
  3. Task.dispatched_at -- Dashboard time-range queries. Add index.
  4. Dispatcher tasks (status, created_at) -- Composite index. Monitor pagination uses both columns.
  5. Skill.category -- Gallery view filters by category often enough to warrant an index.

Verifying query performance

Use EXPLAIN ANALYZE on hot-path queries to verify index usage:

EXPLAIN ANALYZE SELECT * FROM tasks_task WHERE agent_key = 'key-value';