Skip to content

feat(retrieval): branch delta, survivors, comparison, nearest and after - #117

Merged
venkat1701 merged 6 commits into
mainfrom
feature/branch-retrieval
Nov 23, 2026
Merged

venkat1701 merged 6 commits into
mainfrom
feature/branch-retrieval

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

Stacked on #115: it reuses the change-feed fold and lineage from #115. Merge #115 first, then retarget this to main.

This adds five read-only statements about branches. Like DIFF and HISTORY, they are for global admins only.

Statement Answers
BRANCH DELTA b [SINCE GENERATION g] what b changed since its fork (or since g): one row per incidence, atom or property, with values before and after
BRANCH SURVIVORS b the entries of b's head untouched since the fork
COMPARE BRANCH b AND c every entry either branch changed since their common ancestor, classed ONLY_LEFT, ONLY_RIGHT, BOTH_SAME or BOTH_DIFFERENT
NEAREST BRANCH TO b [AMONG (…)] TOP k other branches ranked by the number of differing entries
BRANCH AFTER b GENERATION g [WINDOW w] later commits on b that touched an atom commit g touched; this shows what came after, not what was caused

Every statement except AFTER accepts SCOPE INCIDENCES | TYPE T | AROUND @atom. The syntax is open for renaming before merge.

How it is answered

  • A side's net change comes from the ancestor snapshot while it is retained. Otherwise it comes from the change feed, folded over the branch's lineage into the first value before and the last value after for each entry. Both routes return the same rows.
  • An ancestor that is neither retained nor covered by the feed is an error that names the generation.
  • NEAREST diffs the heads directly and skips candidates whose lower bound (difference in incidence or type counts) cannot beat the k-th best.

Testing

  • Full build: engine 269, database 192, server 41, all passing.
  • Randomized histories: histories of 300 to 500 commits over four branches (nested and siblings), compared against snapshot-to-snapshot diffs of every atom, incidence and property. Delta is checked on both routes, then compare, survivors, nearest under three scopes, and after.
  • Mutation checks: a fold keeping the wrong "before", same and different swapped, and an over-large lower bound each make a test fail.

Independent review. It found three important issues, fixed here with tests that failed first:

It also found several smaller issues, fixed and tested here: comparing a branch with itself, a SINCE in the future, AFTER on another branch's commit, a negative WINDOW, repeated AMONG names, and bounds taken from a different snapshot than distances.

Not done here

  • A changed type or key on an existing atom is reported by the feed route only. Only engine-level updateAtom can cause one today.
  • These statements ignore an AT GENERATION pin.
  • Atom values show type ids rather than names.

Five read-only statements for global admins answer what a branch changed
since its fork (BRANCH DELTA), what in its head is untouched since then
(BRANCH SURVIVORS), how two branches diverged from their common ancestor
(COMPARE BRANCH), which branches are closest to one (NEAREST BRANCH) and
which later commits touched the atoms of a given commit (BRANCH AFTER).

An entry is an incidence, an atom or one property. A side's net change
comes from the ancestor snapshot when it is retained and otherwise from
the change feed folded over the branch's lineage; both give the same rows.
NEAREST diffs heads directly and prunes candidates with a lower bound
from root counts. Commits that changed nothing have no feed event, and
BRANCH AFTER on one returns no rows.

No issue tracks this work.
Moving a member of an ordered edge changes only its position label, which
is not part of an entry; the snapshot route reported it as a change while
the feed route did not, and now neither does. Ancestors and lineages are
resolved over every branch record, so a branch whose parent was merged or
dropped no longer fails or loses its parent's history. Every member
change, expanded deletion, feed change and scanned entry now counts
against the budget.

Comparing a branch with itself returns nothing, a SINCE generation in the
future and BRANCH AFTER on another branch's commit are refused, WINDOW
must not be negative, AMONG ignores repeated names, and NEAREST takes its
bounds and distances from the same snapshots.

No issue tracks this work.
@venkat1701
venkat1701 changed the base branch from feature/temporal-retrieval to main November 23, 2026 10:53
# Conflicts:
#	database/src/main/java/io/hstore/db/query/Ast.java
#	database/src/main/java/io/hstore/db/query/Executor.java
#	database/src/main/java/io/hstore/db/query/Parser.java
#	server/src/main/java/io/hstore/server/StatementLogger.java
@venkat1701
venkat1701 merged commit 40895df into main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant