Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use this skill when designing database schemas, choosing between SQL and NoSQL, optimizing queries, designing indexes, modeling relationships, working with vector databases, or planning data migrations. Trigger on keywords: database, schema, SQL, NoSQL, index, query optimization, data model, migration, ORM, PostgreSQL, MongoDB, Redis, vector database, N+1.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-21 | ✗→✓ | ▲ Improved | 62% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 20% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 6% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 13% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 23% | 0% |
user_id not uid, created_at not tscreated_at, updated_atdeleted_at instead of hard deleting rows you might need to recover| Relationship | Implementation | |---|---| | One-to-One | Foreign key on either table + UNIQUE constraint | | One-to-Many | Foreign key on the "many" side | | Many-to-Many | Junction/pivot table with two foreign keys |
Rule: Index columns you filter, sort, or join on frequently.
sql-- Index for common query patterns CREATE INDEX idx_orders_user_status ON orders(user_id, status); CREATE INDEX idx_posts_created ON posts(created_at DESC); -- Partial index for active records only CREATE INDEX idx_active_users ON users(email) WHERE deleted_at IS NULL;
typescript// BAD — N+1: 1 query for posts + N queries for each author const posts = await Post.findAll() for (const post of posts) { const author = await User.findById(post.userId) // N queries! } // GOOD — 2 queries total using JOIN or eager loading const posts = await Post.findAll({ include: [{ model: User }] })
sql-- Offset pagination (simple but slow for large offsets) SELECT * FROM posts ORDER BY created_at DESC LIMIT 20 OFFSET 100; -- Cursor pagination (fast for large datasets) SELECT * FROM posts WHERE created_at < :cursor ORDER BY created_at DESC LIMIT 20;
Use cursor pagination for large tables or infinite scroll.
| SQL | NoSQL | |---|---| | ACID transactions | High write throughput | | Complex queries, joins | Flexible/variable schema | | Data integrity critical | Horizontal scale priority | | Well-defined schema | Unstructured or nested data | | PostgreSQL, MySQL | MongoDB, DynamoDB, Cassandra |
Hybrid: Use SQL as the source of truth, Redis for caching, Elasticsearch for search.
For semantic search, RAG, and embeddings:
| DB | Best For | |---|---| | pgvector | Existing PostgreSQL stack | | Pinecone | Managed, production-scale | | Weaviate | Multi-modal, hybrid search | | Chroma | Local dev and prototyping |
NOT NULL DEFAULT carefully, add constraints after backfill| Use Case | Pattern | |---|---| | Session storage | Key: session:{id}, TTL | | Rate limiting | Increment counter with TTL | | Caching | Key: cache:{resource}:{id}, TTL | | Pub/Sub | Real-time events between services | | Job queue | List with LPUSH/BRPOP | | Leaderboard | Sorted Set (ZADD/ZRANGE) |
Other measured skills in the registry, with their headline benchmark lift.