Skip to content

fix(#12774): a derived index name is not carried in the index metadata, so a rename cannot leave it stale for TRUNCATE TYPE - #12784

Merged
lvca merged 1 commit into
ArcadeData:mainfrom
shaunpatterson:fix/12774-stale-index-name-after-truncate
Nov 24, 2026
Merged

lvca merged 1 commit into
ArcadeData:mainfrom
shaunpatterson:fix/12774-stale-index-name-after-truncate

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

What does this PR do?

An index name that equals the name derived from the type and the properties is no longer stored as the typeIndexName of the index metadata when the index is built; only a name that differs from it (a manual name) is.

  • LocalDocumentType.manualIndexName(typeName, propertyNames, family, name) (new): name when it differs from defaultIndexName(...), null otherwise.
  • TypeIndexBuilder.create() and BucketIndexBuilder.create() store manualIndexName(...) instead of the raw name handed through withIndexName.

Motivation

#12774: after REBUILD INDEX, ALTER TYPE D NAME Dren and TRUNCATE TYPE Dren, an LSM_SPARSE_VECTOR index came back as D[tk,wt] on type Dren, flagged as a manual name, so it was persisted that way and survived a reopen. vectorSparseNeighbors('D[tk,wt]', ...) then failed with Type with name 'D' was not found, and a new type D could not get the same sparse index (AlreadyExistsException: Index 'D[tk,wt]' already exists).

REBUILD INDEX hands the TypeIndex name back through withIndexName, which the builders stored as the typeIndexName of the bucket-level metadata. The rename moves the TypeIndex and the sub-indexes' typeName, and leaves that stored name at the old derived one. TRUNCATE TYPE re-creates the index from getMetadataForNewFile(), which carries the stale name, and LocalDocumentType.addIndexInternal compares it with the name derived from the CURRENT type name: they differ, so it takes it for a manual name. Confirmed by running the sequence on main: the same stale name is reached by CREATE INDEX D[tk,wt] ON D (tk, wt) LSM_SPARSE_VECTOR (the derived name spelled out), a rename and a truncate, with no REBUILD at all.

The fix is on the producing side (option 2 of the issue, applied where every caller meets it): the derived name never enters the metadata, so there is nothing for a rename to leave behind. RebuildIndexStatement and DatabaseChecker keep handing the name back, which still keeps a manual name through a REBUILD (#5791, #4139) and renames a derived one with the type (#10751). Nothing changes on a hot path: the comparison runs once per index build.

Related issues

Fixes #12774

Additional Notes

New test Issue12774StaleIndexNameAfterTruncateTest (8 tests, engine):

  • sparseIndexKeepsDerivedNameAfterRebuildRenameTruncate: the sequence of the issue; Dren[tk,wt] on Dren after the truncate and after a reopen, a new type D takes its own sparse index, vectorSparseNeighbors('Dren[tk,wt]', ...) answers over the renamed type and D[tk,wt] over the new one, DROP TYPE Dren leaves D[tk,wt].
  • sparseIndexNamedByTheUserKeepsItsNameAfterRebuildRenameTruncate: CREATE INDEX myname ON D (tk, wt) LSM_SPARSE_VECTOR keeps myname through rebuild, rename, truncate and reopen, and answers vectorSparseNeighbors('myname', ...).
  • indexNamedLikeTheDerivedOneFollowsTheRenameAfterTruncate: the derived name spelled out in CREATE INDEX follows the rename (no REBUILD involved).
  • everyKindKeepsDerivedNameAfterRebuildRenameTruncate (5 kinds: NOTUNIQUE, FULL_TEXT, GEOSPATIAL, LSM_VECTOR, LSM_SPARSE_VECTOR): derived name after the sequence and after a reopen. Only the sparse vector one was wrong on main.

On origin/main (dc07b20) 3 of the 8 fail (the sparse vector ones, D[tk,wt]@Dren instead of Dren[tk,wt]@Dren); with the fix all 8 pass.

Second run, 165 tests, 0 failures: LSMTreeIndexTest, ManualIndexNameGuardTest and the CheckDatabase* classes.

Neighbours run with the fix, 271 tests, 0 failures: Issue12774StaleIndexNameAfterTruncateTest, RebuildIndexPreservesNameTest, TypeRenameTest (incl. nested), CheckDatabaseFixPreservesIndexMetadataTest, CreateIndexIfNotExistsTest, TypeCreationTest, TruncateType4817Test, TruncateTypeIndexBug4352Test, TruncateTypeVectorIndexBug4359Test, TruncateTypeStatementTestParserTest, RebuildIndexTest, RebuildIndexInPlaceTest, RebuildIndexInPlaceKindsTest, RebuildIndexOrphanBucketTest.

Checklist

  • I have run the build using mvn clean package command
  • My unit tests cover both failure and success scenarios

…ex metadata, so a rename cannot leave it stale for TRUNCATE TYPE
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8cab0b48-88c5-470b-97d0-223628e2f4e5
Commits

Reviewing files that changed from the base of the PR and between dc07b20 and 026ea76.

Files selected for processing: 4

  • engine/src/main/java/com/arcadedb/schema/BucketIndexBuilder.java
  • engine/src/main/java/com/arcadedb/schema/LocalDocumentType.java
  • engine/src/main/java/com/arcadedb/schema/TypeIndexBuilder.java
  • engine/src/test/java/com/arcadedb/schema/Issue12774StaleIndexNameAfterTruncateTest.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@github-actions github-actions Bot added engine Core engine: document/schema API has-issue The PR links an issue it resolves severity:minor Cosmetic, documentation, edge case, or a workaround exists triage:lgtm PR triage: nothing blocking, ready for a maintainer labels Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:lgtm · severity:minor · areas: engine · has-issue

The fix is small and targeted. It adds LocalDocumentType.manualIndexName(...), and TypeIndexBuilder.create() and BucketIndexBuilder.create() use it. An index name equal to the derived one is no longer stored as typeIndexName in the index metadata, so a type rename cannot leave a stale name for TRUNCATE TYPE to read as a manual name (#12774). I did not run any of the code or tests.

Minor note: the checklist item for running mvn clean package is unchecked. Run it before merging, along with the neighbouring schema and index tests the description lists.

shaunpatterson added a commit to shaunpatterson/arcadedb that referenced this pull request Nov 24, 2026
@lvca lvca self-assigned this Nov 24, 2026
@lvca lvca added this to the 26.12.1 milestone Nov 24, 2026
@lvca lvca added the pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head label Nov 24, 2026
@lvca
lvca merged commit f34874c into ArcadeData:main Nov 24, 2026
28 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Core engine: document/schema API has-issue The PR links an issue it resolves pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head severity:minor Cosmetic, documentation, edge case, or a workaround exists triage:lgtm PR triage: nothing blocking, ready for a maintainer

Projects

None yet

2 participants