> [!NOTE] Sample Scan > <table> > <tr> > <td width="25%"><img src="assets/ex_samplescan.png"></td> > <td>Implements the <code>TABLESAMPLE</code> clause. Instead of scanning the whole table, the engine uses a specific sampling method (Bernoulli or System) to select a random subset of pages or rows, drastically reducing I/O for statistical queries.</td> > </tr> > </table> > > ```sql > -- Sampling 10% of the animals table using the SYSTEM method > EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE) > SELECT * FROM animals TABLESAMPLE SYSTEM (10); > ``` > > ![SampleScan Plan Tree](assets/plan_tree_op_sample_scan.svg) > > ```text > Sample Scan on public.animals (cost=0.00..38.00 rows=1000 width=27) (actual time=0.003..0.013 rows=272 loops=1) > Output: id, name, species_id, created_at > Sampling: system ('10'::real) > Buffers: shared hit=2 > Planning: > Buffers: shared hit=73 > Planning Time: 0.163 ms > Execution Time: 0.025 ms > ``` > > ![Sample Scan measured plan performance signature](assets/trace_op_sample_scan.svg) > > <table> > <tr> > <td rowspan="2" width="25%"><img src="assets/ex_scan.svg"></td> > <td><b>Performance</b></td><td>High performance; <code>SYSTEM</code> sampling is typically much faster than <code>BERNOULLI</code> as it samples at the block level rather than the row level.</td> > </tr> > <tr><td><b>Cost</b></td><td><code>sampling cost * sample size</code></td></tr> > </table>