{"schema": "pgtrue.report/1", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958", "published": "2026-10-19T07:59:41Z", "publisher": "PostgresAI", "article": {"title": "How TABLESAMPLE picks rows", "url": "https://boringsql.com/posts/tablesample", "date_published": "2026-10-11T00:00:00Z", "author": "Radim Marek", "publisher": "boringSQL"}, "grade": "B", "axes": [{"axis": "Factual", "summary": "B- \u00b7 2 wrong of 8 checked \u00b7 0 caveats"}, {"axis": "Applicable", "summary": "A \u00b7 0 wrong of 7 checked \u00b7 1 caveat"}, {"axis": "Consistent", "summary": "A \u00b7 0 wrong of 8 checked \u00b7 0 caveats"}, {"axis": "Transparent", "summary": "C \u00b7 0 wrong of 3 checked \u00b7 0 caveats \u00b7 reproducibility: C (no hardware)"}, {"axis": "Safe", "summary": "not applicable"}], "findings": [{"anchor": "F3", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F3", "claim": "\u2026a sample scan runs in the leader process\u2026", "title": "Sample scans can execute inside parallel workers", "explanation": "SampleScan has parallel_aware=false, but its parallel_safe flag follows the relation. allpaths.c explicitly permits safe sampling inside workers. A sample scan can form a non-parallel inner input within a parallel join. TABLESAMPLE does not force every surrounding plan to run serially.", "verdict": "False", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/parallel.sgml#L310-L360", "label": "REL_18_6 \u00b7 doc/src/sgml/parallel.sgml:310-360"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/optimizer/path/allpaths.c#L625-L644", "label": "REL_18_6 \u00b7 src/backend/optimizer/path/allpaths.c:625-644"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/optimizer/util/pathnode.c#L1011-L1028", "label": "REL_18_6 \u00b7 src/backend/optimizer/util/pathnode.c:1011-1028"}]}, {"anchor": "F4", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F4", "claim": "\u2026a scan reads all of them from disk, every time\u2026", "explanation": "A full scan does not necessarily require physical storage reads for every page. PostgreSQL relies on the operating system cache (E-11, E-32). Measure storage I/O before assigning every full scan a physical-read cost of 1 TB.", "verdict": "False", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L1727-L1760", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:1727-1760"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L1754-L1756", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:1754-1756"}]}, {"anchor": "F2", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F2", "claim": "None of them when you need a filtered subset\u2026", "explanation": "TABLESAMPLE chooses rows before WHERE, so it cannot guarantee a requested qualifying sample size. The article demonstrates filtering that sample. Its conclusion says none of the methods suit filtered subsets. That wording also excludes key hashing, which can accompany another WHERE predicate.", "verdict": "Mostly accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/select.sgml#L438-L443", "label": "REL_18_6 \u00b7 doc/src/sgml/ref/select.sgml:438-443"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/hash/hashfunc.c#L103-L114", "label": "REL_18_6 \u00b7 src/backend/access/hash/hashfunc.c:103-114"}]}, {"anchor": "F5", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F5", "claim": "\u2026Both built-in sampling methods hash part of that address together with a seed\u2026", "explanation": "SYSTEM hashes the block number and seed (E-2). BERNOULLI hashes the block number, tuple offset, and seed (E-13). Equal inputs preserve selection decisions. Heap sampling skips non-normal item pointers (E-25). These ranges verify address-based selection, without verifying HOT update placement or measured retention.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/tablesample/bernoulli.c#L195-L220", "label": "REL_18_6 \u00b7 src/backend/access/tablesample/bernoulli.c:195-220"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/tablesample/system.c#L185-L208", "label": "REL_18_6 \u00b7 src/backend/access/tablesample/system.c:185-208"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/heap/heapam_handler.c#L2280-L2320", "label": "REL_18_6 \u00b7 src/backend/access/heap/heapam_handler.c:2280-2320"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeSamplescan.c#L248-L272", "label": "REL_18_6 \u00b7 src/backend/executor/nodeSamplescan.c:248-272"}]}, {"anchor": "F6", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F6", "claim": "\u2026larger than a quarter of shared_buffers\u2026", "explanation": "heapam.c selects BAS_BULKREAD for eligible non-local relations exceeding NBuffers / 4 blocks. The caller must permit the strategy (E-15). shared_buffers sets shared-buffer memory (E-11). These ranges verify the threshold and eligibility conditions.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L1727-L1760", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:1727-1760"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/heap/heapam.c#L391-L404", "label": "REL_18_6 \u00b7 src/backend/access/heap/heapam.c:391-404"}]}, {"anchor": "F7", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F7", "claim": "\u2026SET enable_hashjoin = off ; SET enable_mergejoin = off ;\u2026", "title": "The join settings support the alternative-plan comparison", "explanation": "enable_hashjoin and enable_mergejoin control the planner's respective join methods. Both default to on. Setting both off changes subsequent planning for the illustrated inner join. The source separately permits these methods for FULL joins when necessary.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L5644-L5656", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:5644-5656"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L5743-L5755", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:5743-5755"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/optimizer/path/joinpath.c#L281-L345", "label": "REL_18_6 \u00b7 src/backend/optimizer/path/joinpath.c:281-345"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/optimizer/path/joinpath.c#L170-L249", "label": "REL_18_6 \u00b7 src/backend/optimizer/path/joinpath.c:170-249"}]}, {"anchor": "F8", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F8", "claim": "ANALYZE builds pg_stats from a sample too\u2026", "title": "ANALYZE uses its own block and row sampling", "explanation": "ANALYZE initializes BlockSampler with a random seed from pg_global_prng_state. It then samples rows within selected blocks. pg_stats exposes information stored in pg_statistic. Changing samples can change statistics without changes to table data.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/analyze.c#L1223-L1233", "label": "REL_18_6 \u00b7 src/backend/commands/analyze.c:1223-1233"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/analyze.c#L1166-L1186", "label": "REL_18_6 \u00b7 src/backend/commands/analyze.c:1166-1186"}, {"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/system-views.sgml#L4146-L4225", "label": "REL_18_6 \u00b7 doc/src/sgml/system-views.sgml:4146-4225"}]}, {"anchor": "F11", "url": "https://pgtrue.postgres.ai/shared/brief/25eecb81-8ef3-4705-b362-35732dd9d958#F11", "claim": "\u2026all 18,085 of them (141 MB)\u2026", "title": "18,085 pages correctly round to 141 MiB", "explanation": "The size conversion is correct. At 8 KiB per page, 18,085 pages occupy 141 MiB rounded (derived: 18,085 \u00d7 8,192 / 1,048,576).", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/config.sgml#L1743-L1743", "label": "REL_18_6 \u00b7 doc/src/sgml/config.sgml:1743-1743"}]}]}