Prompt Engineering SQL Scaling

SQL Performance Analysis — Surviving the Billion-Row Table

At 240M rows and growing: keyset pagination over OFFSET, partition pruning, and the PostgreSQL specifics — analysis aimed at the scale the table will reach, not the scale it passed.

Overview

Performance analysis at large scale is a different discipline: what matters is not today's timing but the curve it sits on. This prompt configures the scaling goal on PostgreSQL for an audit-log table heading to a billion rows: reason at target scale explicitly, identify the worse-than-linear work, replace OFFSET pagination — whose cost grows with page depth — with keyset pagination, and evaluate partition pruning where the platform offers it. The PostgreSQL guidance grounds it: EXPLAIN (ANALYZE, BUFFERS) for the evidence, BRIN indexes as the append-only table's cheap friend, bloat and autovacuum state at volumes where they dominate, and parallelism checked rather than assumed.

Workflow

  1. Name the target scale

    Every conclusion states the row count it assumes — one billion is the design point, not today's 240M.

  2. Kill OFFSET before it kills you

    Deep-page OFFSET cost grows with depth; keyset pagination holds constant.

  3. Prune instead of scan

    Partitioning evaluated by what queries can actually prune — not by partitioning fashion.

Why This Works

  • Target-scale reasoning catches what passes today and fails next year
  • Keyset-over-OFFSET is the highest-value pagination fix at scale
  • Pruning-based evaluation keeps partitioning honest about its wins

Best for

  • Append-heavy tables: audit logs, events, time series
  • Systems whose data outgrew their original query patterns
  • Capacity planning grounded in query mechanics

Not for

  • Small-table tuning where scale is not the issue — that's the Query Speed goal
  • Refactoring the application's data access layer — that's the Refactor Prompt Builder

Use cases

  • Preparing audit and event tables for the next order of magnitude
  • Replacing OFFSET pagination before deep pages time out
  • Evaluating partitioning with honest pruning analysis

Tip: Save time by exploring related resources and tools that integrate with this workflow.

Explore all resources