オプション
家 Skill データベース管理 database-designer

専門的な分析と自動化ツールを活用して、データベーススキーマの設計、データ移行の計画、クエリの最適化、およびデータ関係のモデリングを行います。

...すべて拡張します
21
更新された時間 2026年8月29日

データベース設計者 - 高度な階層設計スキル

概要

最新のデータベースシステムに対して、専門家レベルの分析、最適化、移行機能を提供する包括的なデータベース設計スキルです。このスキルは、理論的な原則と実用的なツールを組み合わせることで、アーキテクトや開発者がスケーラブルで高性能、かつ保守性の高いデータベーススキーマを構築できるよう支援します。

中核となる能力

スキーマ設計と分析

  • 正規化分析:正規化レベル(1NF~BCNF)の自動検出
  • 非正規化戦略:パフォーマンス最適化のためのスマートな推奨事項
  • データ型の最適化:不適切なデータ型やサイズの問題の特定
  • 制約分析:外部キーの欠落、一意性制約、NULLチェックの欠落
  • 命名規則の検証:テーブルおよびカラムの命名パターンの一貫性確保
  • ERD生成:DDLからのMermaid図の自動作成

インデックスの最適化

  • インデックスギャップ分析:外部キーおよびクエリパターンに対するインデックスの欠落の特定
  • 複合インデックス戦略:複数カラムインデックスの最適なカラム順序
  • インデックスの冗長性の検出:重複するインデックスや未使用のインデックスの排除
  • パフォーマンス影響のモデリング:選択性の推定とクエリコストの分析
  • インデックス種類の選定:B-ツリー、ハッシュ、部分、カバリング、および特殊インデックス

移行管理

  • ダウンタイムゼロの移行:拡張・縮小パターンの実装
  • スキーマの進化:列の追加、削除、および型の変更を安全に行う
  • データ移行スクリプト:自動化されたデータ変換と検証
  • ロールバック戦略:検証機能を備えた完全な元に戻し機能
  • 実行計画:依存関係の解決を伴う順序付けられた移行手順

ツールのワークフロー(これらを実行してください。スキーマを手作業で分析しないでください)

すべてのパスはこのスキルフォルダを基準としています。サンプル入力は assets/.

1. スキーマを解析する

python3 schema_analyzer.py --input schema.sql --generate-erd --output-format json -o analysis.json

SQL DDL または JSON スキーマを受け付けます(assets/sample_schema.sql / sample_schema.json)。出力には、正規化の結果、欠落している制約、命名に関する問題、およびMermaid ERDが含まれます。最適化を行う前に、ユーザーにERDを表示し、フラグが立てられた問題を修正してください。

2. 実際のクエリパターンに基づいたインデックスの最適化

python3 index_optimizer.py --schema assets/sample_schema.json --queries assets/sample_query_patterns.json --analyze-existing --format json -o indexes.json

まず、ユーザーの頻繁に実行されるクエリをクエリパターンJSONに記述します( assets/sample_query_patterns.json)。出力には、優先順位順に並べられたCREATE INDEXの推奨リストと、冗長なインデックスの削除案が含まれます。

3. 移行プランを生成する

python3 migration_generator.py --current current_schema.json --target target_schema.json --zero-downtime --format sql -o migration.sql

--zero-downtime は展開・縮小プランを出力します。 --validate-only SQLを生成せずに実現可能性をチェックします。

4. 検証ループ

対象スキーマでステップ1を再実行し、初回実行で検出された問題が解消されていることを確認する; migration_generator.py --validate-only マイグレーションを引き渡す前に実行する。

データベース設計の原則

→ 詳細については、references/database-design-reference.md を参照してください

ベストプラクティス

スキーマ設計

  1. 意味のある名前を使用する:明確で一貫性のある命名規則
  2. 適切なデータ型を選択する:保存効率を考慮した適切なサイズのカラム
  3. 適切な制約を定義する:外部キー、チェック制約、一意インデックス
  4. 将来の拡張性を考慮する:最初からスケーラビリティを見込む
  5. 関係の文書化:明確な外部キーの関係とビジネスルール

