Opened 10 years ago

Last modified 3 weeks ago

#2614 new enhancement

Prepared geometry support for ST_DWithin

Reported by: robe Owned by: pramsey
Priority: high Milestone: PostGIS Fund Me
Component: postgis Version: master
Keywords: Cc:

Description (last modified by robe)

In some cases, despite what we tell people, doing an

ST_Intersects(geom1, ST_Buffer(geom2,radius)) 

is sometimes faster than ST_DWithin(geom1,geom2, radius)

Granted ST_DWithin is more accurate.

I'll come up with a small self-standing example to demonstrate the point. The one I have currently is kind of hefty.

But basic assumption is if you have a fairly large constant geometry then ST_Intersects(ST_Buffer..) often out performs ST_DWithin. I assume this is because ST_Intersects takes advantage of prepared geometries and ST_DWithin does not.

Change History (14)

comment:1 by robe, 10 years ago

Description: modified (diff)

comment:2 by pramsey, 9 years ago

This is my distance rect-tree improvement, which is still sitting half-done, taunting me… it scares me too, since distance is only 95% of what people do all the time. Mucking with it is scary.

comment:3 by pramsey, 9 years ago

Priority: mediumhigh

comment:4 by pramsey, 9 years ago

Milestone: PostGIS 2.2.0PostGIS 2.3.0

comment:5 by robe, 8 years ago

I take it this ain't going to happen anytime soon. Okay for me to push?

comment:6 by robe, 8 years ago

Milestone: PostGIS 2.3.0PostGIS 2.4.0

comment:7 by robe, 7 years ago

Milestone: PostGIS 2.4.0PostGIS 2.5.0

comment:8 by pramsey, 6 years ago

In 16393:

Edge tree index on geometries makes distance calculations on large geometries
go much faster. Needs to be used selectively and potentially with a caching
component for maximum effect. Test it out using _ST_DistanceRectTree(geom, geom)
for now.
References #2614

comment:9 by pramsey, 6 years ago

In 16410:

Add cache support for rect_node trees and expose for testing
in _ST_DistanceRectTreeCached(geom, geom).
References #2614

comment:10 by robe, 6 years ago

Milestone: PostGIS 2.5.0PostGIS next

comment:11 by robe, 6 years ago

Milestone: PostGIS nextPostGIS 3.0.0

Milestone renamed

comment:12 by pramsey, 5 years ago

Milestone: PostGIS 3.0.0PostGIS Fund Me

comment:13 by strk, 3 weeks ago

For the record: GEOS-3.10 (2021-10-20) added GEOSDistanceWithin and GEOSPreparedDistanceWithin and I know they are both much faster than the current lwgeom_mindist2d_tolerance implementation ( see https://trac.osgeo.org/postgis/ticket/3587#comment:45 )

comment:14 by strk, 3 weeks ago

Still for the record: GEOSDistanceWithin is also faster when I force the use of the so called "fast" distance calculation in PostGIS, for the case of a large ring compared against a ring inside of it.

Note: See TracTickets for help on using tickets.