Skip to content

TRUNCATE TYPE on a LIGHTWEIGHT edge type deletes nothing (now refuses); scanType() bypasses the vertex walk #7481

Closed

Description

@lvca

Follow-up to #7477 / PR #7478. TRUNCATE TYPE on a LIGHTWEIGHT edge type currently refuses (added in that PR); it should delete the edges.

Why it refuses today

TruncateTypeStatement.executeDDL deletes what Database.scanType() finds, and LocalDatabase.scanType iterates type.getBuckets(polymorphic) and reads those bucket pages directly. It never goes through SelectExecutionPlanner, so the vertex walk #7477 gave SELECT and DELETE FROM does not reach it.

A lightweight edge allocates no record, so that bucket is empty by construction. Before #7478 the statement therefore reported success having deleted nothing:

> select count(*) from Cite
{c: 2}
> truncate type Cite
{operation: truncate type, typeName: Cite, transactional: true}
> select count(*) from Cite
{c: 2}

That is the failure #7477 is about, in its worse form: a caller who believes a bulk delete happened has no reason to look again. #7478 made it throw, naming the type and pointing at DELETE FROM <type>, which reaches the edges correctly.

Why it was not just made to work

The obvious fix - walk the vertices and delete what the walk yields - mutates the very edge lists it is iterating. GraphEngine.deleteEdge removes the entry from both endpoints' lists, so a naive walk-and-delete hits the read-modify-write hazard EdgeLinkedList.edgeIteratorForRemoval exists for (#5680), and the collect-then-delete alternative holds one entry per edge in memory - 75 million of them on the graph that opened #7477, against a TRUNCATE that is otherwise batched precisely so it does not.

So it needs the same care the removal paths in GraphEngine already have, which is more than a rider on a SELECT fix.

Shape of a fix

Either:

  1. Route the deletion through the removal-safe iterator, per source vertex: for each vertex, collect that one vertex's matching OUT entries, delete them, move on. Bounded by degree rather than by edge count, and reuses the invariant edgeIteratorForRemoval already establishes.
  2. Or delegate to the same path DELETE FROM <type> takes, which is already correct, and let TRUNCATE be a thin wrapper for this case - giving up the index-drop/rebuild speed-up, which is worth nothing on a type that has no records to index anyway.

(2) is probably right: a lightweight type has no indexes to drop (it can have no properties), so the fast path truncateInOwnTransaction exists for buys nothing here.

Either way it wants tests of its own: the caller-transaction and own-transaction paths, a mixed hierarchy where only part of the type is lightweight, and rollback.

Also in this family

Database.scanType() is the shared blind spot rather than TRUNCATE specifically. Worth checking every other caller for the same silent no-op before closing this.

Activity

  1. added this to the 26.10.1 milestone on Sep 11, 2026
  2. self-assigned this
    on Sep 11, 2026
  3. added
    engine
    on Sep 11, 2026
  4. added a commit that references this issue on Sep 11, 2026
  5. added
    in progress
    on Sep 15, 2026
  6. lvca commented on Sep 15, 2026

    @lvca
    MemberAuthor

    Fixed in #7626 (26.10.1).

    TRUNCATE TYPE on a LIGHTWEIGHT edge type used to always refuse, because it looked for records in a place where a lightweight edge never leaves one. It now actually deletes the edges, the same way DELETE FROM <type> already did.

    One thing to know: if the type has a subtype, you now need to add POLYMORPHIC to truncate both levels together (e.g. TRUNCATE TYPE Mentions POLYMORPHIC); without it, the statement refuses rather than guessing which edges you meant.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginesql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions