query-optimizer

Analyze D1 queries to detect unindexed columns, N+1 patterns, and pagination issues.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/littlebearapps/cloudflare-engineer --skill query-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-optimizer
Source: https://github.com/littlebearapps/cloudflare-engineer/tree/main/skills/query-optimizer
Command: npx skills add https://github.com/littlebearapps/cloudflare-engineer --skill query-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Static analysis of D1 queries to prevent costly row reads caused by unindexed queries, missing limits, and N+1 patterns. This approach helps developers catch problematic query patterns before they hit production and incur excessive costs.

Core Features & Use Cases

  • Detects expensive patterns such as SELECT * without LIMIT, unindexed WHERE clauses, and queries inside loops.
  • Flags N+1 query scenarios and suggests batching or in-clauses.
  • Supports Drizzle ORM patterns and general D1 usage across codebases.
  • Guides indexing strategies and query refactoring to reduce row reads and costs.
  • Use cases include API route audits, background jobs, and development environments to avoid cost surges.

Quick Start

Analyze a project to generate a D1 query optimization report that highlights risky queries and recommended fixes.

Frequently Asked Questions about query-optimizer

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

FAQPage Schema
How do I detect N+1 queries and excessive row reads in D1 before deploying?

To prevent D1 billing traps, analyze your codebase to identify unindexed WHERE clauses, SELECT * without LIMIT, and queries inside loops that cause excessive row reads before they incur production costs.

What causes high D1 billing costs in API routes?

High D1 billing costs are caused by unindexed columns, missing LIMIT clauses, and N+1 query patterns that trigger excessive row reads during API route execution.

Can I analyze Drizzle ORM patterns for D1 query optimization?

Yes, you can analyze Drizzle ORM patterns by scanning your codebase to detect risky ORM usage, score row read risks, and guide indexing and query-refactoring recommendations to reduce D1 costs.

What is the best way to fix unindexed D1 queries?

The best way to fix unindexed D1 queries is to apply static analysis to detect unindexed WHERE clauses, score the risk, and follow guided indexing strategies and query refactoring to reduce row reads.

Does static query analysis catch pagination issues in D1?

Yes, static query analysis catches D1 pagination issues by scanning API routes and ORM queries to detect missing limits and unindexed columns, guiding refactoring to mitigate excessive row reads.