Database Query Optimization

Database Query Optimization

Improves database query performance through indexing strategy, execution plan analysis and query optimization techniques.

Skill files7 files

references/

scripts/

templates/

SKILL.md82 lines
1
---
2
name: database-query-optimization
3
description: >
4
Improve database query performance through indexing, query optimization, and
5
execution plan analysis. Reduce response times and database load.
6
---
7
8
# Database Query Optimization
9
10
## Table of Contents
11
12
- [Overview](#overview)
13
- [When to Use](#when-to-use)
14
- [Quick Start](#quick-start)
15
- [Reference Guides](#reference-guides)
16
- [Best Practices](#best-practices)
17
18
## Overview
19
20
Slow database queries are a common performance bottleneck. Optimization through indexing, efficient queries, and caching dramatically improves application performance.
21
22
## When to Use
23
24
- Slow response times
25
- High database CPU usage
26
- Performance regression
27
- New feature deployment
28
- Regular maintenance
29
30
## Quick Start
31
32
Minimal working example:
33
34
```sql
35
-- Analyze query performance
36
37
EXPLAIN ANALYZE
38
SELECT users.id, users.name, COUNT(orders.id) as order_count
39
FROM users
40
LEFT JOIN orders ON users.id = orders.user_id
41
WHERE users.created_at > '2024-01-01'
42
GROUP BY users.id, users.name
43
ORDER BY order_count DESC;
44
45
-- Results show:
46
-- - Seq Scan (slow) vs Index Scan (fast)
47
-- - Rows: actual vs planned (high variance = bad)
48
-- - Execution time (milliseconds)
49
50
-- Key metrics:
51
-- - Sequential Scan: Full table read (slow)
52
-- - Index Scan: Uses index (fast)
53
-- - Nested Loop: Joins with loops
54
-- - Sort: In-memory or disk sort
55
```
56
57
## Reference Guides
58
59
Detailed implementations in the `references/` directory:
60
61
| Guide | Contents |
62
|---|---|
63
| [Query Analysis](references/query-analysis.md) | Query Analysis |
64
| [Indexing Strategy](references/indexing-strategy.md) | Indexing Strategy |
65
| [Query Optimization Techniques](references/query-optimization-techniques.md) | Query Optimization Techniques |
66
| [Optimization Checklist](references/optimization-checklist.md) | Optimization Checklist |
67
68
## Best Practices
69
70
### ✅ DO
71
72
- Follow established patterns and conventions
73
- Write clean, maintainable code
74
- Add appropriate documentation
75
- Test thoroughly before deploying
76
77
### ❌ DON'T
78
79
- Skip testing or validation
80
- Ignore error handling
81
- Hard-code configuration values
82

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

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,410 prompts

More by @OpenSourceBuffGuy

See all
Cornflower meadow path to a misty sailboat prompt image

Cornflower meadow path to a misty sailboat

Draws a portrait-format colored-pencil scene of a cornflower meadow with a winding path leading to a misty sea, a distant sailboat and a sunset sky.

image-prompt, illustration, landscape, flowers, ocean, dreamy, pastel, golden-hour, vertical-format, nano-banana, sketch, summer, for-artists, wallpaper, soft-lighting, wide-shot, high-angle

Swordswoman faces colossal robed figure in industrial yard prompt image

Swordswoman faces colossal robed figure in industrial yard

Writes a two-scene, 20-second live-action video prompt in which a swordswoman freezes a colossal figure with realistic ice and shatters him with a finishing slash.

video-prompt, seedance, action, martial-arts, visual-effects, multi-shot, cinematic, character-consistency, timed-beats, negative-prompt, guardrails, structured-output, photorealistic, fantasy-world, japan, camera-movement, slow-motion, blue-hour, widescreen, advanced, long-form, for-filmmakers, sound-effects, creatures, warriors

Overhead portrait of a girl lying in snow prompt image

Overhead portrait of a girl lying in snow

Creates an overhead portrait of a girl in a school blazer lying in fresh snow, using a JSON spec that keeps the reference face and sets camera, outfit and soft overcast light.

image-prompt, json-prompt, nano-banana, reference-image, face-reference, negative-prompt, photorealistic, portrait, woman, close-up, high-angle, winter, soft-lighting, natural-light, bokeh, moody, editorial, vertical-format, muted-colors, limited-palette, film-grain, cinematic, structured-output, for-photographers, for-artists

Reviews

Loading reviews…

Discussion

Loading comments…