`tests/spec/indexes/` is 42/42, so all four recorded corpora are green:
positional 51, operators 125, indexes 42, aggregate 70.
Records what implementing the row taught, including the three things the
design review got wrong. Two were already noted when the corpus was
recorded ($in is allowed; a differing filter is 86); the third is new and
cheaper than the review's version: hashed needs no flags bit, because it
belongs to a key *component* and the per-component direction byte was
already there holding 0 or 1.
Also fixes a corpus case that did not measure what it said. "equality
across numeric types" sent an int32, because a source is plain JSON and
`5.0` is `5` after JSON.parse -- it was a second copy of the case above
it. Reading sources as EJSON was tried and reverted, and the recorder now
says why: EJSON's wrapper namespace collides with the query operators
these sources are made of, so `{"$regex": "x"}` became a BSONRegExp,
`structuredClone` flattened it to `{pattern, options}`, and "a filter
using $regex is refused" silently became a filter mongod accepts. The
cross-type property is a unit test instead, which is where it belongs --
it is about how this server hashes, and mongod's hash is a different
function, so a corpus could only ever check the answer.
The case is renamed to what it does measure rather than deleted: two
documents sharing a value is still the read a hashed index exists for.
Verified: 256/256 unit tests in ReleaseFast and ReleaseSafe, 87/87 fuzz,
all four corpora 0 fail, pinned scorecard unchanged at 228/63/196, the
full e2e matrix and crash-fuzz green.
157 lines
5.8 KiB
JSON
157 lines
5.8 KiB
JSON
{
|
|
"_comment": [
|
|
"Inputs only. Expectations are measured -- see record.js.",
|
|
"Hashed indexes. The tree is ordered by a hash, so it answers equality and",
|
|
"nothing else; every read case here exists to pin that a range query and a",
|
|
"sort still come back *correct*, because the planner declining to use the",
|
|
"index is the only thing that makes them so."
|
|
],
|
|
"documents": [
|
|
{ "_id": 1, "a": 1, "s": "x" },
|
|
{ "_id": 2, "a": 5, "s": "y" },
|
|
{ "_id": 3, "s": "z" },
|
|
{ "_id": 4, "a": 5, "s": "x" }
|
|
],
|
|
"cases": [
|
|
{
|
|
"description": "a hashed index is created and names itself for the plugin",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "listIndexes", "arguments": {} }
|
|
]
|
|
},
|
|
{
|
|
"description": "an equality query answers every match",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "find", "arguments": { "filter": { "a": 5 }, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "equality against a value nothing holds",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "find", "arguments": { "filter": { "a": 99 }, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "equality against a missing field",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "find", "arguments": { "filter": { "a": null }, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "a range query still answers every match",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "find", "arguments": { "filter": { "a": { "$gte": 5 } }, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "a sort on the hashed field is by value, not by hash",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "find", "arguments": { "filter": {}, "sort": { "a": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "equality against a value two documents share",
|
|
"_comment": [
|
|
"This was 'equality across numeric types' and could not be: a source",
|
|
"is plain JSON, so 5.0 reaches the driver as an int32 and the case was",
|
|
"a second copy of the one above it. The cross-type property belongs to",
|
|
"how this server hashes anyway -- it hashes the *encoded* value, which",
|
|
"normalizes every numeric type -- and mongod's hash is a different",
|
|
"function, so a corpus could only ever check the answer. It is a unit",
|
|
"test instead: 'a hashed component answers equality across numeric",
|
|
"types and nothing else' in src/index.zig."
|
|
],
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "find", "arguments": { "filter": { "a": 5 }, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "inserting after the index exists",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "insertOne", "arguments": { "document": { "_id": 5, "a": 5 } } },
|
|
{ "name": "find", "arguments": { "filter": { "a": 5 }, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "deleting through a hashed index",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "deleteMany", "arguments": { "filter": { "a": 5 } } },
|
|
{ "name": "find", "arguments": { "filter": {}, "sort": { "_id": 1 } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "a hashed component beside a range one",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed", "s": 1 } } },
|
|
{ "name": "listIndexes", "arguments": {} }
|
|
]
|
|
},
|
|
{
|
|
"description": "two hashed components are refused",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed", "s": "hashed" } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "a unique hashed index is refused",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" }, "unique": true } }
|
|
]
|
|
},
|
|
{
|
|
"description": "an array at the hashed path is refused, at insert time",
|
|
"documents": [],
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "insertOne", "arguments": { "document": { "_id": 1, "a": [1, 2] } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "a key direction that is neither 1, -1 nor hashed",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "bogus" } } }
|
|
]
|
|
},
|
|
{
|
|
"description": "a sparse hashed index",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" }, "sparse": true } },
|
|
{ "name": "listIndexes", "arguments": {} }
|
|
]
|
|
},
|
|
{
|
|
"description": "the same hashed index twice is idempotent",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "listIndexes", "arguments": {} }
|
|
]
|
|
},
|
|
{
|
|
"description": "a hashed index beside an ascending one on the same field",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": 1 } } },
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "listIndexes", "arguments": {} }
|
|
]
|
|
},
|
|
{
|
|
"description": "a hashed index is dropped by name",
|
|
"ops": [
|
|
{ "name": "createIndex", "arguments": { "keys": { "a": "hashed" } } },
|
|
{ "name": "dropIndex", "arguments": { "name": "a_hashed" } },
|
|
{ "name": "listIndexes", "arguments": {} }
|
|
]
|
|
}
|
|
]
|
|
}
|