Skip to content

ST_DWITHIN with zero buffer faster than ST_WITHIN ? #826

Description

@glaroc

Hi, I'm performing a spatial join with:

CREATE TABLE regions_obs AS
           SELECT adm2_name, count(*) AS cnt
           FROM atlas a
           JOIN regions_qc r ON ST_Within(a.geom, r.geometry) 
           GROUP BY adm2_name;

The atlas table has 55 million rows and an RTREE index on the geometry. The regions_qc file has 17 polygons. The query above takes several hours and a lot of memory on a machine with 15 cores and 180GB of RAM.

However, this query

CREATE TABLE regions_obs AS
           SELECT adm2_name, count(*) AS cnt
           FROM atlas a
           JOIN regions_qc r ON ST_DWithin(a.geom, r.geometry,0)
           GROUP BY adm2_name;

Which, to my understanding, should be identical, finishes in about 15 minutes.

Any idea why that is ?

With Duckdb 1.5.3 and most recent spatial extension commit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions