Skip to content

RTree UPDATE does not persist changed bounds #208

Closed

Description

@whb07

Summary

UPDATE statements against an RTree virtual table report success but leave geometry unchanged.

Severity: High

Reproduction

Create an rtree(id,minx,maxx,miny,maxy), insert (1,0,1,0,1), update all bounds to 5/6, and query the row. Repeat by updating only maxx to 20.

Expected behavior

The full update returns (1,5,6,5,6), and the partial update persists maxx=20.

Actual behavior

The original bounds remain (1,0,1,0,1); partial coordinate updates are likewise ignored.

Validation

Fresh-database tests assert the pre-update rectangle, require UPDATE success, and compare every coordinate after full and partial updates with SQLite.

Activity

  1. Dicklesworthstone commented on Jul 16, 2026

    @Dicklesworthstone
    Owner

    Thanks for the report — confirmed, and the diagnosis is interesting: the UPDATE actually does persist, but same-connection reads don't see it.

    What's happening: DML against live virtual tables must be routed through the module's xUpdate so the in-memory module instance and the backing storage stay coherent. INSERT and DELETE already do this (execute_live_vtab_insert_rows / execute_live_vtab_delete in fsqlite-core/src/connection.rs; the DELETE branch was added for #94 and its comment documents exactly this hazard). The Statement::Update arm never got the equivalent branch — it compiles a plain VDBE table-update program that mutates the persisted materialized backing rows but never touches the live RtreeVirtualTable instance that answers SELECT scans on the same connection. That's why changes() reports 1 and the bounds look unchanged: the write landed on disk, the in-memory R-tree is stale. You can verify this from your repro — closing and reopening the database shows the updated rectangle (1|5.0|20.0|5.0|6.0, matching SQLite exactly), because reopen rehydrates the vtab from the persisted rows.

    So no data is lost, but any read in the same session after an rtree UPDATE returns stale geometry, which is a silent wrong-result and clearly unacceptable.

    Planned handling: add a live-vtab branch to the UPDATE arm (connection.rs ~25015) mirroring the DELETE precedent — resolve the matching rowids and new row images (the trigger machinery already computes old/new pairs), then route each row through the module's xUpdate update form so both the in-memory instance and backing storage are written together, including the rtree first-column/rowid patching the INSERT path already applies. While fixing this we'll also cover the adjacent failure we found on the same path: UPDATE on an FTS5 table currently errors with "OpenWrite failed: could not open storage cursor on root page 0" for the same missing-routing reason, just with a louder failure mode. Both will be gated with parity tests against the rusqlite oracle covering full and partial coordinate updates plus rowid-change UPDATEs.


    Status: confirmed and queued for a fix — tracked internally as bd-gh-live-vtab-update-routing-bw5nh with the full verified evidence and fix-location analysis attached. This issue stays open until the fix lands.

  2. added 4 commits that reference this issue on Aug 16, 2026
  3. Dicklesworthstone commented on Aug 18, 2026

    @Dicklesworthstone
    Owner

    Verified fixed at main (fix commit 5905ec2, 'route live virtual-table UPDATE through the module'). RTree UPDATE now persists changed bounds (full and partial coordinate updates). Regression keeper crates/fsqlite-core/tests/rtree_update_live_refresh_gh208.rs passes (1/1) at HEAD.

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址