Skip to content
About
Main content

Scan resistance by declaration

Why does an operator that declares its scan beat every adaptive replacement policy?

Every policy above (, Clock, LRU-K, , ) is an attempt to infer statistically that a scan is a scan. The executor already knows.

PostgreSQL's buffer access strategies express this directly:

  • A sequential scan of a table larger than a quarter of shared_buffers gets a 256 KB : it reuses the same handful of frames and never touches the main pool.
  • Bulk writes get a 16 MB ring.
  • VACUUM gets its own ring.

This is this mechanism's central theme at its sharpest, and it operates at two levels in one mechanism. The exists because the application knows more than the kernel. The ring buffer exists because the operator knows more than the buffer pool. No amount of adaptivity in the replacement policy can match a caller that simply says what it is doing, because the policy infers from a lossy projection of information that exists intact one layer up.

It is also the cleanest test of the take-back rule from Ownership, and the rule passes with its boundary condition intact: the override exists exactly where extra information exists, and nowhere else. A point lookup does not get a ring buffer, because the executor has nothing extra to say about it.

One-line compression: every adaptive policy infers what the caller could have declared. Where the caller can declare it, the policy is bypassed rather than tuned.