SQL Query Optimization

SQL Query Optimization

Analyzes and rewrites slow SQL queries in PostgreSQL and MySQL using EXPLAIN plans, indexing and batching techniques.

Skill files7 files

references/

scripts/

templates/

SKILL.md76 lines
1
---
2
name: sql-query-optimization
3
description: >
4
Analyze and optimize SQL queries for performance. Use when improving slow
5
queries, reducing execution time, or analyzing query performance in PostgreSQL
6
and MySQL.
7
---
8
9
# SQL Query Optimization
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Analyze SQL queries to identify performance bottlenecks and implement optimization techniques. Includes query analysis, indexing strategies, and rewriting patterns for improved performance.
22
23
## When to Use
24
25
- Slow query analysis and tuning
26
- Query rewriting and refactoring
27
- Index utilization verification
28
- Join optimization
29
- Subquery optimization
30
- Query plan analysis (EXPLAIN)
31
- Performance baseline establishment
32
33
## Quick Start
34
35
**PostgreSQL:**
36
37
```sql
38
-- Analyze query plan with execution time
39
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
40
SELECT u.id, u.email, COUNT(o.id) as order_count
41
FROM users u
42
LEFT JOIN orders o ON u.id = o.user_id
43
WHERE u.created_at > NOW() - INTERVAL '1 year'
44
GROUP BY u.id, u.email;
45
46
-- Check table statistics
47
SELECT * FROM pg_stats
48
WHERE tablename = 'users' AND attname = 'created_at';
49
```
50
51
## Reference Guides
52
53
Detailed implementations in the `references/` directory:
54
55
| Guide | Contents |
56
|---|---|
57
| [Analyze Current Performance](references/analyze-current-performance.md) | Analyze Current Performance |
58
| [Common Optimization Patterns](references/common-optimization-patterns.md) | Common Optimization Patterns |
59
| [Query Rewriting Techniques](references/query-rewriting-techniques.md) | Query Rewriting Techniques |
60
| [Batch Operations](references/batch-operations.md) | Batch Operations |
61
62
## Best Practices
63
64
### ✅ DO
65
66
- Follow established patterns and conventions
67
- Write clean, maintainable code
68
- Add appropriate documentation
69
- Test thoroughly before deploying
70
71
### ❌ DON'T
72
73
- Skip testing or validation
74
- Ignore error handling
75
- Hard-code configuration values
76

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…