SQL
AuraScore 81/100

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.

Template

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

  1. Analyze execution characteristics and bottleneck operators within {{current_slow_query}}.
  2. Inspect table joins across {{casework_table_schema}} to replace correlated subqueries with optimized join predicates or window constructs.
  3. Implement explicit timestamp filtering to calculate pending turnaround times against {{sla_threshold_hours}}.
  4. Design indexed CTE structures that prune closed or resolved cases before evaluating backlog aging.
  5. Optimize grouping and aggregation sets to reduce memory consumption during queue sorting.
  6. Formulate covering index and partial index recommendations tailored to {{database_engine_version}}.
  7. Test query plan predictability to avoid full table scans across historical case archives.
  8. 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:

  1. Execution Plan Diagnostic & Root Cause Analysis (max 250 words)
  2. Refactored Production SQL Script (fully commented code block)
  3. Indexing & Physical Design Recommendations (DDL code block and justification)
  4. 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}}.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

data-analytics
data-sql
public-sector-nonprofit
sql
performance-tuning
civic-tech