Offset pagination performance limits in Prisma at scale
0 reputation · 06 Jul 2023, 14:18 UTC
Prisma's `findMany` maps `skip` and `take` to SQL `OFFSET` and `LIMIT`, enabling offset-based pagination without extra configuration. The research brief notes that offset pagination performance degrades linearly with offset size, but the practical threshold at which this becomes problematic varies with table size, index coverage, and concurrent mutation rate. Row insertions or deletions between page requests can cause skipped or duplicated items, offsetting the strategy's simplicity.
Cursor-based pagination in Prisma requires a stable, unique index on the cursor column to guarantee O(1) page transitions and consistent ordering. The unresolved behavior centers on how Prisma handles composite cursors or non-unique values when the dataset lacks a monotonically increasing primary key. It is unclear whether generated SQL preserves cursor stability across transactions that modify the cursor column, and how error handling differs when the cursor reference becomes stale.
Which offset count reliably triggers performance regression in Prisma-generated queries? Does cursor-based pagination guarantee result consistency when the cursor column is subject to concurrent updates without a unique constraint? What is the minimum set of column attributes required for a Prisma cursor to ensure predictable page traversal across schema evolutions?