Skip to content

feat(profiling): tier 2 — what each column would cost as a blocking key (PR D) - #410

Merged
athvin merged 1 commit into
mainfrom
bm/profile-p4-blocking-readiness
Nov 3, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/profile-p4-blocking-readiness

Conversation

@athvin

@athvin athvin commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Dataset profiling, fourth of six. The half aimed at the model rather than the reader: er profile --tier 2 measures what an equi-join on each plausible column would cost, and says which one to block on.

This also gives PR A's estimate_candidate_key / rank_candidate_keys their first product caller. They shipped with none, which this repo's own rule rejects — a declared capability nothing honours is the shape the parity program already found once.

New entity candidate_key

Per key: exact expected_pairs (Σ C(n, 2) over the value groups), the largest block, distinct values, entropy in bits, and pair_loss_from_nulls.

That last one is the number people get wrong. A key reaches only fill² of the corpus's pairs, so a column 60% populated reaches 36% — and the pairs it drops are reported nowhere else. Cost and loss are stored side by side rather than one of them implied, because a cheap key is so often cheap for the wrong reason.

key_columns is chr(31)-joined: it is part of the natural key, and DuckLake has no list equality to MERGE on.

Candidates come from the tier-1 shape, not a blind sweep

A constant column is the cartesian product and a mostly-empty one cannot reach its pairs — both already have their own findings, so spending a GROUP BY to rediscover that would make the deep tier slower for no new information.

Capped at 25, most-selective-first, and the cap is reported: a truncated list that looks complete is how someone ends up trusting a key nobody measured.

A CorpusRule trait beside ColumnRule

The two new findings cannot be answered one column at a time. Whether a corpus is blockable depends on the best column, so a per-column rule would either say nothing or say the same thing twelve times.

Code Severity Invariant
P009 warning at least one column is a usable blocking key on its own
P010 info the most selective usable blocking key is named with its cost

P009 names the closest candidate and suggests a composite key. Two bars rather than one, because the failure modes are opposite: too few comparisons eliminated makes the run quadratic; cheap-because-empty makes it miss most of its pairs.

P010 is deliberately positive and info-severity. A findings panel that only ever reports problems is one people learn to skip, and this is the most actionable line in the whole profile: here is the key to block on, and here is what it will cost.

Three decisions worth a reviewer's attention

P010 names the cheapest VIABLE key, never the cheapest overall. The cheapest key on a real corpus is very often a column that is almost entirely empty, and recommending it would recommend a key that cannot see the data. Pinned by a test: a fax column covering 4% of rows at 500 pairs loses to email at 1,000,000.

The corpus rules stay silent in two cases, each for its own reason. Below ~1000 rows the full cartesian product is cheap, so "no good key exists" is true and useless — a warning on every small dataset teaches people to ignore the panel. And an empty candidate list means tier 2 did not run, not that nothing qualified; that distinction is why findings_with takes an explicit slice rather than an Option, so a tier-1 caller cannot pass nothing and have it read as a verdict.

candidate_keys is created upfront with the other three profile relations rather than lazily on first write, so a reader always finds an empty table instead of a missing one. It therefore joins cli_e2e's fileless list, because er run-all resolves a corpus and does not describe one.

Verification

make check green — read from the log, not the exit status: all six targets, skills-check: ok, 48 entities / 132 generated files current, analyser clean, 91 test binaries, 0 failures.

Five new unit cases cover the corpus rules, including both silence conditions and the cheap-but-blind trap. A new lake e2e (tier_two_measures_candidate_blocking_keys) asserts tier 1 writes no keys at all, tier 2 writes one row per measured key ranked cheapest-first with internally consistent numbers, that tier is part of the profile identity so tier 1 and tier 2 are two rows rather than one overwriting the other, and that a re-measure rewrites rather than duplicates.

Open question for review

I made P009 a warning, consistent with this registry's rule that nothing refuses a corpus. But an unblockable corpus arguably meets the error definition in Severity ("will produce wrong results if left alone") — the run either goes quadratic or silently loses most of its pairs. Happy to promote it; it is a one-line change.

The ~1000-row floor is the least principled number here. It is defensible but it is a judgement call, not a measurement, and the constant's doc comment says so rather than dressing it up.

🤖 Generated with Claude Code

@athvin
athvin force-pushed the bm/profile-p4-blocking-readiness branch 3 times, most recently from d7bc9cb to a2e107a Compare November 3, 2026 02:31
…ey (PR D)

Dataset profiling, fourth of six. The half aimed at the model rather than the
reader: `er profile --tier 2` measures what an equi-join on each plausible
column would cost, and says which one to block on.

This also gives PR A's `estimate_candidate_key`/`rank_candidate_keys` their
first product caller. They shipped with none, which this repo's own rule rejects
— a declared capability nothing honours is the shape the parity program already
found once.

**New entity `candidate_key`.** Per key: exact `expected_pairs` (the sum of
C(n, 2) over the value groups), the largest block, distinct values, entropy in
bits, and `pair_loss_from_nulls`. That last is the number people get wrong: a
key reaches only `fill^2` of the corpus's pairs, so a column 60% populated
reaches 36% — and the pairs it drops are reported nowhere else, which is why the
cost and the loss are stored side by side rather than one of them implied.
`key_columns` is chr(31)-joined because it is in the natural key and DuckLake
has no list equality to MERGE on.

**Candidates come from the tier-1 shape, not from a blind sweep.** A constant
column is the cartesian product and a mostly-empty one cannot reach its pairs;
both already have their own findings, so spending a GROUP BY to rediscover that
would make the deep tier slower for no new information. Capped at 25,
most-selective-first, and the cap is REPORTED — a truncated list that looks
complete is how someone ends up trusting a key nobody measured.

**A `CorpusRule` trait beside `ColumnRule`,** because the two new findings
cannot be answered one column at a time. Whether a corpus is blockable depends
on the BEST column, so a per-column rule would either say nothing or say the
same thing twelve times.

- **P009** — no single column blocks this corpus. Names the closest candidate
  and suggests a composite. Two bars, not one, because the failure modes are
  opposite: too few comparisons eliminated makes the run quadratic, and
  cheap-because-empty makes it miss most of its pairs.
- **P010** — the most selective USABLE key, named with its cost. `info` and
  deliberately positive: a panel that only ever reports problems is one people
  learn to skip, and this is the most actionable line in the profile.

**P010 names the cheapest VIABLE key, never the cheapest overall.** The cheapest
key on a real corpus is very often a column that is almost entirely empty, and
recommending it would recommend a key that cannot see the data. The test pins
it: a `fax` column covering 4% of rows at 500 pairs loses to `email` at
1,000,000.

**Both corpus rules stay silent in two cases, each for its own reason.** Below
~1000 rows the full cartesian product is cheap, so "no good key exists" is true
and useless — a warning on every small dataset teaches people to ignore the
panel. And an EMPTY candidate list means tier 2 did not run, not that nothing
qualified; that distinction is why `findings_with` takes an explicit slice
rather than an `Option`, so a tier-1 caller cannot pass nothing and have it read
as a verdict.

`candidate_keys` is created upfront with the other three profile relations
rather than lazily on first write, so a reader always finds an empty table
instead of a missing one — and it joins `cli_e2e`'s fileless list, because
`er run-all` resolves a corpus and does not describe one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

**Two gradings settled, and one constant replaced.**

The severity scale had three levels and used two: eight warnings, two infos, no
error at all — a declared level nothing honours, which is the shape this repo
rejects elsewhere. Rather than promote P009, which matches the `warning`
definition exactly (it costs recall or runtime; it does not corrupt), the two
rules that genuinely produce a WRONG RESULT are now errors. P004 because
`unknown` equals `unknown`, so records sharing nothing but their missing data
get merged, and an over-merge is the expensive mistake in entity resolution.
P008 because the outcome is not a slow run or a missed match but a row that is
gone, overwritten by whichever copy landed last. Both carry the reason in the
rule, and a test asserts the grading AND that all three levels are in use, so
the scale cannot go decorative again.

The 1000-row floor is removed rather than defended: it had the wrong UNIT.
Blocking defuses a quadratic, so "does this corpus need blocking?" is a question
about pairs, answerable with the same C(n, 2) arithmetic the module already
uses. It is now a 5,000,000-pair budget, anchored to a measurement rather than
picked — `fake_1000` is 1000 rows, so 499,500 unblocked pairs, and it resolves
end to end in well under a second, which makes half a million pairs
demonstrably free; one order of magnitude up is where the cost is worth a
sentence. The test pins it in pairs (3000 rows silent at 4.5M, 4000 rows speaks
at 8M), which a row floor could not express.

Rebased onto main and regenerated: telemetry P8 (#416) wrapped every generated
statement function in an `er_span::sql_span`, and this entity was generated
before that landed, so its upsert lacked one. CI caught it as a stale generated
file — correctly, because it verifies against the merge with current main while
the tree was authored two merges earlier. The new statement now emits a span
like every other one without a line of instrumentation written by hand, which
is what having one generator authority is for.
@athvin
athvin force-pushed the bm/profile-p4-blocking-readiness branch from a2e107a to 0e8d7a7 Compare November 3, 2026 04:42
@athvin
athvin merged commit a4a318a into main Nov 3, 2026
34 checks passed
@athvin
athvin deleted the bm/profile-p4-blocking-readiness branch November 3, 2026 07:03
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.

2 participants