Skip to content

TRUNCATE TYPE never refuses a non-empty vertex or edge type: the guard asks isSubTypeOf("V")/isSubTypeOf("E"), and no type ArcadeDB creates has a super type by those names, so the UNSAFE keyword the message demands is never actually demanded #8042

Closed

Description

@ruispereira

Summary

TruncateTypeStatement.executeDDL refuses to truncate a non-empty graph type unless UNSAFE is given. That
refusal is the only thing standing between TRUNCATE TYPE Person and the silent destruction of a live vertex type
and every edge attached to it, and its message tells the user exactly how to override it. It cannot fire.

The test for "is this a graph type" is typez.isSubTypeOf("V") / typez.isSubTypeOf("E").
LocalDocumentType.isSubTypeOf(String) matches by NAME - this type's own name, then recursively its super types'
names. ArcadeDB has no implicit root types called V and E: CREATE VERTEX TYPE Person builds a
LocalVertexType with an EMPTY super-type list, and there is no V anywhere in the schema for it to be under
(that is an OrientDB inheritance, not an ArcadeDB one). So for every vertex and edge type an ArcadeDB user
actually creates, both tests answer false, the recs > 0 block falls through with nothing to throw, and the
truncate proceeds.

The consequence is a data-loss footgun with a safety net that is painted on: a single
TRUNCATE TYPE <vertexType> with no UNSAFE empties the type and detaches every edge on it, and the documented
"Apply the 'UNSAFE' keyword to force it (at your own risk)" is never shown.

It also means the #7919 fix in this window does not close what its own comment says it closes. That commit
corrected the per-subtype count from countType(typeName, false) to countType(subType.getName(), true),
describing the bug as "a polymorphic TRUNCATE of an EMPTY root with non-empty subtypes sailed past the check that
exists to refuse it". The count is now right and the check it feeds is still dead, so for a real vertex/edge
hierarchy the statement still sails past. The regression test passes only because it builds the hierarchy around a
type it creates called E:

database.command("sql", "CREATE EDGE TYPE E");
database.command("sql", "CREATE EDGE TYPE Base");
database.command("sql", "CREATE EDGE TYPE Sub EXTENDS Base, E");

and the sibling test's own comment says so out loud: "Base is not under E, so the whole-subtree check does not
refuse".

Where (HEAD 28b71e3)

engine/src/main/java/com/arcadedb/query/sql/parser/TruncateTypeStatement.java:129