パフォーマンスの最適化

  1. 戦略的なインデックス作成:過剰なインデックス作成を避けつつ、一般的なクエリパターンを網羅する
  2. クエリのパフォーマンスを監視する:遅いクエリを定期的に分析する
  3. 大規模なテーブルをパーティション分割する:クエリのパフォーマンスとメンテナンスを改善する
  4. 適切な隔離レベルを使用する:一貫性とパフォーマンスのバランスをとる
  5. 接続プールの実装:リソースの効率的な活用

セキュリティに関する考慮事項

  1. 最小権限の原則:必要最小限の権限のみを付与する
  2. 機密データの暗号化:保存時および転送時
  3. アクセスパターンの監査:データベースへのアクセスを監視し、ログを記録する
  4. 入力の検証:SQLインジェクション攻撃の防止
  5. 定期的なセキュリティ更新:データベースソフトウェアを最新の状態に保つ

クエリ生成パターン

JOIN を含む SELECT 文

-- INNER JOIN: only matching rows
SELECT o.id, c.name, o.total
FROM orders o
INNER JOIN customers c ON c.id = o.customer_id;

-- LEFT JOIN: all left rows, NULLs for non-matches
SELECT c.name, COUNT(o.id) AS order_count
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.name;

-- Self-join: hierarchical data (employees/managers)
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON m.id = e.manager_id;

共通テーブル式(CTE)

-- Recursive CTE for org chart
WITH RECURSIVE org AS (
  SELECT id, name, manager_id, 1 AS depth
  FROM employees WHERE manager_id IS NULL
  UNION ALL
  SELECT e.id, e.name, e.manager_id, o.depth + 1
  FROM employees e INNER JOIN org o ON o.id = e.manager_id
)
SELECT * FROM org ORDER BY depth, name;

ウィンドウ関数

-- ROW_NUMBER for pagination / dedup
SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY created_at DESC) AS rn
FROM orders;

-- RANK with gaps, DENSE_RANK without gaps
SELECT name, score, RANK() OVER (ORDER BY score DESC) AS rank FROM leaderboard;

-- LAG/LEAD for comparing adjacent rows
SELECT date, revenue,
  revenue - LAG(revenue) OVER (ORDER BY date) AS daily_change
FROM daily_sales;

集計パターン

-- FILTER clause (PostgreSQL) for conditional aggregation
SELECT
  COUNT(*) AS total,
  COUNT(*) FILTER (WHERE status = 'active') AS active,
  AVG(amount) FILTER (WHERE amount > 0) AS avg_positive
FROM accounts;

-- GROUPING SETS for multi-level rollups
SELECT region, product, SUM(revenue)
FROM sales
GROUP BY GROUPING SETS ((region, product), (region), ());

移行パターン

アップ/ダウン移行スクリプト

すべての移行には、元に戻せる対応する手順が必要です。順序付けのために、ファイル名にはタイムスタンプを接頭辞として付けます:

migrations/
├── 20260101_000001_create_users.up.sql
├── 20260101_000001_create_users.down.sql
├── 20260115_000002_add_users_email_index.up.sql
└── 20260115_000002_add_users_email_index.down.sql

ダウンタイムゼロのマイグレーション(拡張/縮小)

実行中のコードのロックや破損を避けるために、expand-contract パターンを使用します:

  1. 拡張 — 新しいカラム/テーブルを追加(NULL許可、デフォルト値あり)
  2. データの移行 — バッチ処理によるバックフィル;アプリケーションからの二重書き込み
  3. 移行 — アプリケーションは新しいカラムから読み取り、古いカラムへの書き込みを停止
  4. 縮小 — 後続のマイグレーションで古い列を削除

データのバックフィル戦略

