cloudflare-d1-query-tuning

Tune slow Cloudflare D1 queries via SQL rewrites without schema changes.

1|1|Updated May 3, 2026
One-click install
npx skills add https://github.com/matt-riley/agent-skills --skill cloudflare-d1-query-tuning
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cloudflare-d1-query-tuning
Source: https://github.com/matt-riley/agent-skills/tree/main/skills/cloudflare-d1-query-tuning
Command: npx skills add https://github.com/matt-riley/agent-skills --skill cloudflare-d1-query-tuning

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Cloudflare D1 query performance can degrade in D1-backed repos due to N+1 lookups, over-fetching, and poorly paginated queries. This skill guides safe, no-schema-change tuning that preserves data contracts and repo behavior.

Core Features & Use Cases

  • D1 runtime inspection: use wrappers and commands like wrangler d1 execute and EXPLAIN QUERY PLAN to understand the slow path without changing data access contracts.
  • No-schema tuning: pushes filtering, limiting, and path optimization into SQL to reduce scans and round trips.
  • Real-world scenarios: ideal for Cloudflare Workers data access layers with N+1 patterns, over-fetching, or pagination bottlenecks in production.

Quick Start

Reproduce the slow path with the exact D1 binding and apply a set-based rewrite to reduce scans while preserving results.

Frequently Asked Questions about cloudflare-d1-query-tuning

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

FAQPage Schema
How do I fix slow Cloudflare D1 queries without changing the database schema?

You can fix slow Cloudflare D1 queries without schema changes by applying SQL-side rewrites that push filtering, limiting, and path optimization into the query to reduce scans and round trips.

What is the best way to resolve N+1 lookup patterns in a Cloudflare Workers data access layer?

The best way to resolve N+1 lookups in a Cloudflare Workers data access layer is replacing iterative single-row fetches with set-based SQL rewrites that retrieve all required rows in a single query.

How do I use EXPLAIN QUERY PLAN to debug Cloudflare D1 performance bottlenecks?

You can use EXPLAIN QUERY PLAN alongside wrangler d1 execute to inspect D1 binding behavior and identify the slow query path, allowing targeted SQL rewrites without modifying data access contracts.

Can I tune D1 pagination bottlenecks in production without altering data access contracts?

Yes, you can tune D1 pagination bottlenecks in production by inspecting runtime query shapes and applying SQL-side path optimization that preserves result semantics and repo behavior without schema migrations.

Why does my Cloudflare D1 query over-fetch data and how can I limit it?

Your Cloudflare D1 query over-fetches data due to poorly shaped runtime queries, which you can fix by pushing stricter filtering and limiting logic directly into the SQL statement to reduce unnecessary scans.