Public Assistance Casework Backlog SQL Refactoring Brief
Diagnose query bottlenecks and refactor operational SQL for public social services case queues and statutory processing SLA tracking.
Use this template when municipal social service application processing dashboards experience query degradation. It delivers a performance-tuning brief and refactored SQL to monitor case backlogs within regulatory deadlines.
Role: Senior Civic Systems Database Performance Engineer specializing in high-concurrency public welfare casework queues.
Context
- Database Engine & Version: {{database_engine_version}}
- Casework Queue Schema: {{casework_table_schema}}
- Statutory Processing SLA: {{sla_threshold_hours}}
- Underperforming Production Query: {{current_slow_query}}
- Storage & Index Constraints: {{indexing_constraints}}
Task
Deliver an operational SQL performance refactoring brief that identifies execution plan bottlenecks in {{current_slow_query}}, optimizes index usage under {{indexing_constraints}}, and outputs high-efficiency SQL for tracking case eligibility queues against {{sla_threshold_hours}}.
Method
- Analyze execution characteristics and bottleneck operators within {{current_slow_query}}.
- Inspect table joins across {{casework_table_schema}} to replace correlated subqueries with optimized join predicates or window constructs.
- Implement explicit timestamp filtering to calculate pending turnaround times against {{sla_threshold_hours}}.
- Design indexed CTE structures that prune closed or resolved cases before evaluating backlog aging.
- Optimize grouping and aggregation sets to reduce memory consumption during queue sorting.
- Formulate covering index and partial index recommendations tailored to {{database_engine_version}}.
- Test query plan predictability to avoid full table scans across historical case archives.
- Document the pre- and post-optimization logical complexity and expected reduction in I/O operations.
Constraints
- MUST NOT alter underlying casework business logic or omit pending citizen applications.
- MUST formulate all index recommendations within the boundaries of {{indexing_constraints}}.
- The refactored SQL must maintain deterministic ordering for caseworker priority queues.
- Explicit query hints must be avoided unless required to prevent plan regression on {{database_engine_version}}.
- All timestamp differential arithmetic must account for time zone offsets and business hours if specified in schema.
Output format
Provide a technical brief structured as follows:
- Execution Plan Diagnostic & Root Cause Analysis (max 250 words)
- Refactored Production SQL Script (fully commented code block)
- Indexing & Physical Design Recommendations (DDL code block and justification)
- Verification & Load-Testing Protocol (step-by-step validation guide, max 200 words)
Self-review
- Ensure the refactored script strictly enforces the {{sla_threshold_hours}} deadline threshold.
- Validate that all proposed indexes respect limitations defined in {{indexing_constraints}}.
- Verify that query syntax matches the syntax rules of {{database_engine_version}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.