An index-aware function lets PostgreSQL use a GiST index for an initial bounding-box filter before evaluating the exact spatial condition. This speeds searches while preserving accurate results. section 10.6.2
ST_DWithin is index-aware: it combines bounding-box operators such as && with ST_Expand, then compares actual distances. ST_Distance is not index-aware and can force a parallel full-table scan. section 10.6.2
Find nearby shops
Join points with ST_DWithin(b.way, p.way, 500), filter shops, calculate exact ST_Distance for display, sort by distance, and return the 10 closest results. The plan uses a GiST-assisted bitmap heap scan; replacing ST_DWithin with ST_Distance(...) <= 500 removes that index path.
