SQL Aggregation Not Materialization

Push counting, summing, and grouping into the database instead of loading rows to tally them in application code; replace per-item queries inside loops with one batched query; and cap any result set that can grow without bound. Use this whenever code reads from a database to compute a statistic, whenever a loop issues one query per element (the N+1 pattern), whenever an endpoint returns "all" of something, and whenever a function that runs on a hot path (every request, every tick, every recall) deserializes rows it does not need. Triggers — "this query is slow", "it scales with the table", "N+1", "database is the bottleneck", "the export times out", "count by", "group by", "stats endpoint". Push to use this whenever row-reading work grows with corpus size on a frequently-called path.

annatchijova 3d73e43 3 files · 9.6 KB Updated

File contents

annatchijova/SKILLS/tree/main/sql-aggregation-not-materialization commit 3d73e43a66

Frequently asked questions

npx skillmds@latest add annatchijova/sql-aggregation-not-materialization