-- Batch update to avoid long-running locks
UPDATE users SET email_normalized = LOWER(email)
WHERE id IN (SELECT id FROM users WHERE email_normalized IS NULL LIMIT 5000);
-- Repeat in a loop until 0 rows affected

ロールバック手順

  • 必ず down.sql 本番環境にデプロイする前に up.sql 本番環境にデプロイする
  • ロールバックの期間を短く保つ — 契約ステップが実行済みの場合、ロールバックには新たなフォワード・マイグレーションが必要となる
  • 元に戻せない変更(データを含むカラムの削除など)を行う場合は、まず論理バックアップを取得してください

パフォーマンスの最適化

インデックス戦略

インデックスの種類 ユースケース
B-tree (デフォルト) 等値、範囲、ORDER BY CREATE INDEX idx_users_email ON users(email);
GIN 全文検索、JSONB、配列 CREATE INDEX idx_docs_body ON docs USING gin(to_tsvector('english', body));
GiST Geometry、範囲型、最近傍検索 CREATE INDEX idx_locations ON places USING gist(coords);
部分一致 行の部分集合(サイズ縮小) CREATE INDEX idx_active ON users(email) WHERE active = true;
カバリング インデックスのみのスキャン CREATE INDEX idx_cov ON orders(customer_id) INCLUDE (total, created_at);

EXPLAIN プランの読み方

EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;

注目すべきキーのシグナル:

  • 大規模テーブルでのシーケンシャルスキャン — インデックスの欠如
  • 行数の推定値が高いネストループ — ハッシュ結合やマージ結合の検討、またはインデックスの追加を検討
  • バッファ共有の読み取り数がヒット数を大幅に上回る — ワーキングセットがメモリ容量を超過している

N+1クエリの検出

症状:アプリケーションが1行ごとに1つのクエリを発行している(例:ループ内で関連レコードを取得する場合)。

対策:

  • 1回のラウンドトリップで取得できるよう、 JOIN またはサブクエリを使用して、1回のラウンドトリップで取得する
  • ORMのイージーローディング(select_related / includes / with)
  • GraphQL リゾルバー向けの DataLoader パターン

接続プーリング

ツール プロトコル 最適な用途
PgBouncer PostgreSQL トランザクション/ステートメントのプーリング、オーバーヘッドが低い
ProxySQL MySQL クエリルーティング、読み取り/書き込みの分離
組み込みプール(HikariCP、SQLAlchemyプール) 任意 アプリケーションレベルのプール

経験則:プールサイズを (2 * CPU cores) + disk spindlesに設定する。クラウドSSDの場合は、 2 * vCPUs から始めて、調整してください。

読み取りレプリカとクエリのルーティング

  • すべての SELECT クエリをレプリカにルーティングし、書き込みはプライマリへ
  • レプリケーションの遅延を考慮する(非同期の場合は通常1秒未満、同期の場合は0秒)
  • pg_last_wal_replay_lsn() を使用して、重要なデータを読み取る前にラグを検出する

マルチデータベースの意思決定マトリックス

基準 PostgreSQL MySQL SQLite SQL Server
最適用途 複雑なクエリ、JSONB、拡張機能 Webアプリ、読み取り中心のワークロード 組み込み、開発・テスト、エッジ エンタープライズ向け .NET スタック
JSONのサポート 非常に優れている(JSONB + GIN) 良好(JSON 型) 最小限 良好 (OPENJSON)
レプリケーション ストリーミング、論理 グループレプリケーション、InnoDBクラスタ 該当なし Always On AG
ライセンス オープンソース(PostgreSQLライセンス) オープンソース(GPL)/商用 パブリックドメイン 商用
実用上の最大サイズ 数TB 数TB 約1 TB(シングルライター) 数TB

