Software Development · Manufacturing

Optimise a slow SQL query for Manufacturing

Use this when a page or report is slow because of a database query. Written for a manufacturing plant running shift-based production lines.

Your prompt is ready 4 brackets to fill
You are an expert in this kind of work, and you know the Manufacturing sector from the inside.

## Your task
This query is slow on a [DATABASE] database at a manufacturing plant running shift-based production lines. Table sizes: [ROW COUNTS]. Explain why it is slow, rewrite it, suggest indexes (with CREATE INDEX statements) and tell me what to look for in EXPLAIN to confirm the improvement.

## About my situation
- Who this is for: plant managers, line operators and procurement teams
- What we must respect: safety rules, ISO 9001 quality standards and fixed production schedules
- How we measure success: OEE and defect rate

## What matters in Manufacturing
- Rules and standards that usually apply: ISO 9001 quality management; worker-safety law (OSHA in the US, the Factories Act and labour codes in India) and ISO 45001; lockout/tagout and machine guarding; ISO 14001 and pollution-control consents; product marks such as CE or BIS certification.
- Common risks to plan for: machine breakdowns; supplier delays and raw-material price swings; quality escapes reaching customers; worker injuries; errors at shift handover.
- Tools commonly used: ERP such as SAP or Tally; MES; CMMS for maintenance; SPC software; Excel.
- Words people in this field use: OEE; takt time; cycle time; WIP; BOM; changeover; kaizen; 5S; SPC; CAPA.
- Rules differ by country. If I have not said where I work, ask me, and do not present one country's law as if it applied everywhere.

## What I will give you
Query:
[PASTE QUERY]
Schema:
[PASTE SCHEMA]

## How to work through it
1. Read the query and schema and explain how the database will execute it.
2. Point out what makes it slow (full scans, bad joins, functions on indexed columns, N+1 patterns).
3. Rewrite the query.
4. Suggest indexes with CREATE INDEX statements and their trade-offs.
5. Explain what to look for in EXPLAIN before and after.

## What to deliver
- Why it is slow
- The rewritten query
- Index statements
- EXPLAIN checklist
- Expected improvement

## Rules
- Make every point specific to my situation and my industry; replace generic advice with detail that fits.
- Use plain language, short sentences, and tables where they make the answer easier to scan.
- Use only the facts I give you. Do not invent figures, laws, sources or quotes. Mark anything you had to assume with "Assumption:".
- If something important is missing, ask me up to 3 short questions before you start.

## Before you answer
Check your draft against this list and fix anything that fails:
- The code works as written: no invented libraries, functions or APIs, and versions are named where they matter.
- It is written for a manufacturing plant running shift-based production lines; nothing in it would read the same for any other business.
- Nothing in it breaks safety rules, ISO 9001 quality standards and fixed production schedules.
- Every item under "What to deliver" is included.
Open in ChatGPT Claude Perplexity

How to use this prompt

  1. Copy the prompt. Press Copy prompt and the full text goes to your clipboard.
  2. Fill the brackets. Use the form above, or replace [DATABASE], [ROW COUNTS], [PASTE QUERY], [PASTE SCHEMA] with your own details.
  3. Paste and send. Paste it into ChatGPT, Claude and DeepSeek and send. Ask follow-up questions to refine the answer.

Why this prompt works

The “Optimise a slow SQL query” prompt tells the assistant exactly what to hand back: why it is slow; the rewritten query; index statements; EXPLAIN checklist; and expected improvement. It makes the assistant work through 5 steps in order, starting with "read the query and schema and explain how the database will execute it", instead of jumping straight to an answer. Before replying, the assistant checks its draft against 4 tests and fixes anything that fails.

This version is written for a manufacturing plant running shift-based production lines, so the assistant keeps safety rules, ISO 9001 quality standards and fixed production schedules in mind and judges the result by OEE and defect rate. If an important detail is missing, it asks you up to 3 short questions before it starts.

How to get the best answer

  1. Fill every bracket with real detail: [DATABASE], [ROW COUNTS], [PASTE QUERY] and the rest should hold real names, numbers and dates, not placeholders.
  2. Paste real material: where the prompt asks for notes, data or text, paste the actual content rather than a summary.
  3. Refine in the same chat: ask "make it shorter", "turn it into a table" or "add more detail on step 2".
  4. Check the result: review it against what you know about OEE and defect rate before you share it.

Other industries

Same prompt for other industries

The same optimise a slow sql query prompt, rewritten for each industry.

FAQ

Frequently asked questions

Which AI assistant works best with the “Optimise a slow SQL query” prompt?

The “Optimise a slow SQL query” prompt works in any chat assistant and suits ChatGPT, Claude and DeepSeek best. Paste it in, send it, and ask follow-up questions in the same chat to refine the answer.

What do I fill in before sending the “Optimise a slow SQL query” prompt?

Replace the 4 highlighted brackets – [DATABASE], [ROW COUNTS], [PASTE QUERY], [PASTE SCHEMA] – with your own details. The more specific you are, the better the answer.

Is the “Optimise a slow SQL query” prompt only for Manufacturing?

No. This version is written for a manufacturing plant running shift-based production lines, and the same prompt is also written for 15 other industries, listed on this page.

Is the “Optimise a slow SQL query” prompt free to use?

Yes. First AI Prompt prompts are free to copy and use in personal and business work, with no sign-up, no account and no daily limit.

Can I trust the answer the “Optimise a slow SQL query” prompt gives?

Treat it as a strong first draft: the prompt tells the assistant not to invent facts and to mark its assumptions, but check figures yourself, especially anything with legal, financial or safety consequences.

Keep exploring

Browse more Manufacturing prompts