Repository navigation
Re-index a node that is added to an RTree layer again - #495
Merged
Merged
Conversation
Adding an already indexed node created a second RTREE_REFERENCE: queries returned it twice, the feature count grew, and removing or updating the node failed with "More than one relationship". The RTree now drops duplicates from the input and re-inserts a node it already holds only when its envelope no longer fits its leaf, so a moved node can simply be added again and an unchanged one costs no writes.
Removing or re-adding a node that is in more than one RTree layer failed with "More than one relationship[RTREE_REFERENCE, INCOMING]". add, remove and isNodeIndexed now act on every reference this tree holds to the node, which also drops duplicate references written by earlier releases when the node is added again. A moved node must be re-added to each layer.
There was a problem hiding this comment.
🔵 Needs a closer look
Human validation is needed because the RTree delete/reinsert changes affect persisted structure and legacy duplicate references, while runtime tests are unavailable to verify tree invariants and cross-layer behavior.
No open issues 🎉
What changed in this PR
Updates RTree indexing so re-adding an existing node avoids duplicate references and can relocate nodes whose geometry changed.
Changes:
- Deduplicates nodes in bulk additions and reindexes moved or previously duplicated RTree entries.
- Removes matching references safely when removing nodes and handles membership across multiple layers.
- Adds regression tests and updates procedure and API documentation.
| File | Description |
|---|---|
| server-plugin/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java | Adds regression coverage for repeated additions, moved nodes, duplicate legacy references, multiple layers, and WKT-backed layers. |
| server-plugin/src/main/java/org/neo4j/gis/spatial/rtree/RTreeIndex.java | Implements duplicate detection, reindexing of moved nodes, and safe removal of multiple references. |
| server-plugin/src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java | Documents repeated-add and moved-node behavior for the spatial add procedures. |
| docs/docs/modules/ROOT/partials/generated/api/spatial/spatial.addNodes.adoc | Updates the generated documentation for spatial.addNodes reindexing behavior. |
| docs/docs/modules/ROOT/partials/generated/api/spatial/spatial.addNode.adoc | Updates the generated documentation for spatial.addNode reindexing behavior. |
| docs/docs/modules/ROOT/partials/generated/api/index.adoc | Reflects the updated spatial procedure descriptions in the generated API index. |
Review effort: Lite
Collaborator
Author
|
On the tree invariants: removing a reference runs the unchanged
A broken leaf bounding box would show up as a missed search hit. So no separate tree invariant test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding a node that was already in an RTree layer created a second
RTREE_REFERENCE. Queries then returned the node twice,spatial.getFeatureCountcounted it twice, andspatial.removeNode/spatial.updateWKTfailed withMore than one relationship[RTREE_REFERENCE, INCOMING].spatial.addNodeandspatial.addNodesnow re-index a node the layer already holds. Calling them again after changing a node's coordinates moves it in the index; a moved node has to be re-added to every layer that holds it. A re-added node whose envelope still fits its leaf is left untouched. Duplicates within onespatial.addNodeslist are indexed once.Removing or re-adding a node that is in several RTree layers no longer fails with
More than one relationship. Duplicate references written by earlier releases are dropped when the node is added again.Geohash, z-order and Hilbert layers were not affected.
Resolves #65
Resolves #254
Resolves #178
Resolves #229
Resolves #439