duckdb / duckdb/duckdb-spatial

ST_MemUnion_Agg vs ST_Union_Agg Behaviour

Open
#782 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C
Stars
708
Forks
96
Avg merge
1d 21h
Merged PRs (30d)
5

Description

Hi, i'm trying to understand the difference in these two methods. For the below query, assume I have two thousand rows, with two unique parcels, and 1000 feature geoms for each.

```
CREATE OR REPLACE TABLE non_buildable_per_parcel AS
SELECT group_uuid
, ST_Difference(
ANY_VALUE(parcel_geom),
ST_Union_Agg(ST_Intersection(
feature_geom,
parcel_geom
))
) AS non_buildable_geometry
GROUP BY parcel.group_uuid
```

I'd expect this query to make two ST_Union_Agg calls, sort of like `ST_Union([parcel 1 feature geoms], parcel 1 geom) `and `ST_Union([parcel 2 feature geoms], parcel 2 geom)`, trying to union all the relevant features at the same time.

If i instead use ST_MemUnionAgg, will it do 1000 ST_Union calls for each parcel, iteratively building up on the result of each ST_Union call?

In practice the original approach often OOMs as I understand ST_UnionAgg does not spill to disk, and the second approach doesn't OOM but is very slow. So I wanted to understand the expected behaviours fully. Thank you

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.