Skip to content

Commit

Permalink
Update pgp-antipattern.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts authored Mar 19, 2024
1 parent 436d9ad commit 5cbc2b3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pgp-antipattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
1. TOC
{:toc}

## Using `ST_Intersects` with `ST_Buffer` for proximity queries
## Using `ST_Distance` OR `ST_Intersects` with `ST_Buffer` for proximity queries

A simplistic way to test if geometries are near to (within a distance of) a given geometry is to compute the
buffer of the query geometry and then use `ST_Intersects` against the buffer geometry.
A simple way to test if geometries are near to (within a distance of) a given geometry is to compute the
buffer of the query geometry and then use `ST_Intersects` against the buffer geometry. However, this is somewhat inaccurate, since buffers are only approximations, and computing large buffers can be slow.

Use `ST_DWithin` instead, since it is automatically indexed, is faster to compute, and is more accurate.
Another way is to use `ST_Distance`. But this forces the full distance to be computed even though it is not needed. Also, this query does not take advantage of spatial indexes.

Instead, use `ST_DWithin` instead, since it is automatically indexed, is faster to compute, and is more accurate.
(it avoids having to compute the explicit buffer, which is only a close approximiation of the true distance).

## Using `ST_Contains/ST_Within` instead of `ST_Covers/ST_CoveredBy`
Expand Down

0 comments on commit 5cbc2b3

Please sign in to comment.