{"success":true,"name":"paginate-large-sql-results-instead-of-fetching-everything","description":"A SQL query returns a list that will grow over time.","category":"ai-brimind","path":"ai-brimind/paginate-large-sql-results-instead-of-fetching-everything/SKILL.md","file":"SKILL.md","content":"---\nname: paginate-large-sql-results-instead-of-fetching-everything\ndescription: \"A SQL query returns a list that will grow over time.\"\n---\n\n# Paginate Large SQL Results Instead of Fetching Everything\n\n## When to use\nProject uses SQL, and you are writing a query that returns a user-facing or processed list with no LIMIT, on a table that grows.\n\n## Example request\nLoading all rows to show a page → works with 200 rows, freezes with 200,000; growth was never in the test. OFFSET 50000 for deep pages → the database still walks all skipped rows; keyset (WHERE id > last_seen) pagination scales. Pagination without ORDER BY → rows shuffle between pages; stable ordering is part of the contract. Processing a whole table in one fetch → memory blows up; batching with LIMIT in a loop is the pattern.\n\n## Instructions\nAct like a developer who designs for the table's size next year, not today. For any query returning a list: add an explicit LIMIT and a deterministic ORDER BY (with a unique tiebreaker column) — no exceptions for 'small' tables, they grow. Choose the pagination style deliberately: OFFSET is fine for shallow pages, keyset pagination (filtering past the last seen key) for deep or infinite scrolling. For background processing, batch with LIMIT in a loop instead of loading everything. Check whether your framework already ships a pagination helper before writing one. Only finish once you can state the maximum rows any single query can return, and why the page order stays stable as data changes.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1035\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}