選択すべき場合:

  • PostgreSQL — 新規プロジェクトのデフォルトの選択肢。拡張性と標準準拠性が最も優れている
  • MySQL — 既存のMySQLエコシステム;読み込みが中心のシンプルなWebアプリケーション
  • SQLite — モバイルアプリ、CLIツール、単体テスト用データベース、IoT/エッジ
  • SQL Server — 企業ポリシーで指定されている場合;.NET/Azureとの深い統合

NoSQLに関する考慮事項

データベース モデル 使用場面
MongoDB ドキュメント スキーマの柔軟性、迅速なプロトタイピング、コンテンツ管理
Redis キー・バリュー/キャッシュ セッションストア、レート制限、リーダーボード、パブリッシュ/サブスクライブ
DynamoDB ワイドカラム サーバーレスなAWSアプリ、あらゆるスケールで1桁ミリ秒のレイテンシ

デフォルトではSQLを使用する。アクセスパターンがNoSQLの利点を明確に享受できる場合にのみ、NoSQLを採用する。

シャーディングとレプリケーション

水平パーティショニングと垂直パーティショニング

  • 垂直パーティショニング:列を複数のテーブルに分割する(例:BLOB列を分離)。狭い範囲のクエリにおけるI/Oを削減する。
  • 水平パーティショニング(シャーディング):行をデータベースやサーバー間で分割する。単一のノードではデータセットを保持できない場合や、スループットに対応できない場合に必要となる。

シャーディング戦略

戦略 仕組み メリット デメリット
ハッシュ shard = hash(key) % N 均等な分散 リシャーディングにはコストがかかる
範囲 日付またはIDの範囲ごとにシャーディング シンプルで、時系列データに適している 最新のシャードにホットスポットが発生する
地理 ユーザーの地域ごとのシャード分割 データの局所性、コンプライアンス リージョン間のクエリは難しい

レプリケーションパターン

パターン 一貫性 レイテンシ ユースケース
同期 強い 書き込みレイテンシが高い 金融取引
非同期 最終的には 書き込みレイテンシが低い 読み込みが中心のWebアプリ
半同期 少なくとも1つのレプリカが確認済み 中程度 安全性と速度のバランス

関連項目

  • sql-database-assistant — 日常的なSQL作業のためのクエリ作成、最適化、およびデバッグ
  • database-schema-designer — ERDモデリング、正規化分析、およびスキーマ生成
  • migration-architect — データベースエンジン間での大規模な移行計画や、スキーマの大幅な見直し
  • senior-backend — アプリケーション層のパターン(コネクションプーリング、ORMのベストプラクティス)
  • senior-devops — データベースクラスタおよびレプリカのインフラストラクチャのプロビジョニング
GitHubで見る
---
name: database-designer
description: Design database schemas, plan data migrations, optimize queries, and model data relationships using expert analysis and automated tools.
---

# Database Designer - POWERFUL Tier Skill

## Overview

A comprehensive database design skill that provides expert-level analysis, optimization, and migration capabilities for modern database systems. This skill combines theoretical principles with practical tools to help architects and developers create scalable, performant, and maintainable database schemas.

## Core Competencies

### Schema Design & Analysis
- **Normalization Analysis**: Automated detection of normalization levels (1NF through BCNF)
- **Denormalization Strategy**: Smart recommendations for performance optimization
- **Data Type Optimization**: Identification of inappropriate types and size issues
- **Constraint Analysis**: Missing foreign keys, unique constraints, and null checks
- **Naming Convention Validation**: Consistent table and column naming patterns
- **ERD Generation**: Automatic Mermaid diagram creation from DDL

### Index Optimization
- **Index Gap Analysis**: Identification of missing indexes on foreign keys and query patterns
- **Composite Index Strategy**: Optimal column ordering for multi-column indexes
- **Index Redundancy Detection**: Elimination of overlapping and unused indexes
- **Performance Impact Modeling**: Selectivity estimation and query cost analysis
- **Index Type Selection**: B-tree, hash, partial, covering, and specialized indexes

