26 November 2026 · 6 min

How to test Cloudflare D1 index recommendations before shipping

A CRM can show 20 open enquiries while scanning thousands of rows. Here’s how to test a D1 Insights recommendation with SQLite and measure whether the migration pays off.

How to test Cloudflare D1 index recommendations before shipping

On Monday morning, the sales team opens its CRM and sees 20 open enquiries. Behind that short list there may be a full table scan. Every time a team loads the view again, the database repeats the search. Cloudflare D1 measures usage in rows read, so the length of the result tells you very little about the work behind it. Cloudflare D1 Pricing

Since November 25, 2026, D1 Insights has been able to recommend indexes. The database’s Metrics tab shows the proposed SQL, the queries it is meant to improve and metrics for those queries. Cloudflare validates the syntax. Checking whether the index fits the application’s schema and whether SQLite uses it is part of reviewing the migration. Cloudflare’s November 25 changelog · D1 Index Recommendations

Start with the query people run all day

Say the list reads 8,000 rows per load and opens 1,200 times a day. That adds up to 9.6 million rows read per day. An export that reads 200,000 rows once a day looks more expensive on a single trace. Measured by daily read volume, the list is the bigger job.

That is where we would start. Look at executions per day, rows read per execution and 95th percentile duration to see how the query behaves at the slower end. The D1 Workers binding also returns rows_read and rows_written for individual executions. Those values help when the aggregate combines customers with very different amounts of data. D1 Metrics and Analytics

Build the index around the sales team’s actual view

In our example, the query filters by workspace_id and status, then puts the newest enquiries first. The ID breaks ties when two enquiries have the same timestamp. That gives us a stable order to check before and after the migration.

SELECT id, created_at FROM leads
WHERE workspace_id = ? AND status = ?
ORDER BY created_at DESC, id DESC LIMIT 20;

A composite SQLite index on workspace_id, status, created_at and id is a good candidate. The first two columns narrow the search. The last two support the requested order, so SQLite can find the newest matching entries in sequence. A separate view that shows all statuses sorted together by date has a different query shape and warrants its own measurement. SQLite Query Planning

CREATE INDEX leads_workspace_status_recent
ON leads (workspace_id, status, created_at DESC, id DESC);

Run the migration against a realistic test dataset

Run the same query with and without the index. EXPLAIN QUERY PLAN shows whether SQLite selects the new index and whether it builds a temporary structure to sort the result. Then compare rows and ordering for a small workspace, a busy workspace and a workspace with no open enquiries. In D1, compare rows read for those same runs. Measure the full endpoint separately, since authentication and other queries can add time after the database change.

The database has to maintain the index whenever you insert a new enquiry. Status changes can add write work too. If the CRM handles bulk imports, measure an import as part of the evaluation. Once the read improvement justifies the write overhead, keep the change in a versioned D1 migration. After rollout, check read volume, write volume and slower requests against the baseline. D1 Index Recommendations · Cloudflare D1 Pricing

Review what goes into the recommendation

Cloudflare uses Workers AI to generate the suggestions from query statements, usage data and database schema. The usage metrics themselves come from D1 analytics. The setting applies across the account, which matters when one account hosts several client databases. Teams can turn off the recommendations and keep their ordinary D1 metrics. D1 Index Recommendations

For your next performance review, ask the sales team which view they open first each morning. If that query reads far more rows than it returns, you have a place to start. The index earns its place when the team sees the same enquiries and the database consistently does less work to find them.

Cloud
Cloud
Contact us

We can say a lot. It is better to make something great together.

Tell us briefly what you have in mind — we will reply with a few concrete first thoughts.

Personal reply · usually within 1 working day · first call is free