Skip to content

fix(rust/sedona-functions): check collections member by member in ST_IsClosed - #1602

Merged
paleolimbot merged 1 commit into
apache:mainfrom
FurkhanShaikh:fix/isclosed-quadratic-emptiness
Nov 23, 2026
Merged

paleolimbot merged 1 commit into
apache:mainfrom
FurkhanShaikh:fix/isclosed-quadratic-emptiness

Conversation

@FurkhanShaikh

@FurkhanShaikh FurkhanShaikh commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1601.

Summary

Since #1600, is_geometry_empty looks into a collection's members, recursing into nested collections, until it finds one that is not empty. ST_IsClosed called it on every geometry before recursing into a collection's members, so for a collection nested around a non-empty geometry each level searched all the levels below it again, and a collection nested d levels deep took O(d²) work.

is_geometry_closed now handles a collection before the emptiness check, as suggested in #1601. An empty member is not closed, so checking the members also covers a collection whose members are all empty. Only a collection without members needs its own check, and it still returns false. Results are unchanged.

Time per call of is_geometry_closed on a collection nested around one point (debug build, Linux, all three measured in the same run). This PR brings it back to what it was before #1600:

Depth Before #1600 main (with #1600) This PR
125 6.3 µs 186 µs 6.8 µs
250 13.9 µs 721 µs 11.1 µs
500 26.6 µs 2,963 µs 23.9 µs

Test plan

  • New udf_collections test: empty collections, collections whose members are all empty, an empty member next to a non-empty one, and closed and open members, nested and not. It passes before and after this change, and fails if the check for a collection without members is removed. All seven cases match PostGIS 3.6.4.
  • The timings come from a local test that is not part of this PR.
  • cargo test -p sedona-functions (669 passed), cargo clippy -p sedona-functions --all-targets -- -D warnings, and cargo fmt --all -- --check (Linux).

…IsClosed

Since apache#1600, is_geometry_empty() looks into a collection's members,
recursing into nested collections, until it finds one that is not
empty. is_geometry_closed() called it at every level before recursing
into the members, so for a collection nested d levels deep around a
non-empty geometry each level searched all the levels below it again:
O(d^2) work. Collections are now handled before the emptiness check: an
empty member is not closed, so checking the members also covers a
collection whose members are all empty, and only a collection without
members needs its own check. Results are unchanged; a new test pins
them for collections.

Closes apache#1601.

Generated-by: Claude Code (Claude)

@jiayuasu jiayuasu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paleolimbot
paleolimbot merged commit fb1f669 into apache:main Nov 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The empty check in ST_IsClosed performs repeated recursive work

3 participants