d1-optimizer

Analyze D1/SQLite query plans and recommend indexes for Cloudflare edge deployments.

Updated Mar 28, 2026
One-click install
npx skills add https://github.com/cffrank/paperclip-skills-agents --skill d1-optimizer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: d1-optimizer
Source: https://github.com/cffrank/paperclip-skills-agents/tree/main/skills/d1-optimizer
Command: npx skills add https://github.com/cffrank/paperclip-skills-agents --skill d1-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

D1 is SQLite at the edge and imposes constraints distinct from traditional PostgreSQL, including a serialized-writes model and limited extensions. This skill helps diagnose slow edge queries by providing structured guidance on query plans, indexing strategies, and batch-write patterns to improve performance on Cloudflare's D1.

Core Features & Use Cases

  • EXPLAIN QUERY PLAN analysis to identify bottlenecks and index usage.
  • Index strategy recommendations tailored to D1's constraints, including composite and partial indexes.
  • N+1 query elimination through joins and batch-fetch patterns.
  • Batch write optimization to reduce round-trips and ensure atomicity with D1.
  • Read replica patterns to route reads to replicas while directing writes to primary.
  • Guidance on common anti-patterns and FTS considerations for efficient data access.

Quick Start

Run a diagnostic against a sample D1 schema to get explain plans and index recommendations.

Frequently Asked Questions about d1-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow SQLite queries on Cloudflare D1?▼

To optimize slow SQLite queries on Cloudflare D1, analyze EXPLAIN QUERY PLAN output to identify bottlenecks, apply tailored composite or partial indexes, and eliminate N+1 queries using batch-fetch patterns.

What is the best way to handle D1 single-writer mode constraints?▼

Handling D1 single-writer mode constraints requires using batch write optimization to group operations, reducing round-trips and ensuring atomicity, while routing read queries to replicas to improve performance.

How does EXPLAIN QUERY PLAN analysis improve D1 edge performance?▼

EXPLAIN QUERY PLAN analysis improves D1 edge performance by revealing how the SQLite engine executes a query, allowing you to identify missing indexes, detect full table scans, and eliminate N+1 query bottlenecks.

Can I use read replicas to speed up D1 query performance at the edge?▼

You can speed up D1 query performance by implementing read replica patterns that route read queries to replicas, directing writes to the primary database to respect serialized-writes constraints and reduce latency.

Why are my batch writes failing atomicity checks in Cloudflare D1?▼

Batch writes may fail atomicity if operations are not grouped correctly; D1 requires batch write optimization to reduce round-trips and ensure atomic execution under its serialized-writes edge deployment model.

What are common SQLite anti-patterns to avoid with D1 indexing?▼

Common D1 indexing anti-patterns include ignoring composite and partial indexes, failing to eliminate N+1 queries through joins, and overlooking FTS considerations for efficient data access on edge deployments.