Skip to content

fix(#12036): ALTER TYPE ... SUPERTYPE + propagates the super type's indexes over the whole joining subtree - #12062

Merged
lvca merged 3 commits into
ArcadeData:mainfrom
shaunpatterson:fix/12036-supertype-subtree-index
Nov 23, 2026
Merged

lvca merged 3 commits into
ArcadeData:mainfrom
shaunpatterson:fix/12036-supertype-subtree-index

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

Root cause

ALTER TYPE A SUPERTYPE +W propagates W's indexes (and those of W's super types) through LocalDocumentType.propagateSuperTypeIndexes / createSubIndexesFor, which walked buckets, the joining type's OWN buckets. The sub types of A join W with it (their records are W records from then on, SELECT FROM W returns them), but their buckets got no sub-index. So a UNIQUE index of W was not enforced for them, SEARCH_INDEX on a FULL_TEXT index and vectorNeighbors on an LSM_VECTOR index never returned them, and SELECT FROM index:... listed nothing for them. A sub type created later and ALTER TYPE A BUCKET +b were fine because both go through addBucketInternal, which propagates getAllIndexes(true) per bucket.

Fix

createSubIndexesFor walks cachedPolymorphicBuckets (the joining type's buckets and those of every type below it, at any depth) instead of buckets, and asks the type that owns each bucket (schema.getBucketOwner) whether the bucket already carries the index, since a sub type's sub-indexes are bound to that sub type (#10412; createBucketIndex already binds a sub type's bucket to its owner under the propagated wrapper). The question of whether the caller's transaction wrote into the scanned buckets (#10450) is asked about the same polymorphic bucket list.

Everything else is the existing path: the components are created in their own transaction, the builds join the caller's transaction, and any failure (a UNIQUE clash between a record of the subtree and one of W, or between two types of the subtree) drops every component created and unlinks the super type (#11302), so the change is refused with nothing changed. This is the same for every index family the propagation handles (LSM_TREE UNIQUE/NOTUNIQUE, BY ITEM, FULL_TEXT, LSM_VECTOR).

Possible textual overlap: a parallel change for #12028/#12029/#12030/#12033/#12034/#12037/#12040 edits LocalDocumentType (schema DDL validation). This change touches only propagateSuperTypeIndexes (one line) and the head of createSubIndexesFor.

Tests

New SuperTypeSubtreeIndexPropagationTest (engine, TestHelper), with a subtree A, X EXTENDS A, Y EXTENDS X, 7 tests:

  • UNIQUE index of W: covers A, X, Y (sub-indexes on all three buckets, lookups find X's and Y's keys), duplicates into X, Y, A refused, also after reopen;

  • NOTUNIQUE index of a super type above W (W EXTENDS V0) covers X and Y;

  • UNIQUE clash between Y and W, and between A and X: DuplicatedKeyException, A not a sub type of W, no sub-index of W[s] left on any bucket of the subtree, also after reopen;

  • BY ITEM, FULL_TEXT (including a record inserted into X after the change) and LSM_VECTOR indexes return the records of every type of the subtree.

  • Failing first: with engine/src/main from origin/main, 7 of 7 fail. With the fix: 7/7 pass.

  • -Dtest='com/arcadedb/schema/**,*SuperType*,*Polymorphic*,*FullText*,*Vector*,*AlterType*,*Inherit*,*Unique*,*TypeIndex*' -DexcludedGroups=slow,benchmark: 3993 tests, 0 failures, 0 errors.

End to end

arcadedata/arcadedb:26.12.1-SNAPSHOT container with this branch's engine jar, the issue's steps over HTTP.

UNIQUE (ALTER TYPE A SUPERTYPE +W, X EXTENDS A):

statement main this branch
schema:indexes A_0_..., W[s], W_0_... (nothing on X_0) A_0_..., W[s], W_0_..., X_0_... (bucket 8)
SELECT key, rid FROM index:`W[s]` a1 #5:0, w1 #1:0 a1 #5:0, w1 #1:0, x1 #8:0
INSERT INTO X SET s = 'w1' 200 accepted 409 DuplicatedKeyException
INSERT INTO X SET s = 'x1' 200 accepted 409 DuplicatedKeyException
INSERT INTO A SET s = 'x1' 200 accepted 409 DuplicatedKeyException
SELECT s, count(*) FROM W GROUP BY s a1 1, w1 2, x1 3 a1 1, w1 1, x1 1
after a restart: INSERT INTO X SET s = 'w1' / REBUILD INDEX `W[s]` 200 accepted / 500 (as measured in the issue) 409 / 200 (totalIndexed: 3)

With X holding w1 before the change, ALTER TYPE A SUPERTYPE +W answers 409 DuplicatedKeyException, A has no super type afterwards and schema:indexes lists only W[s] and W_0_....

Records of A returned / expected (ALTER TYPE W SUPERTYPE +A, X EXTENDS W, 10 records each):

index on A main this branch
FULL_TEXT, SEARCH_INDEX('A[t]', 'alpha') 4 / 6 (X 0/2) 6 / 6
LSM_VECTOR, vectorNeighbors('A[v]', [0.5, 0.5], 100) 20 / 30 (X 0/10) 30 / 30
LSM_TREE NOTUNIQUE, t = 'alpha' 6 / 6 6 / 6
LSM_TREE BY ITEM, tags CONTAINS 'alpha' 6 / 6 6 / 6

Fixes #12036

…r type's indexes over the whole joining subtree
@coderabbitai

coderabbitai Bot commented Nov 15, 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 12 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: 77ee2a04-bb44-4558-b795-51d795457431
Commits

Reviewing files that changed from the base of the PR and between 571f803 and e14b29e.

Files selected for processing: 2

  • engine/src/main/java/com/arcadedb/schema/LocalDocumentType.java
  • engine/src/test/java/com/arcadedb/schema/SuperTypeSubtreeIndexPropagationTest.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 15, 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

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 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

The change is small and targeted. It fixes #12036, where ALTER TYPE A SUPERTYPE +W only put W's indexes on A's own buckets and skipped the buckets of A's sub types.

What changed in LocalDocumentType

Checks and tests

  • By reading LocalDocumentType.java, cachedPolymorphicBuckets is the volatile, recomputed polymorphic bucket cache. I did not run anything.
  • I could not check from the diff that getBucketOwner resolves every bucket in that cache.
  • The new SuperTypeSubtreeIndexPropagationTest has 7 tests. They cover:
    • UNIQUE, with a subtree two levels deep, duplicate rejection, and persistence across a reopen;
    • an index on a super type above W;
    • both UNIQUE clash directions, with rollback;
    • BY ITEM, FULL_TEXT and LSM_VECTOR.
  • The test uses the assertThat style from CLAUDE.md, has no wall-clock assertions and no hardcoded ports.
  • The PR reports 7 of 7 tests failing on main and 3993 related tests passing with the fix. I did not run them.

Security and scope

  • I found no security concerns and no unrelated changes.
  • Performance impact is limited to a DDL path. It does a linear scan over the subtree buckets, which is the expected cost of this operation.

Nit, not blocking: the (owner != null ? owner : this).getPolymorphicBucketIndexByBucketId(...) expression is dense. Pulling the owner into a local variable would make it easier to read.

@github-actions github-actions Bot added triage:lgtm PR triage: nothing blocking, ready for a maintainer and removed triage:lgtm PR triage: nothing blocking, ready for a maintainer labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

The change is small and targeted. createSubIndexesFor now walks cachedPolymorphicBuckets instead of buckets, so the whole joining subtree gets the super type's sub-indexes. The "already carries the index" check now asks the type that owns each bucket, via the existing schema.getBucketOwner, and falls back to this when there is no owner. The callerTransactionHasChangesIn check in propagateSuperTypeIndexes now uses the same polymorphic bucket list. The existing rollback path (#11302) is reused, so a UNIQUE clash anywhere in the subtree refuses the change and undoes it.

The new SuperTypeSubtreeIndexPropagationTest covers UNIQUE, a NOTUNIQUE index on a super type above the new one, rollback on a clash (both against the super type and between two sub types), BY ITEM, FULL_TEXT and LSM_VECTOR. It also reopens the database after the change and after a refusal. It uses TestHelper and assertj in the project's style. I read the diff only and did not run the tests.

Minor, non-blocking:

  • Consider a short comment noting that cachedPolymorphicBuckets must already include the sub types' buckets at this point in propagateSuperTypeIndexes.
  • The ternary inside the for header in createSubIndexesFor is hard to read. Extracting final LocalDocumentType indexOwner = owner != null ? owner : this; would help.

@lvca lvca self-assigned this Nov 23, 2026
@lvca lvca added this to the 26.12.1 milestone Nov 23, 2026
… the reverse and the diamond of the subtree sub-index propagation

Name the type that carries a bucket's sub-index in a local variable in createSubIndexesFor, and add four tests to the regression class: a record of a sub type written in the caller's transaction is indexed and readable through the index before the commit (it fails when the caller-transaction check looks at the joining type's own buckets only), a rolled-back caller leaves the sub-indexes of the whole subtree in place and usable, ALTER TYPE ... SUPERTYPE -W drops them again and frees the key of W, and a sub type that already carries the index through another super type keeps one sub-index (it fails when the bucket owner is not asked).
@github-actions github-actions Bot added triage:lgtm PR triage: nothing blocking, ready for a maintainer and removed triage:lgtm PR triage: nothing blocking, ready for a maintainer labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

The fix is small and correct. createSubIndexesFor now walks cachedPolymorphicBuckets, which covers the joining type and every type below it, instead of only buckets. It looks up each bucket's carrier through schema.getBucketOwner. The caller-transaction check in propagateSuperTypeIndexes uses the same polymorphic list. I did not run anything, so this is from reading the diff and the surrounding code.

  • Duplicates: the already-created check uses the bucket owner, so a sub type that already carries the index through another super type should not get a second sub-index. A diamond test covers this.
  • Rollback: the existing failure path unlinks the super type and drops the created components. Tests cover this for UNIQUE clashes and for a caller rollback.
  • Tests: the new SuperTypeSubtreeIndexPropagationTest covers UNIQUE, NOTUNIQUE on a super type above the new one, BY ITEM, FULL_TEXT and LSM_VECTOR. It also covers rollback, removing the super type again, and reopening the database. It follows the repo's AssertJ style and does not assert on wall-clock time.
  • Scope and conventions: the change touches only the two relevant spots in LocalDocumentType. I found no security concerns, new dependencies, or unrelated changes.

The linked issue is labelled minor, and the diff supports that. It is a narrow edge case: a super type added to a type that already has sub types.

@lvca lvca added the pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head label Nov 23, 2026
@lvca
lvca merged commit 1f02fec into ArcadeData:main Nov 23, 2026
27 of 31 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