Data flow · EXPLAIN ANALYZE, PostgreSQL 16
Wrapping the column vs rewriting as a range
Wrapping the column vs rewriting as a range
A date_part condition wrapped around tao_luc leads to a Seq Scan reading all 200,000 rows and discarding 162,482, taking 29.6 ms, with the planner estimating 1,000 rows against 37,518 actual. A range condition on the bare column leads to a Bitmap Index Scan on idx_don_tao_luc then a Bitmap Heap Scan, taking 5.4 ms, estimating 38,225 rows against 37,518 actual.
WHERE CONDITION
ACCESS PATH
TIME · ROW COUNT
Function wraps the column
date_part('year', tao_luc)
= 2026
Seq Scan on don
computes date_part on all 200,000 rows
Filter throws away 162,482 rows
29.6 ms
est. 1,000 rows
actual 37,518 rows
Range on the bare column
tao_luc >= '2026-01-01'
AND tao_luc < '2027-01-01'
Bitmap Index Scan
idx_don_tao_luc
jumps to the 2026 range
Bitmap Heap Scan
reads matching pages only
37,518 rows
5.4 ms
est. 38,225 rows
actual 37,518 rows
LEGEND
Execution plan node
Plan that uses the index
© tiennhm