Prompt file imported from hanhn-dev/hrms (
.cursor/commands/improve-sql-performance.md). Fill in{{arguments}}before use. Copyright stays with the author.
Command: improve-sql-performance
Context
Business logic lives in SQL under d:\TDG HRMS DB\HRMS-DATABASE\<Database>\.
Read those scripts. Do not modify SQL in the database repository.
Do not create an Azure DevOps work item from the agent.
Output home (pending draft only):
d:\hrms\apps\backstage\content\azure\_work-item-drafts\<uuid>.json
A root admin reviews drafts at /azure/work-item-drafts and publishes to Azure
DevOps from Backstage. The agent only writes the draft file.
Task
Given an object name ({{arguments}}, or the text after /improve-sql-performance),
read its script, investigate performance, propose a rewrite, compare current vs
proposed, choose a concrete solution, and write one pending draft work item whose
description contains the full investigation for database developers.
If the name is empty, stop and ask for one. Do not execute the object.
Database slugs
Map the HRMS-DATABASE folder to the slug used by content/wiki/baseline-*.md:
| Folder | Slug |
|---|---|
HRMS |
hrms |
HRMS-TRAINING |
hrms-training |
HRMS-SURVEY |
hrms-survey |
HRMS_TRAVELNEXPENSE |
hrms-travelnexpense |
HRMS-RESOURCEALLOCATION |
hrms-resourceallocation |
HRM-TIMEPORT |
hrm-timeport |
HRMS-CRBBOOKING |
hrms-crbbooking |
HRMS-TranslationService |
hrms-translationservice |
HRMS-RewardNRecognition |
hrms-rewardnrecognition |
HRM-VMS |
hrm-vms |
If the same object name exists in more than one database, stop and ask which one.
If {{arguments}} includes a second token that matches a slug, use that database.
Steps
-
Resolve the script. Search that database for the object name:
- Procedures:
STOREPROCEDURE/andStored Procedures/ - Functions:
FUNCTIONS/ - Views:
VIEWS/andViews/Prefer thesqlFilepath on the newest matching changeSet inchangelog/baseline-inventory-storeprocedure.xml,changelog/baseline-inventory-stored-procedures.xml,changelog/baseline-inventory-functions.xml, orchangelog/baseline-inventory-views.xmlwhen present. If it is not inventoried, use the copy whose parent folder isSTOREPROCEDURE,Stored Procedures,FUNCTIONS,VIEWS, orViews. Skip a numeric work-item folder such as172636_173535.
- Procedures:
-
Pending-draft collision. List
apps/backstage/content/azure/_work-item-drafts/*.json. If any draft withstatus: "pending"already has the samedatabaseSlug+objectName, stop and ask whether to replace it. On replace, delete or mark that draftrejectedwith reasonsuperseded, then continue. Do not write a second pending draft for the same object. -
Investigate (required order). Work from the script only. Audience: database developers. Tie every claim to the script; call out assumptions.
Analyze for: non-SARGable predicates,
SELECT *, cursors, nested loops / RBAR, temp table vs table-variable misuse, implicit conversions, lock-hint abuse, unbounded result sets, redundant joins/subqueries, missing-index suggestions only (no liveSET STATISTICSunless the user asks).Produce content in this order — all of it goes into the draft
description:- Findings / performance issues (severity + script evidence)
- Bad practices
- Proposed rewrite (SQL in fenced blocks — full object when practical, else each changed hot path). Preserve parameters and behavior unless an intentional contract change is called out.
- Comparison: current vs proposed — what differs, expected benefit, risks / trade-offs. Do this before locking one recommendation.
- Concrete solution — the chosen change set after comparison (not a vague “consider indexing”)
- Risks and behavior parity
- Reference (object, database slug, source path)
-
Write the draft JSON. Create a new UUID file under
apps/backstage/content/azure/_work-item-drafts/<uuid>.jsonwith:-
id: the UUID -
status:"pending" -
createdAt/updatedAt: ISO-8601 with offset -
objectName,objectType(procedure|view|function),databaseSlug,sourcePath(absolute or repo-relative path to the SQL) -
title:SQL performance: <ObjectName> (<database-slug>) -
type:"Product Backlog Item" -
description: markdown using exactly these H2 headings, in order:## Summary ## Investigation — performance issues ## Investigation — bad practices ## Proposed rewrite ## Comparison (current vs proposed) ## Concrete solution ## Risks and behavior parity ## Reference -
acceptanceCriteria: verification checklist for a DB developer (parity checks, expected plan shape notes, regression notes) — plain text or markdown list; maps to ADO Acceptance Criteria on publish -
tags: includesql-performanceand the object type (procedure/view/function) -
Optional:
currentSqlExcerpt,proposedSqlExcerpt(also present insidedescriptionso ADO has the full story) -
Leave
assignedTo,areaPath,iterationPathunset so Backstage publish usesCREATE_WORK_ITEM_DEFAULTS -
Optional:
priority(1–4),parentIdonly if the user asked
-
-
Report back. Tell the user the draft id, object, title, and that they review/publish at
/azure/work-item-drafts. Do not callaz_create_work_itemor any other ADO create API.
Hard rules
- Never create the Azure DevOps work item from this command.
- Never modify the SQL source files as part of this command.
- Never skip the propose → compare → concrete solution sequence.
- Never invent runtime metrics you did not measure; mark estimates as estimates.