if (recs > 0 && !unsafe) {
  if (typez.isSubTypeOf("V")) {
    throw new CommandExecutionException("'TRUNCATE TYPE' command cannot be used on not empty vertex classes. "
        + "Apply the 'UNSAFE' keyword to force it (at your own risk)");
  } else if (typez.isSubTypeOf("E")) {
    ...

and the same pair again at lines 152 and 155 inside the per-subtype loop #7919 rewrote.

engine/src/main/java/com/arcadedb/schema/LocalDocumentType.java:2142

@Override
public boolean isSubTypeOf(final String type) {
  if (type == null)
    return false;
  if (type.equalsIgnoreCase(getName()))
    return true;
  for (final DocumentType superType : superTypes) {
    if (superType.isSubTypeOf(type))
      return true;
  }
  return false;
}

The line dates from the repository's first commit, so it is old code rather than churn - but #7919 has just
rewritten the code that feeds it without noticing.

Repro

Embedded, against engine/target/classes:

CREATE VERTEX TYPE Person
CREATE EDGE TYPE Knows
INSERT INTO Person SET name='a'
INSERT INTO Person SET name='b'
CREATE EDGE Knows FROM (SELECT FROM Person WHERE name='a') TO (SELECT FROM Person WHERE name='b')

SELECT count(*) FROM Person                -> 2
SELECT count(*) FROM Knows                 -> 1

TRUNCATE TYPE Knows                        -> OK   {"operation":"truncate type","typeName":"Knows"}
SELECT count(*) FROM Knows                 -> 0
SELECT out().size() FROM Person            -> 0     (the edge is gone, no UNSAFE was given)

TRUNCATE TYPE Person                       -> OK
SELECT count(*) FROM Person                -> 0

And the same guard DOES fire the moment a type literally named V is above it, which is the proof that the
predicate is the problem and not the surrounding logic:

CREATE DOCUMENT TYPE V
CREATE VERTEX TYPE P2 EXTENDS V
INSERT INTO P2 SET name='c'
TRUNCATE TYPE P2 -> CommandExecutionException: 'TRUNCATE TYPE' command cannot be used on not empty vertex
                    classes. Apply the 'UNSAFE' keyword to force it (at your own risk)

The polymorphic half, which is what #7919 rewrote:

CREATE VERTEX TYPE VB
CREATE VERTEX TYPE VS EXTENDS VB
CREATE VERTEX TYPE VGS EXTENDS VS
INSERT INTO VGS SET x=1
countType(VB, true) -> 1      countType(VB, false) -> 0      VB.isSubTypeOf("V") -> false
TRUNCATE TYPE VB POLYMORPHIC  -> OK, and VGS is emptied

Side by side on one non-empty vertex type, which is the whole finding in four lines:

CREATE VERTEX TYPE Person BUCKETS 1
INSERT INTO Person SET name='a'
SELECT count(*) FROM Person       -> 1

TRUNCATE BUCKET Person_0 -> CommandExecutionException: 'TRUNCATE BUCKET' command cannot be used on not empty
                            vertex bucket. Apply the 'UNSAFE' keyword to force it (at your own risk)
TRUNCATE TYPE   Person   -> OK
SELECT count(*) FROM Person       -> 0

The sibling statement gets it right

TruncateBucketStatement.executeDDL carries the identical guard, with the identical wording, and tests the type
instead of the name:

final DocumentType type = schema.getTypeByBucketId(bucket.getFileId());
if (type != null && !unsafe) {
  final long recordCount = db.countBucket(resolvedBucketName);
  if (recordCount > 0) {
    if (type instanceof VertexType) {
      throw new CommandExecutionException(
          "'TRUNCATE BUCKET' command cannot be used on not empty vertex bucket. Apply the 'UNSAFE' keyword ...");
    } else if (type instanceof EdgeType) {

So TRUNCATE BUCKET <b> refuses where TRUNCATE TYPE <t> does not, on the same data, with the same message
template - which is also the shortest possible proof that the name-based test in TRUNCATE TYPE is a mistake and
not a deliberate narrowing. DropTypeStatement, the third statement carrying an UNSAFE guard of this shape,
uses a third correct form again - typez.getType() == Vertex.RECORD_TYPE - so TRUNCATE TYPE is the only one of
the three that asks the question by name.

Suggested fix

Ask the schema what the type IS, not what it is called: copy TruncateBucketStatement's
type instanceof VertexType / type instanceof EdgeType. TruncateTypeStatement itself already uses
typez instanceof EdgeType edgeType && edgeType.isLightweight() a few lines above, so the file is already
inconsistent with itself. Replace all four occurrences. Note this will make the refusal start firing on
databases where it never has, which is the point, but it is a behaviour change worth calling out in the release
notes; the escape hatch (UNSAFE) already exists and is already named in the message.

While there, either extend the #7919 regression test to a hierarchy with no type called E in it, or it will go
on passing through the next rewrite of this block.

Scope / confidence

Reproduced end to end, both the vertex and the edge arm, both the direct and the polymorphic form, plus the
positive control that shows the guard works when a type named V is present. Tried to refute it by checking
whether LocalVertexType/LocalEdgeType override isSubTypeOf (they do not - the only implementation is
LocalDocumentType's, matching by name) and whether the engine registers implicit V/E types at database
creation (it does not - VB.getSubTypes()/getSuperTypes() show an empty parent list for a freshly created
vertex type).


Activity

  1. added
    engine
    severity:critical
    on Sep 21, 2026
  2. added this to the 26.10.1 milestone on Sep 21, 2026
  3. added
    in progress
    on Sep 21, 2026
  4. self-assigned this
    on Sep 21, 2026
  5. lvca commented on Sep 21, 2026

    @lvca
    Member

    Fixed in #8094, released in 26.10.1.

    TRUNCATE TYPE is supposed to refuse to empty a non-empty vertex or edge type unless you add the UNSAFE keyword, and the error message says exactly that. That safety net never worked: the check asked whether the type inherited from types named V or E, which is an OrientDB convention that does not exist in ArcadeDB. So for every vertex and edge type you create, the check silently answered "no" and the truncate went ahead.

    In practice a single TRUNCATE TYPE Person emptied a live vertex type and detached every edge on it, without ever asking for the UNSAFE you were told was required. TRUNCATE BUCKET did refuse on the same data, which is what made the inconsistency visible.

    The check now asks what the type actually is. It also looks at the whole type hierarchy below the one being truncated, not just its direct children, and names the type that actually holds the records.

    Please note this is a behaviour change: TRUNCATE TYPE will now start refusing on databases where it previously succeeded. That is the intent. If you want the old behaviour, add UNSAFE:

    TRUNCATE TYPE Person UNSAFE

    ❤️ 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.

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

Metadata

Metadata

Assignees

Labels

bugengineseverity:criticalsql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions