commands: distinct #4
Reference in New Issue
Block a user
Delete Branch "m3-distinct"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
M3 opens with the cheapest lever: a whole command that did not exist. Five
corpus cases answered "no such command".
Two things were measured against mongod 8.3.7 rather than recalled, and the
first is not what anyone would guess:
values were met.
{s: "b"}, {s: "a"}, {s: null}answers[null, "a", "b"].Insertion order is the obvious implementation, it passes every test anybody
would think to write by hand against
[11, 22, 33], and it is wrong.1and a double1.0collapsewhile
nulland"1"survive.Both fall out of
bson.compare, which$sortand$minalready use -- andthat is not luck: mongod accumulates into a
BSONElementSetordered by thesame
woCompare. The rest reuses the shared read path.Running the identical probe against both servers now agrees on every
semantic row.
Scorecard
201 pass / 90 fail -> 204 / 87.
distinct.json0/2 -> 2/0,distinct-rawdata0/1 -> 1/0.distinct-commentnets zero: its "no suchcommand" is replaced by the pre-4.4.14 document-comment case, which
estimatedDocumentCountalready carries as a standing failure -- emulating abug fixed in 4.4.14 for one command would make the two disagree.
distinct-collationstill needs M8, but now fails with the honest"expected 1 elements, got 2".
Recorded, not fixed here (PLAN §6)
{x: {$bogus: 1}}answersok: 1with an empty result onfind,countand
aggregatealike, where mongod answersBadValueon all three.Measured on both servers side by side. Same class as M2's six silent wrong
answers, and it lives in the shared query path -- one fix for every command.
BadValuewhere mongod saysInvalidNamespace(73): one answer for the whole command table.distinctis unbounded in memory, joining$groupand$sort.Verification
198/198 unit (7 new) in ReleaseFast and ReleaseSafe, 83/83 fuzz, aggregation
corpus 70/0, full e2e matrix and crash-fuzz green.
A whole command that did not exist: five corpus cases answered "no such command". Two things about it were measured against mongod 8.3.7 rather than recalled, and the first is not what anyone would guess. - The answer is **sorted in canonical BSON order**, not in the order the values were met. `{s: "b"}, {s: "a"}, {s: null}` answers `[null, "a", "b"]`. Insertion order is the obvious implementation, it passes every test anybody would think to write by hand against `[11, 22, 33]`, and it is wrong. - Deduping is the same comparator, so an int32 `1` and a double `1.0` collapse while `null` and `"1"` survive. Both fall out of `bson.compare`, which `$sort` and `$min` already use -- and that is not luck: mongod accumulates into a `BSONElementSet` ordered by the same `woCompare`. The rest reuses the shared read path: byte-walked `collect_values_bytes` for the key, so the traversal, the multikey descent and the numeric path segments are the ones the matcher and the index already agree on. Also measured: a terminal array contributes its elements exactly one level deep (`[[7, 8], 9]` gives `[7, 8]` and `9`, never 7 and 8); a missing field contributes nothing where an explicit null contributes null; an absent collection, an absent database and an empty key are each `ok: 1` with an empty array rather than an error; `query` absent and `query: null` are both an empty filter; a missing `key` is IDLFailedToParse (40414) while a wrong-typed one is TypeMismatch (14). Running the identical probe against both servers now agrees on every semantic row. Three divergences remain, all outside this command and recorded in PLAN §6: an unknown query operator matches nothing instead of erroring (shared with find/count/aggregate, and the same class as M2's six silent wrong answers), a non-string collection name is refused by dispatch as BadValue where mongod says InvalidNamespace, and an unknown top-level field is tolerated -- deliberately, since `comment` and `rawData` arrive through that door and the corpus requires both be ignored. crud scorecard: 201 pass / 90 fail -> 204 / 87. distinct.json 0/2 -> 2/0, distinct-rawdata 0/1 -> 1/0. distinct-comment nets zero: its "no such command" is replaced by the pre-4.4.14 document-comment case, which `estimatedDocumentCount` already carries as a standing failure -- and emulating a bug fixed in 4.4.14 for one command would make the two disagree. distinct-collation still needs M8, but now fails with the honest "expected 1 elements, got 2". 198/198 unit (7 new) in ReleaseFast and ReleaseSafe, 83/83 fuzz, aggregation corpus 70/0, full e2e matrix and crash-fuzz green.