### Migration Management
- **Zero-Downtime Migrations**: Expand-contract pattern implementation
- **Schema Evolution**: Safe column additions, deletions, and type changes
- **Data Migration Scripts**: Automated data transformation and validation
- **Rollback Strategy**: Complete reversal capabilities with validation
- **Execution Planning**: Ordered migration steps with dependency resolution

## Tool Workflow (run these — do not analyze schemas by hand)

All paths relative to this skill folder; sample inputs in `assets/`.

### 1. Analyze the schema

```bash
python3 schema_analyzer.py --input schema.sql --generate-erd --output-format json -o analysis.json
```

Accepts SQL DDL or JSON schema (`assets/sample_schema.sql` / `sample_schema.json`). Output includes normalization findings, missing constraints, naming issues, and a Mermaid ERD — show the ERD to the user and fix flagged issues before optimizing.

### 2. Optimize indexes against real query patterns

```bash
python3 index_optimizer.py --schema assets/sample_schema.json --queries assets/sample_query_patterns.json --analyze-existing --format json -o indexes.json
```

Write the user's hot queries into a query-patterns JSON first (copy `assets/sample_query_patterns.json`). Output is a priority-ordered list of CREATE INDEX recommendations plus redundant-index removals.

### 3. Generate the migration

```bash
python3 migration_generator.py --current current_schema.json --target target_schema.json --zero-downtime --format sql -o migration.sql
```

`--zero-downtime` emits an expand-contract plan; `--validate-only` checks feasibility without generating SQL.

### 4. Verification loop

Re-run step 1 on the *target* schema and assert the issues found in the first pass are gone; run `migration_generator.py --validate-only` before handing over the migration.

## Database Design Principles
→ See references/database-design-reference.md for details

## Best Practices

### Schema Design
1. **Use meaningful names**: Clear, consistent naming conventions
2. **Choose appropriate data types**: Right-sized columns for storage efficiency
3. **Define proper constraints**: Foreign keys, check constraints, unique indexes
4. **Consider future growth**: Plan for scale from the beginning
5. **Document relationships**: Clear foreign key relationships and business rules

### Performance Optimization
1. **Index strategically**: Cover common query patterns without over-indexing
2. **Monitor query performance**: Regular analysis of slow queries
3. **Partition large tables**: Improve query performance and maintenance
4. **Use appropriate isolation levels**: Balance consistency with performance
5. **Implement connection pooling**: Efficient resource utilization

### Security Considerations
1. **Principle of least privilege**: Grant minimal necessary permissions
2. **Encrypt sensitive data**: At rest and in transit
3. **Audit access patterns**: Monitor and log database access
4. **Validate inputs**: Prevent SQL injection attacks
5. **Regular security updates**: Keep database software current

## Query Generation Patterns

### SELECT with JOINs

```sql
-- INNER JOIN: only matching rows
SELECT o.id, c.name, o.total
FROM orders o
INNER JOIN customers c ON c.id = o.customer_id;

-- LEFT JOIN: all left rows, NULLs for non-matches
SELECT c.name, COUNT(o.id) AS order_count
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.name;

-- Self-join: hierarchical data (employees/managers)
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON m.id = e.manager_id;
```

### Common Table Expressions (CTEs)

```sql
-- Recursive CTE for org chart
WITH RECURSIVE org AS (
  SELECT id, name, manager_id, 1 AS depth
  FROM employees WHERE manager_id IS NULL
  UNION ALL
  SELECT e.id, e.name, e.manager_id, o.depth + 1
  FROM employees e INNER JOIN org o ON o.id = e.manager_id
)
SELECT * FROM org ORDER BY depth, name;
```

### Window Functions

```sql
-- ROW_NUMBER for pagination / dedup
SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY created_at DESC) AS rn
FROM orders;

-- RANK with gaps, DENSE_RANK without gaps
SELECT name, score, RANK() OVER (ORDER BY score DESC) AS rank FROM leaderboard;

-- LAG/LEAD for comparing adjacent rows
SELECT date, revenue,
  revenue - LAG(revenue) OVER (ORDER BY date) AS daily_change
FROM daily_sales;
```

