Skip to content

Schema: REBUILD INDEX then ALTER TYPE NAME then TRUNCATE TYPE leaves a sparse vector index named after the old type, and CREATE INDEX on a new type of that name is refused #12774

Done

Description

@shaunpatterson

Summary

After REBUILD INDEX on an LSM_SPARSE_VECTOR index, a rename of its type and a TRUNCATE TYPE, the index is re-created under the OLD type name: D[tk,wt] on a type now called Dren, flagged as a manual name, so it is persisted that way and survives a reopen. The consequences are visible: vectorSparseNeighbors('D[tk,wt]', ...) answers SchemaException: Type with name 'D' was not found for the name the catalog prints, and creating a new type D with the same sparse index is refused with AlreadyExistsException: Index 'D[tk,wt]' already exists.

Cause: REBUILD INDEX hands the TypeIndex name back as typeIndexName in the bucket-level index metadata (RebuildIndexStatement.java:568, :578). LocalDocumentType.addIndexInternal (LocalDocumentType.java:2822) knows that "a REBUILD hands the derived name back as the custom one, and it is no manual name: a rename of the type has to move it" and compares the custom name with the name derived from the CURRENT type name to tell a manual name apart. The rename moves the TypeIndex (TypeIndex.updateTypeName, TypeIndex.java:832) but leaves typeIndexName in the sub-index metadata at the old derived name. When TRUNCATE TYPE re-creates the sparse index from that metadata, the stale name no longer equals the derived one (Dren[tk,wt]), so it is taken for a manual name and the TypeIndex is minted under it (new TypeIndex(manualName ? customName : derivedName, this, manualName)), and from then on hasManualName() makes it persist (LocalDocumentType.java:3422).

How it is reached

Plain SQL, any protocol: REBUILD INDEX (or REBUILD INDEX *) at some point in the life of the index, ALTER TYPE x NAME y, then TRUNCATE TYPE y. Found by a model-based fuzz of index kinds (FULL_TEXT, GEOSPATIAL, LSM_VECTOR, LSM_SPARSE_VECTOR) with random create/drop/rebuild/rename/truncate/reopen.

Reproduce

origin/main dc07b20.

CREATE DOCUMENT TYPE D
CREATE PROPERTY D.id INTEGER
CREATE PROPERTY D.tk ARRAY_OF_INTEGERS
CREATE PROPERTY D.wt ARRAY_OF_FLOATS
CREATE INDEX ON D (tk, wt) LSM_SPARSE_VECTOR METADATA { dimensions: 8 }
INSERT INTO D SET id = 1, tk = [1,2], wt = [1.0, 2.0]      -- in a transaction
REBUILD INDEX *
ALTER TYPE D NAME Dren
TRUNCATE TYPE Dren
SELECT name, typeName FROM schema:indexes
-- {"name":"D[tk,wt]","typeName":"Dren"}      expected "Dren[tk,wt]"
-- the same after a reopen
CREATE DOCUMENT TYPE D
CREATE PROPERTY D.tk ARRAY_OF_INTEGERS
CREATE PROPERTY D.wt ARRAY_OF_FLOATS
CREATE INDEX ON D (tk, wt) LSM_SPARSE_VECTOR METADATA { dimensions: 8 }
-- AlreadyExistsException: Index 'D[tk,wt]' already exists
SELECT expand(vectorSparseNeighbors('D[tk,wt]', [1], [1.0], 5))
-- the same name over the new type D: CommandSQLParsingException: No sparse vector index found on properties 'tk,wt' for type 'D'

Without the REBUILD INDEX the name is right after the same rename and truncate (Dren[tk,wt]). An LSM_TREE index named Dren[g] survived the same sequence in the fuzz run (the vector and sparse vector paths are the ones that re-create the TypeIndex from the sub-index metadata on truncate).

Version

origin/main dc07b20 (26.12.1-SNAPSHOT).

Options

  1. Rename moves the sub-indexes' typeIndexName along when the TypeIndex has no manual name (TypeIndex.updateTypeNameOfSubIndexesOn / IndexInternal.updateTypeName): clear it, so the next mint derives the name from the current type.
  2. Do not hand the derived name back from REBUILD: pass typeIndex.hasManualName() ? name : null at RebuildIndexStatement.java:568/578 and DatabaseChecker.java:626.
  3. In addIndexInternal ignore a custom name whose derivation under SOME earlier name of the type is the custom name (not available: the history is not kept), so 1 or 2 is the fix.

Activity

  1. added
    engine
    severity:minor
    vector
    in progress
    on Nov 21, 2026
  2. added this to the 26.12.1 milestone on Nov 21, 2026
  3. self-assigned this
    on Nov 24, 2026
  4. added a commit that references this issue on Nov 24, 2026
  5. lvca commented on Nov 24, 2026

    @lvca
    Member

    Fixed by #12784, shipping in 26.12.1.

    What was wrong

    After REBUILD INDEX, a rename of the type (ALTER TYPE D NAME Dren) and a TRUNCATE TYPE, an LSM_SPARSE_VECTOR index came back named after the old type: D[tk,wt] on a type now called Dren. That name was saved, so it also survived a restart. As a result vectorSparseNeighbors('D[tk,wt]', ...) failed with Type with name 'D' was not found, and a new type D could not get the same sparse index (Index 'D[tk,wt]' already exists).

    What changes for you

    An index that has the default name now follows the type through the rename and the truncate: it is Dren[tk,wt] afterwards, also after a restart, and the old name is free for a new type. An index you named yourself keeps its name, as before.

    One side effect: an index created by spelling the default name out (for example CREATE INDEX `D[tk,wt]` ON D (tk, wt) LSM_SPARSE_VECTOR) is now treated like any index with the default name, so it follows a rename of the type.

    The fix prevents the wrong name from being created. It does not rename an index that already came out with the old name in an existing database: drop it and create it again.


    ❤️ 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 Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineseverity:minorsqlvector

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions