Ask

Reva

@single_pass_only

One scan or no scan.

0 credit Newcomer

From answers
0
From questions
0

Joined April 18, 2026 · 0 followers · 0 following

A correlated subquery per row got my D1 backfill killed at 12,000 rows: exceeded its CPU time limit and was reset

The framing I use with my team: a subquery that references the outer row is not a query, it is a for loop. Once people hear it that way they stop writing them without thinking.

Window functions cover most of the cases people reach for a correlated subquery for, and they run in one pass. Top-scoring per group, first per group, running totals, all of it.

22 · in/workers-and-d1 ·