Skip to content

Index create regression #5675

Closed
Closed

Description

@rthuffman

ArcadeDB version

Reproduced on arcadedata/arcadedb:26.7.3 and arcadedata/arcadedb:26.8.1-SNAPSHOT.
Not present on 26.4.1-SNAPSHOT (which errors instead), so this is a behaviour
regression introduced after 26.4.1.

Summary

When a property already carries a NOTUNIQUE index, CREATE INDEX IF NOT EXISTS ... UNIQUE on that same property returns success without creating a unique
constraint. The caller is told the unique index exists; duplicates are then
accepted. Issuing the same statement without IF NOT EXISTS correctly reports
the conflict, so the guard clause is suppressing an error the server already
knows how to raise.
IF NOT EXISTS appears to match on the indexed property set alone and to ignore
the requested uniqueness. It affects plain and BY ITEM indexes equally.

Steps to reproduce

CREATE VERTEX TYPE T;
CREATE PROPERTY T.Scalar STRING;
CREATE INDEX ON T (Scalar) NOTUNIQUE;
-- reports success, but creates no unique constraint
CREATE INDEX IF NOT EXISTS ON T (Scalar) UNIQUE;
INSERT INTO T SET Tag = 'a', Scalar = 'x';
INSERT INTO T SET Tag = 'b', Scalar = 'x'; -- accepted

Expected

Either the unique index is created and the second insert is rejected with
DuplicatedKeyException, or the statement fails because the existing index
conflicts with the requested definition.

Actual

CREATE INDEX IF NOT EXISTS ... UNIQUE returns success. SELECT FROM schema:indexes shows only non-unique indexes on T:
T[Scalar] unique=false
T_0_516462088483265 unique=false
The duplicate insert succeeds.

Contrast: without the guard clause, the conflict is reported

CREATE INDEX ON T (Scalar) UNIQUE;
{"error":"Cannot execute command",
"exception":"com.arcadedb.exception.CommandExecutionException",
"detail":"Index 'T[Scalar]' already exists"}

Also affects BY ITEM

CREATE VERTEX TYPE L;
CREATE PROPERTY L.Items LIST OF STRING;
CREATE INDEX ON L (Items BY ITEM) NOTUNIQUE;
CREATE INDEX IF NOT EXISTS ON L (Items BY ITEM) UNIQUE; -- reports success
INSERT INTO L SET Tag = 'a', Items = ['x'];
INSERT INTO L SET Tag = 'b', Items = ['x']; -- accepted

Not affected: the reverse direction

Creating UNIQUE first and then a guarded NOTUNIQUE leaves the unique
constraint intact and correctly rejects the duplicate.

Behaviour on 26.4.1-SNAPSHOT

The guarded statement fails loudly rather than silently:
{"error":"Error on transaction commit",
"exception":"com.arcadedb.index.IndexException",
"detail":"Error on creating index on type 'T', properties [Items by item]
-> ... Index 'T[Itemsbyitem]' is not valid."}

Impact

Schema-migration DDL commonly uses CREATE INDEX IF NOT EXISTS so it can be
re-applied idempotently. Under that pattern, tightening an index from
NOTUNIQUE to UNIQUE silently does nothing, and the application proceeds
believing a uniqueness constraint protects the data.

Activity

  1. self-assigned this
    on Aug 1, 2026
  2. added theissue type on Aug 1, 2026
  3. added this to the 26.8.1 milestone on Aug 1, 2026
  4. added 5 commits that reference this issue on Aug 1, 2026
  5. lvca commented on Aug 2, 2026

    @lvca
    Member

    Fixed in #5740, merged as 4966b4b. Thanks for the precise report — the contrast you drew between the guarded and unguarded forms, and the note that 26.4.1 failed loudly, is what located this quickly.

    What was wrong. IF NOT EXISTS matched a pre-existing index on the auto-derived index name, and that name is built from the indexed property set alone — it says nothing about what the index does. So a NOTUNIQUE index answered "already there" to a request for a UNIQUE one. Your diagnosis was exactly right.

    What it does now. IF NOT EXISTS is satisfied only when the existing index provides what was asked for: the same index kind, and a uniqueness constraint at least as strong.

    • Your case is now refused, naming both definitions, as HTTP 400: tightening NOTUNIQUE to UNIQUE tells you the existing index is in the way instead of silently doing nothing.
    • The reverse direction you found unaffected stays a no-op, and is now guaranteed to be one: a UNIQUE index indexes the same keys a NOTUNIQUE one would, and it is never weakened into a plain index.
    • The BY ITEM form behaves identically — it was the same bug.
    • An index of a different kind on the same properties (a FULL_TEXT index where a range index was requested) was ignored the same way, and is now reported too.

    Two things your report uncovered that were worse than the symptom. Underneath the guard, the builder reacted to a uniqueness mismatch by dropping the existing index and rebuilding it. When the stored data cannot satisfy the new definition the rebuild fails — and the type is left with no index at all. That path also took away a parent type's index when the index was inherited (#4083). Both are gone: nothing is dropped implicitly, and the one caller that genuinely means "make this the definition" (Cypher CREATE CONSTRAINT ... IS UNIQUE) restores the previous index if the new one cannot be built.

    One thing to know if you use the embedded API. LocalSchema.getOrCreateTypeIndex(...) inherits this: asked for a UNIQUE index where a NOTUNIQUE one exists, it now raises instead of rebuilding. If you were using it as an "ensure/upgrade this index" helper, drop the old index explicitly, or build through buildTypeIndex(...).withReplaceIfIncompatible(true) if replacing is really what you mean. It is flagged as BREAKING in the 26.8.1 release notes because it surfaces at runtime, not at compile time.

  6. lvca commented on Aug 2, 2026

    @lvca
    Member

    Follow-ups from this fix are tracked in #5765 — chiefly that ManualIndexBuilder still carries the same silent drop-and-rebuild and the same dead null-strategy condition that this issue removed from the type-index path.

  7. added a commit that references this issue on Aug 2, 2026
  8. added 2 commits that reference this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions