Repository navigation
Description
Two loose ends around BucketSelectionStrategy, both found while working on #5603 (PR #5605) and both left out of it deliberately: the first predates that change, the second is a gap its refusal cannot close on its own. Ordered by severity.
-
1.
ALTER TYPE ... BucketSelectionStrategyis not persisted, so a partitioned type reverts toround-robinafter a restartThe strategy is set in memory and nothing writes it out.
schema.jsongains nobucketSelectionStrategyentry unless some later schema mutation happens to flush the configuration:before close = partitioned schema.json has bucketSelectionStrategy = false after reopen = round-robinReproduced with:
CREATE DOCUMENT TYPE P BUCKETS 3; CREATE PROPERTY P.k STRING; CREATE INDEX ON P(k) UNIQUE; ALTER TYPE P BucketSelectionStrategy `partitioned('k')`; -- close, reopen: P is round-robin again
This is arguably worse than the bug Partitioned bucket strategy: follow-ups from #5589 / #5595 #5603 fixed, because it hits a suitable partition: a correctly configured type silently loses its pruning across a restart, and new records are placed round-robin among rows that were placed by the partition hash. Nothing warns, and
SELECT ... WHERE k = ?simply gets slower.Where it comes from. Every other schema mutator calls
schema.saveConfiguration()itself -LocalDocumentTypedoes at lines 223, 355, 702 and 1427,LocalPropertyat 64 and 90, plusTypeBuilderandBucketIndexBuilder.setBucketSelectionStrategyis the one that does not. The asymmetry is stark inside the same class:setNeedsRepartition(line ~696) saves on every real transition, so the flag about the partitioning persists while the partitioning itself does not.The existing comment in
setBucketSelectionStrategyalready anticipated this exact fragility:Direct field assignment would only work because the wrapping DDL happens to save the schema afterward; relying on that is brittle.
Not caused by fix(engine) #5603: refuse a partition key whose bucket is not a function of the index key #5605 - reproduced identically with that PR's three main-source files stashed. It is why
PartitionedStrategySuitabilityTest.theFanOutWarningIsNotRepeatedOnEveryReopencallssaveConfiguration()explicitly instead of relying on the DDL, with a comment saying so; that workaround should come out when this is fixed.Worth deciding whether the fix is a
saveConfiguration()in the setter (matching every sibling mutator) or a sweep for other DDL paths mutating schema state without persisting it -setBucketSelectionStrategymay not be the only one. -
2. Creating or recollating an index on an already-partitioned type can disable pruning with no warning
Partitioned bucket strategy: follow-ups from #5589 / #5595 #5603 refuses an unsuitable partition at assignment time, but the same state is reachable by reordering the DDL: attach the strategy first, then create the index that makes it unprunable.
ALTER TYPE T BucketSelectionStrategy `partitioned('name')`; -- accepted DROP INDEX `T[name]`; CREATE INDEX ON T (name COLLATE CI) UNIQUE; -- now unprunable, silently
Correctness holds - the strategy declines to prune, so lookups fan out and
UNIQUEstays global - and the state is reported on the next database open, since the blocker warning fires on reload. But between theCREATE INDEXand the next restart nothing says the partitioning stopped doing anything. The same applies to adding an index on non-partition properties, which draws the fan-out advisory at assignment time but not when the index arrives later.PartitionedBoxedKeyLookupTest.aCaseInsensitivePartitionIndexStillFindsEverySpellingdeliberately builds the state this way, so there is already a test standing on the sequence.Why it was left out of fix(engine) #5603: refuse a partition key whose bucket is not a function of the index key #5605. The natural hook,
LocalDocumentType.addIndexInternal, runs once per bucket, so warning there would emit N lines per index creation and would also fire during schema reload. The right place is the DDL/builder layer (TypeIndexBuilder/CreateIndexStatement), which runs once - a wider change than that issue called for.PartitionedBucketSelectionStrategy.checkSuitability()already returns exactly the blockers and warnings such a hook would need to report, so the diagnosis half is done.
Both are follow-ups to the partitioned-strategy series: #5589 (PR #5591), #5595 (PR #5598), #5603 (PR #5605).
Activity
fix(engine) #5637: persist the partition strategy, and report the ind…
fix(engine) #5637: address the code review on #5644
fix(engine) #5637: address the second code review round on #5644
fix(engine) #5637: address the third code review round on #5644
fix(engine) #5637: address the fourth code review round on #5644
docs(engine) #5637: record why DROP INDEX does not re-run the partiti…
docs(engine) #5637: record the inheritance-path exception-type check …
fix(engine) #5637: persist the partition strategy, and report the ind…
lvca commentedon Jul 31, 2026
Fixed by #5644, merged as 9143995.
Item 1 - the strategy is not persisted. Fixed as proposed, but not by either of the two options the issue weighed. The sweep found no second offender:
setBucketSelectionStrategyreally was the only schema mutator not writing its own change. And the baresaveConfiguration()in the setter turned out to be the thing that creates a third fault (below), so it ships together with a change to how the strategy is bound. The save is skipped underisReadingFromFile()- without that guard every open of a partitioned database rewrites an identicalschema.json, because a save during load only marksdirtyGenerationand the loader flushes it on the way out. Two further redundant writes are also skipped: the one theneedsRepartitionflip already made in the same call, and the one an enclosingrecordFileChangeswill make (the supertype-inheritance path).The fix is on the mutator rather than on
partitioned, sothreadstops being lost across a restart on the same terms.round-robinis the default and stays deliberately absent fromschema.json, which is how reverting to it persists.The
saveConfiguration()workaround inPartitionedStrategySuitabilityTest.theFanOutWarningIsNotRepeatedOnEveryReopenis gone, as this issue asked.Item 2 - a post-hoc index change can disable pruning silently. Fixed at the layer the issue identified:
TypeIndexBuilder.create(), once perCREATE INDEXrather than once per bucket, and it does not fire during schema reload (index restore goes throughaddIndexInternal/setMetadata, not the builder). It reports and never refuses - at assignment time the strategy is what was asked for and a blocked one is pure cost, whereas here the index is what was asked for and it is useful, so the partitioning is what gives way. An index change that leaves the partition exactly as suitable as it was stays quiet.DROP INDEXdeliberately does not call it, which leaves one case reported only at the next open: dropping the partition index and not recreating it. Hooking the drop would announce "there is no unique automatic index" in the middle of a recollate - which is a drop followed by a create - printing a line that is true for an instant, misleading by the time it is read, and ahead of the accurate one the create emits. Filed as #5646; the real fix is deferring the diagnosis to the end of the enclosing transaction, not moving the hook.A third fault, reachable only once item 1 landed. Binding the strategy demanded the unique automatic index on every rebind, including the one the schema loader performs on every open. With the strategy now actually reaching
schema.json, aDROP INDEXon the partition key made the next open throw from insidereadConfiguration- which aborts everything the loader has not reached yet: the remaining types' strategies, the triggers, the function libraries, the extensions, and the compaction file-migration map WAL recovery redirects through. It surfaced only asError on loading schema. The schema will be reset.Binding no longer validates anything. The requirement moved into
checkSuitability(), which still refuses it at assignment time and now only warns on load, so the type keeps its partitioned placement and records written after the index was dropped still land where a lookup would look for them.LocalSchemaadditionally isolates a per-type strategy failure, so any other unusable strategy - an implementation class that no longer resolves, say - costs that one type its pruning instead of the rest of the schema, and the log level separates an expected refusal (WARNING) from a fault in the bind path (SEVERE).Suitability.canPrune()is renamedisUsable(): a missing partition index does not stop the strategy computing a bucket, it removes the index lookup that would have been pruned, so the old name no longer described the whole set. Worth knowing that a partitioned type with no index still prunes a plainWHERE k = <literal>scan throughSelectExecutionPlannerand the CypherPartitionPruningrule.Also filed: #5645. Found while covering the inheritance path.
CREATE DOCUMENT TYPE Derived EXTENDS Baseon a partitionedBasecrashes on the first indexed insert, becauseTypeIndex.getIndexesByKeysderives a bucket index from the parent's modulus and then applies it to each subtype's own bucket list. It predates the whole partitioned-strategy series and nothing in #5644 touches it. The direction of the mismatch decides the symptom: a subtype with fewer buckets throws, one with more silently prunes to a bucket the record was never placed in - the #5589 failure mode again.merge main into issue-5636: main's #5639 supersedes this PR's depende…
fix(engine) #5637: persist the partition strategy, and report the ind…
fix(#6359): the super type link is handed back on every refusal, not …
fix(#6359): the propagated indexes go back on every refusal too, not …
fix(#6359): a propagated index joins the transaction that wrote the r…