### Aggregation Patterns

```sql
-- FILTER clause (PostgreSQL) for conditional aggregation
SELECT
  COUNT(*) AS total,
  COUNT(*) FILTER (WHERE status = 'active') AS active,
  AVG(amount) FILTER (WHERE amount > 0) AS avg_positive
FROM accounts;

-- GROUPING SETS for multi-level rollups
SELECT region, product, SUM(revenue)
FROM sales
GROUP BY GROUPING SETS ((region, product), (region), ());
```

---

## Migration Patterns

### Up/Down Migration Scripts

Every migration must have a reversible counterpart. Name files with a timestamp prefix for ordering:

```
migrations/
├── 20260101_000001_create_users.up.sql
├── 20260101_000001_create_users.down.sql
├── 20260115_000002_add_users_email_index.up.sql
└── 20260115_000002_add_users_email_index.down.sql
```

### Zero-Downtime Migrations (Expand/Contract)

Use the expand-contract pattern to avoid locking or breaking running code:

1. **Expand** — add the new column/table (nullable, with default)
2. **Migrate data** — backfill in batches; dual-write from application
3. **Transition** — application reads from new column; stop writing to old
4. **Contract** — drop old column in a follow-up migration

### Data Backfill Strategies

```sql
-- Batch update to avoid long-running locks
UPDATE users SET email_normalized = LOWER(email)
WHERE id IN (SELECT id FROM users WHERE email_normalized IS NULL LIMIT 5000);
-- Repeat in a loop until 0 rows affected
```

### Rollback Procedures

- Always test the `down.sql` in staging before deploying `up.sql` to production
- Keep rollback window short — if the contract step has run, rollback requires a new forward migration
- For irreversible changes (dropping columns with data), take a logical backup first

---

## Performance Optimization

### Indexing Strategies

| Index Type | Use Case | Example |
|------------|----------|---------|
| **B-tree** (default) | Equality, range, ORDER BY | `CREATE INDEX idx_users_email ON users(email);` |
| **GIN** | Full-text search, JSONB, arrays | `CREATE INDEX idx_docs_body ON docs USING gin(to_tsvector('english', body));` |
| **GiST** | Geometry, range types, nearest-neighbor | `CREATE INDEX idx_locations ON places USING gist(coords);` |
| **Partial** | Subset of rows (reduce size) | `CREATE INDEX idx_active ON users(email) WHERE active = true;` |
| **Covering** | Index-only scans | `CREATE INDEX idx_cov ON orders(customer_id) INCLUDE (total, created_at);` |

### EXPLAIN Plan Reading

```sql
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;
```

Key signals to watch:
- **Seq Scan** on large tables — missing index
- **Nested Loop** with high row estimates — consider hash/merge join or add index
- **Buffers shared read** much higher than **hit** — working set exceeds memory

### N+1 Query Detection

Symptoms: application issues one query per row (e.g., fetching related records in a loop).

Fixes:
- Use `JOIN` or subquery to fetch in one round-trip
- ORM eager loading (`select_related` / `includes` / `with`)
- DataLoader pattern for GraphQL resolvers

### Connection Pooling

| Tool | Protocol | Best For |
|------|----------|----------|
| **PgBouncer** | PostgreSQL | Transaction/statement pooling, low overhead |
| **ProxySQL** | MySQL | Query routing, read/write splitting |
| **Built-in pool** (HikariCP, SQLAlchemy pool) | Any | Application-level pooling |

**Rule of thumb:** Set pool size to `(2 * CPU cores) + disk spindles`. For cloud SSDs, start with `2 * vCPUs` and tune.

### Read Replicas and Query Routing

- Route all `SELECT` queries to replicas; writes to primary
- Account for replication lag (typically <1s for async, 0 for sync)
- Use `pg_last_wal_replay_lsn()` to detect lag before reading critical data

