Repository navigation
A revision lookup by id or by identity sends only the branch it has rows for - #2187
Merged
Merged
Conversation
…ows for Beside an `IN` over an empty list, ClickHouse 26.4 cannot prune the other branch by the sorting key or the `memory_id` index, and reads the whole namespace. `reads.live_revisions` builds its statement from the lists that name a row: ids alone, identities alone, or both joined by `OR`. The answer, the tenant and read-scope clauses and the `LIMIT` are the same on each. On 26.4 with 200,000 rows in one namespace, an identity-only call for two rows reads 256 rows where the joined statement reads 200,896, and an id-only call reads 9,728. A call that names rows both ways sends the joined statement and reads the namespace. The stubs of the namespace.audit and namespace.validate tests recognise the citation read by its select list, which every shape carries. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
On ClickHouse 26.4, the read that resolves the rows a
namespace.audit,namespace.validate,namespace.tuneormemory.inspectreport cites does not read the whole namespace when the report names its rows by id only or by identity only: 256 rows, not 200,896, for two identities in a namespace of 200,000 rows.Why
reads.live_revisionsresolves the rows a report cites: bymemory_id, by full identity(agent, user_id, session_id, memory_key), or by both. It sent one statement for every call,with an empty array bound for a list that names no row. On ClickHouse 26.4, the oldest release Loom runs on, that statement reads the whole namespace.
EXPLAIN indexes = 1on the identity-only call shows the primary key condition asorgandnamespacealone and 1,563 of 1,563 granules selected; with the identity branch alone the condition holds the identity set and 2 granules are selected. An id-only call reads the namespace the same way, where thememory_idbranch alone reads 9,728 rows. On the latest release (26.11.10.7) the joined statement with the id list bound empty reads 512 rows for the same identity-only call.The statement is built from the lists that name a row: ids alone, identities alone, or both joined by
OR. A call with both lists empty returns no row and sends no statement, as before. The select list, theorg,namespaceand tombstone predicates, the read-scope clause and theLIMITare the same on each shape, and so is the answer.Alternative and its cost: one statement per list would let a call that names rows both ways prune too, at a second round trip for that call. This change keeps one statement per call.
Scope and risk
live_revisionsinserver/memory/store/reads.pyand nothing else in the server. Its callers (finding_evidence.revisions_for, and through it the four ops above) are unchanged, and no op answer changes.org = {org:String} AND namespace = {ns:String},tombstoned_at IS NULLandscope_and(scope, params). The statement test asserts all three on each shape, and the clickhouse-local test reads each shape over the whole namespace and inside one user's scope, with another namespace's row and another user's row in the table.tests/analyzer/shapes.txtgains the two new statement shapes; the joined shape keeps its digest.tests/unit/test_namespace_audit.pyandtests/unit/test_namespace_validate.pyrecognised the citation read by the text of its identity branch, which an id-only call does not carry; they recognise it by its select list, which every shape carries. One assertion of the audit test, that an id-only read bindsidentitiesto an empty list, becomes that it binds noidentitiesparameter. The analyzer casememory_repo.live_revisionsintests/analyzer/cases/legs.pydrives the read by id, by identity and by both, which renders the two new shapes.Compatibility, rollout and rollback
Tests
New, in
tests/unit/test_live_revisions.py:test_an_empty_list_sends_no_branch_for_it(three cases: ids, identities, both): fails when the statement holds anINover a list bound empty, when a branch for a named list is missing, or when the tenant predicates, the scope clause or theLIMITleave a shape.test_both_lists_empty_runs_no_statement: fails when a statement is sent.test_each_shape_returns_the_rows_of_the_joined_form(three cases, on clickhouse-local against theloom.memorydefinition ofschemas/schema.sql): fails when a shape drops or adds a row against the joined statement with the unnamed list bound empty. The table holds a row at two versions, a tombstoned row, a second user's row, an unnamed row and another namespace's row named by id and by identity; each case reads over the whole namespace and inside one user's scope and compares with the expected rows too.Against
live_revisionsasmainhas it: 2 failed (the id-only and identity-only cases of the first test), 5 passed. With the change: 7 passed with theclickhousebinary of 26.4.5.143 and of 26.11.10.7; 4 passed, 3 skipped without the binary.Measurement, on a ClickHouse started with
dev/ci_start_clickhouse.shand migrated withmake migrate, 200,000 rows in one namespace in one part (1,563 granules of 128 rows), a call for two rows:read_rowsTo reproduce: seed with
then call
reads.live_revisions('measure-org', 'measure-ns', scope=WHOLE_NAMESPACE, hash_max_bytes=0, ...)underquery_tag(...)for keysk/0000042andk/0150000(by their two identities, by their two ids, and by the id of one with the identity of the other), runSYSTEM FLUSH LOGS, and readThe first column of the table is the same calls at
main's commit, before the edit.Run locally with
pytest -n 2:clickhousebinary of 26.11.10.7:tests/unit/test_live_revisions.pywith the unit tests of the callers (test_namespace_audit.py,test_namespace_validate.py,test_memory_inspect.py,test_namespace_tune.py,test_pg_authority.py), in random order: 558 passed.tests/analyzeragainst the migrated ClickHouse (26.11.10.7): 12 passed.python -m tests.analyzer.corpus --writewrote the two new lines oftests/analyzer/shapes.txt.clickhousebinary: the repository-wide scans (package contracts, op transports, tunable constants, store names, degradation notes, public copy, doc links, agent instructions) withtests/analyzer: 601 passed, 12 skipped (10 need the binary, 2 need a migrated ClickHouse).ruff format --check .,ruff check(themake lintpaths),make typecheck, the function-length and secret gates pass at this head. So does every generator check ofmake lintexcept the Rust and Go SDK generators:rustfmtandgofmtare not installed on this machine, no op or wire field changes, and CI runs them. The Biome lint offrontend/srcwas not run: no frontend file changes.make formatwas not run as a whole:shfmtis not installed, and the diff holds Python files and one generated list.main. The rebase brought in one commit, which touches none of this change's files except other lines oftests/analyzer/shapes.txt.clickhousebinary of 26.11.10.7: 601 passed.tests/integration/test_namespace_findings_contract.py, 5 passed.test_the_citation_read_resolves_ids_and_identitiescallslive_revisionson the live store by id only, by identity only and under another user's scope, so both new shapes ran there. Withtest_memory_inspect.pyandtest_findings_labeled_cases.py(-m "not slow and not destructive"): 7 passed, 1 skipped;test_namespace_tune.py: 1 passed, 1 skipped. Both skips need a server that enforces auth.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff, the tests and this description, ran the checks listed under Tests and took the measurement.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code