Repository navigation
Binding a pushed document's declared phrases counts the base's signatures only for keys not already settled - #1310
Merged
WaylandYang merged 2 commits intoOct 19, 2026
Conversation
…ures only for keys not already settled Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Bogdan Szabo <bogdan@re-cinq.com>
WaylandYang
approved these changes
Oct 19, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
Thank you, the reasoning holds: settled only reaches the key fields through declared and fits_direction, so dropping settled keys before signatures changes nothing except the cost, and the test on a fresh one-connection pool shows the whole-base grouping no longer runs on a settled push. If you touch this again, #[derive(Default)] on PhraseSignature would shrink keyed to a struct update, but it's fine as is. Merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1296 (item 4).
When a pushed document finished extracting,
bind_declaredgathered the document's signature keys whose phrase names a declared relation. Then it calledphrase_bindings::signatures, the GROUP BY over every live open statement in the base, and only after that skipped the signatures whose existing binding was already settled. After the first push of a phrase, every later push with the same phrase and classes is already settled. Each one still grouped the whole base and then wrote nothing.settledonly needs the key and the existing bindings. Throughdeclaredandfits_directionit reads only the phrase, the two class ids and whether the object is a value, and those are exactly the four fields of the key. Sobind_declarednow drops every key whose existing binding is settled before it does anything else. If no keys are left it returns without counting the base's signatures. Otherwise it counts them and filters to the keys that are left, as before. The settled check inside the loop is gone because the keys reaching it can no longer be settled. To run the check from a key, a smallkeyedhelper builds aPhraseSignaturewith only the key's fields filled in. I picked this over a narrower type fordeclared,fits_directionandsettledbecausefits_directionhas six call sites that all pass a full signature. A new type would touch all of them, while the helper adds one function and leaves every caller as it was.Binding behaves the same, so the change only removes cost. That means the test cannot look at the bindings to prove anything; it has to show that the whole-base signatures query was not run. It pushes two documents with the same signature: the first one binds, the second arrives already settled. It then calls
bind_declaredfor the second document on a fresh pool with a single connection. It asserts the call returns 0 and thatpg_prepared_statementson that connection holds no statement containingWITH live AS. sqlx prepares and caches every statement it runs on a connection, so a query that was skipped is absent. This is the same approach as #1307. The probe excludes its own text, because its own LIKE pattern containsWITH live ASand would otherwise match itself. Before the change the test fails with the signatures query listed; after it, it passes.I ran
cargo test -p utopia-serveragainst a migrated Postgres withUTOPIA_TEST_REQUIRE_DB=1: 674 passed, 0 failed, 2 ignored. The phrase tests alone (phrase_filter) are 44 passed.cargo fmt --all -- --checkandcargo clippy -p utopia-server --all-targets -- -D warningsare clean.🤖 Generated with Claude Code