---

## Multi-Database Decision Matrix

| Criteria | PostgreSQL | MySQL | SQLite | SQL Server |
|----------|-----------|-------|--------|------------|
| **Best for** | Complex queries, JSONB, extensions | Web apps, read-heavy workloads | Embedded, dev/test, edge | Enterprise .NET stacks |
| **JSON support** | Excellent (JSONB + GIN) | Good (JSON type) | Minimal | Good (OPENJSON) |
| **Replication** | Streaming, logical | Group replication, InnoDB cluster | N/A | Always On AG |
| **Licensing** | Open source (PostgreSQL License) | Open source (GPL) / commercial | Public domain | Commercial |
| **Max practical size** | Multi-TB | Multi-TB | ~1 TB (single-writer) | Multi-TB |

**When to choose:**
- **PostgreSQL** — default choice for new projects; best extensibility and standards compliance
- **MySQL** — existing MySQL ecosystem; simple read-heavy web applications
- **SQLite** — mobile apps, CLI tools, unit test databases, IoT/edge
- **SQL Server** — mandated by enterprise policy; deep .NET/Azure integration

### NoSQL Considerations

| Database | Model | Use When |
|----------|-------|----------|
| **MongoDB** | Document | Schema flexibility, rapid prototyping, content management |
| **Redis** | Key-value / cache | Session store, rate limiting, leaderboards, pub/sub |
| **DynamoDB** | Wide-column | Serverless AWS apps, single-digit-ms latency at any scale |

> Use SQL as default. Reach for NoSQL only when the access pattern clearly benefits from it.

---

## Sharding & Replication

### Horizontal vs Vertical Partitioning

- **Vertical partitioning**: Split columns across tables (e.g., separate BLOB columns). Reduces I/O for narrow queries.
- **Horizontal partitioning (sharding)**: Split rows across databases/servers. Required when a single node cannot hold the dataset or handle the throughput.

### Sharding Strategies

| Strategy | How It Works | Pros | Cons |
|----------|-------------|------|------|
| **Hash** | `shard = hash(key) % N` | Even distribution | Resharding is expensive |
| **Range** | Shard by date or ID range | Simple, good for time-series | Hot spots on latest shard |
| **Geographic** | Shard by user region | Data locality, compliance | Cross-region queries are hard |

### Replication Patterns

| Pattern | Consistency | Latency | Use Case |
|---------|------------|---------|----------|
| **Synchronous** | Strong | Higher write latency | Financial transactions |
| **Asynchronous** | Eventual | Low write latency | Read-heavy web apps |
| **Semi-synchronous** | At-least-one replica confirmed | Moderate | Balance of safety and speed |

---

## Cross-References

- **sql-database-assistant** — query writing, optimization, and debugging for day-to-day SQL work
- **database-schema-designer** — ERD modeling, normalization analysis, and schema generation
- **migration-architect** — large-scale migration planning across database engines or major schema overhauls
- **senior-backend** — application-layer patterns (connection pooling, ORM best practices)
- **senior-devops** — infrastructure provisioning for database clusters and replicas

すべてのファイル

0件のファイル

database-designerをインストール

スキルファイルをダウンロードし、.claude/skills/ ディレクトリに解凍してください。

ZIPをダウンロード

リポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。

git clone https://github.com/alirezarezvani/claude-skills/tree/main/engineering/skills/database-designer # Copy SKILL.md to your .claude/skills/ directory

コピー コピー
クイックセットアップ: スキルフォルダを .claude/skills/ にコピーしてください。 Claude が自動的にそのスキルを検出して使用します。

関連スキル

microservices-patterns
更新された時間 2026年6月29日
jpa-patterns
更新された時間 2026年6月30日
fabric-lakehouse
更新された時間 2026年6月30日
prisma-expert
更新された時間 2026年6月29日
OR