Skip to content

Partitioned types: the strategy is not persisted, and a post-hoc index change can still disable pruning silently #5637

Closed

Description

@lvca

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 ... BucketSelectionStrategy is not persisted, so a partitioned type reverts to round-robin after a restart

    The strategy is set in memory and nothing writes it out. schema.json gains no bucketSelectionStrategy entry unless some later schema mutation happens to flush the configuration:

    before close    = partitioned
    schema.json has bucketSelectionStrategy = false
    after reopen    = round-robin
    

    Reproduced 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 - LocalDocumentType does at lines 223, 355, 702 and 1427, LocalProperty at 64 and 90, plus TypeBuilder and BucketIndexBuilder. setBucketSelectionStrategy is 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 setBucketSelectionStrategy already 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.theFanOutWarningIsNotRepeatedOnEveryReopen calls saveConfiguration() 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 - setBucketSelectionStrategy may 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 UNIQUE stays global - and the state is reported on the next database open, since the blocker warning fires on reload. But between the CREATE INDEX and 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.aCaseInsensitivePartitionIndexStillFindsEverySpelling deliberately 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

  1. self-assigned this
    on Jul 31, 2026
  2. added this to the 26.8.1 milestone on Jul 31, 2026
  3. added theissue type on Jul 31, 2026
  4. added 8 commits that reference this issue on Jul 31, 2026
  5. lvca commented on Jul 31, 2026

    @lvca
    MemberAuthor

    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: setBucketSelectionStrategy really was the only schema mutator not writing its own change. And the bare saveConfiguration() 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 under isReadingFromFile() - without that guard every open of a partitioned database rewrites an identical schema.json, because a save during load only marks dirtyGeneration and the loader flushes it on the way out. Two further redundant writes are also skipped: the one the needsRepartition flip already made in the same call, and the one an enclosing recordFileChanges will make (the supertype-inheritance path).

    The fix is on the mutator rather than on partitioned, so thread stops being lost across a restart on the same terms. round-robin is the default and stays deliberately absent from schema.json, which is how reverting to it persists.

    The saveConfiguration() workaround in PartitionedStrategySuitabilityTest.theFanOutWarningIsNotRepeatedOnEveryReopen is 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 per CREATE INDEX rather than once per bucket, and it does not fire during schema reload (index restore goes through addIndexInternal/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 INDEX deliberately 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, a DROP INDEX on the partition key made the next open throw from inside readConfiguration - 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 as Error 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. LocalSchema additionally 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 renamed isUsable(): 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 plain WHERE k = <literal> scan through SelectExecutionPlanner and the Cypher PartitionPruning rule.

    Also filed: #5645. Found while covering the inheritance path. CREATE DOCUMENT TYPE Derived EXTENDS Base on a partitioned Base crashes on the first indexed insert, because TypeIndex.getIndexesByKeys derives 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.

  6. added a commit that references this issue on Aug 1, 2026
  7. added a commit that references this issue on Aug 14, 2026
  8. added 3 commits that reference this issue on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions