Repository navigation
fix(#12036): ALTER TYPE ... SUPERTYPE + propagates the super type's indexes over the whole joining subtree - #12062
Conversation
…r type's indexes over the whole joining subtree
|
Warning Review limit reachedYou'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. View limit details
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. |
|
This pull request is merged. |
Up to standards ✅🟢 Issues
|
|
Triage: The change is small and targeted. It fixes #12036, where What changed in
Checks and tests
Security and scope
Nit, not blocking: the |
|
Triage: The change is small and targeted. The new Minor, non-blocking:
|
… 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).
|
Triage: The fix is small and correct.
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. |
Root cause
ALTER TYPE A SUPERTYPE +Wpropagates W's indexes (and those of W's super types) throughLocalDocumentType.propagateSuperTypeIndexes/createSubIndexesFor, which walkedbuckets, the joining type's OWN buckets. The sub types ofAjoinWwith it (their records areWrecords from then on,SELECT FROM Wreturns them), but their buckets got no sub-index. So a UNIQUE index ofWwas not enforced for them,SEARCH_INDEXon a FULL_TEXT index andvectorNeighborson an LSM_VECTOR index never returned them, andSELECT FROM index:...listed nothing for them. A sub type created later andALTER TYPE A BUCKET +bwere fine because both go throughaddBucketInternal, which propagatesgetAllIndexes(true)per bucket.Fix
createSubIndexesForwalkscachedPolymorphicBuckets(the joining type's buckets and those of every type below it, at any depth) instead ofbuckets, 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;createBucketIndexalready 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 onlypropagateSuperTypeIndexes(one line) and the head ofcreateSubIndexesFor.Tests
New
SuperTypeSubtreeIndexPropagationTest(engine,TestHelper), with a subtreeA,X EXTENDS A,Y EXTENDS X, 7 tests:UNIQUE index of
W: coversA,X,Y(sub-indexes on all three buckets, lookups findX's andY's keys), duplicates intoX,Y,Arefused, also after reopen;NOTUNIQUE index of a super type above
W(W EXTENDS V0) coversXandY;UNIQUE clash between
YandW, and betweenAandX:DuplicatedKeyException,Anot a sub type ofW, no sub-index ofW[s]left on any bucket of the subtree, also after reopen;BY ITEM, FULL_TEXT (including a record inserted into
Xafter the change) and LSM_VECTOR indexes return the records of every type of the subtree.Failing first: with
engine/src/mainfromorigin/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-SNAPSHOTcontainer with this branch's engine jar, the issue's steps over HTTP.UNIQUE (
ALTER TYPE A SUPERTYPE +W,X EXTENDS A):schema:indexesA_0_...,W[s],W_0_...(nothing onX_0)A_0_...,W[s],W_0_...,X_0_...(bucket 8)SELECT key, rid FROM index:`W[s]`a1 #5:0,w1 #1:0a1 #5:0,w1 #1:0,x1 #8:0INSERT INTO X SET s = 'w1'DuplicatedKeyExceptionINSERT INTO X SET s = 'x1'DuplicatedKeyExceptionINSERT INTO A SET s = 'x1'DuplicatedKeyExceptionSELECT s, count(*) FROM W GROUP BY sa1 1,w1 2,x1 3a1 1,w1 1,x1 1INSERT INTO X SET s = 'w1'/REBUILD INDEX `W[s]`totalIndexed: 3)With
Xholdingw1before the change,ALTER TYPE A SUPERTYPE +Wanswers 409DuplicatedKeyException,Ahas no super type afterwards andschema:indexeslists onlyW[s]andW_0_....Records of
Areturned / expected (ALTER TYPE W SUPERTYPE +A,X EXTENDS W, 10 records each):ASEARCH_INDEX('A[t]', 'alpha')vectorNeighbors('A[v]', [0.5, 0.5], 100)t = 'alpha'tags CONTAINS 'alpha'Fixes #12036