For most of this answer, I'm going to assume you mean the DO KV API but just in case you meant Worke

For most of this answer, I'm going to assume you mean the DO KV API but just in case you meant Workers KV the huge difference are the network round trips.

So, back to SQL vs DO KV...

First, just because N+1 selects can be as efficient as joins, doesn't mean you won't use joins some or even most of the time. For simple joins like inner and natural the syntax is easy to comprehend and it may even be more efficient. For complex joins like outer and cross as well as SQL with subqueries or aggregations it's less about efficiency and more about making sure that the next developer (and even yourself at a later date) can make sense of what's going on. Doing it in JavaScript may be a better alternative from this perspective. Note, neither @kenton nor the SQLite docs say that you should use N+1 selects, just that if you want, you shouldn't worry about efficiency because there is no network round trip or even CPU context switching cost.

Second, SQL isn't just about joins. Indexes in particular are a feature missing from KV that's super helpful but there are also triggers, constraints, aggregations, etc. that you may want to take advantage of.
Was this page helpful?