Files
MultiforaDB/tests/spec/indexes/partial.json
A.Shakhmatov 7de3e6b666 index: a partial index may answer a query that implies its filter
Step 5, the last of `docs/M3_INDEX_TYPES_DESIGN_REVIEW.md`'s order and the
last item in M3's row. A partial index was maintained and enforced
`unique`, and every read scanned -- correct, but the speedup the option
exists for was never earned.

The test is one-sided by construction: a `false` costs a scan, a `true`
has to be right, because returning too few documents is the one failure
worse than having no index at all. Two routes, and a filter conjunct is
implied if either answers yes:

**Route one, the query pins a value.** Run the *real matcher* against a
stand-in document holding that value at the path, rather than
reimplementing eight operators against a comparison that would then have
two definitions. Sound because every operator `check_partial_filter`
admits is existential -- "some value at this path satisfies it" -- so a
document with more values at the path satisfies it at least as easily,
and every document the query matches has the pinned value among its
values there. Covers `$eq`, `$in`, `$type`, `$exists` and the bounds in
one stroke.

Two shapes break that argument and are refused rather than approximated,
and both have a row in the test table:

  - an **array** value. `{a: [1, 2]}` matches `{a: [[1, 2], 3]}`, whose
    values at `a` do not include 1 or 2 -- only one level is expanded, so
    the real document's value set is not a superset of the stand-in's.
  - a **null** value. `{a: null}` also matches a document with no `a`,
    which has no values at the path rather than more of them. The
    stand-in alone would report `{a: {$exists: true}}` as implied, so an
    empty document is tested too and both have to agree. This is the rule
    the previous commit's null fix made necessary and possible in the
    same breath.

**Route two, bounds.** The only route needing neither side to name a
document: `{a: {$gt: 5}}` implies `{a: {$gt: 0}}`. Inclusivity is where
it is decided -- `$gte: 0` admits the endpoint that `$gt: 0` excludes.

Soundness is judged against *this server's* matcher, not mongod's. Both
halves of the question run the same code: `query.matches_bytes` decides
the index's contents in `build_entries` and re-filters every candidate
the plan yields. Where this server's comparison differs from mongod's
(PLAN §6: the comparison operators are not type-bracketed) both halves
are wrong together, which is a matching bug and not a lost document.

`$or` on the filter's side is implied by one implied branch: sufficient,
not necessary, since a query can imply a disjunction without implying a
disjunct.

**What each gate can and cannot see, measured with two mutations.** With
`query_implies_filter` forced to `true`, `partial.json` goes 23/7 and
every failure reads "expected N, got N-1" -- the exact shape of the bug.
With it forced to `false` -- the behaviour this commit replaces -- the
corpus is 30/30, because no client can observe *that* an index was used,
only that an answer went missing. So the corpus guards soundness and the
unit test on `plan()` is the only thing that sees the feature work at
all; both are needed and the commit says which does which.

Six corpus cases added, each pairing a query that implies the filter with
one that does not and touches the same field: a query leaving the
filter's field out, an `$in` straddling the filter, a query for null
against an `$exists` filter, equalities inside and outside a range
filter, a sort a partial index could serve, and a unique partial index
read. `partial.json` 24 -> 30 cases, `tests/spec/indexes/` 42 -> 48.

Verified: 257/257 unit tests in ReleaseFast and ReleaseSafe, 88/88 fuzz,
all four corpora 0 fail, pinned scorecard unchanged at 228/63/196, the
full e2e matrix and crash-fuzz green.
2026-08-11 00:34:30 +03:00

2 lines
28 KiB
JSON

{"description":"partial","schemaVersion":"1.4","createEntities":[{"client":{"id":"client0"}},{"database":{"id":"database0","client":"client0","databaseName":"index-corpus"}},{"collection":{"id":"collection0","database":"database0","collectionName":"coll"}}],"initialData":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}],"tests":[{"description":"a partial index is created and reports its filter","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gte":{"$numberInt":"5"}}}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"a":{"$gte":{"$numberInt":"5"}}}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a query the filter covers still answers every match","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gte":{"$numberInt":"5"}}}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$gte":{"$numberInt":"5"}}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a query the filter excludes still answers every match","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gte":{"$numberInt":"5"}}}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"1"}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a query straddling the filter still answers every match","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gte":{"$numberInt":"5"}}}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$gte":{"$numberInt":"1"}}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]},{"object":"collection0","name":"countDocuments","arguments":{"filter":{}},"expectResult":{"$numberInt":"4"}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a unique partial index accepts duplicates its filter excludes","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"unique":true,"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false}]},"expectResult":{"insertedCount":{"$numberInt":"2"},"insertedIds":{"0":{"$numberInt":"1"},"1":{"$numberInt":"2"}}}},{"object":"collection0","name":"find","arguments":{"filter":{},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false}]}]},{"description":"a unique partial index refuses duplicates its filter selects","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"unique":true,"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":true}]},"expectError":{"isError":true,"errorCode":{"$numberInt":"11000"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true}]}]},{"description":"a document leaving the filter frees the value it held","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"unique":true,"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true}]},"expectResult":{"insertedCount":{"$numberInt":"1"},"insertedIds":{"0":{"$numberInt":"1"}}}},{"object":"collection0","name":"updateOne","arguments":{"filter":{"_id":{"$numberInt":"1"}},"update":{"$set":{"t":false}}},"expectResult":{"matchedCount":{"$numberInt":"1"},"modifiedCount":{"$numberInt":"1"},"upsertedCount":{"$numberInt":"0"}}},{"object":"collection0","name":"insertOne","arguments":{"document":{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":true}},"expectResult":{"insertedId":{"$numberInt":"2"}}},{"object":"collection0","name":"find","arguments":{"filter":{},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":false},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":true}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":false},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":true}]}]},{"description":"a document entering the filter takes the value it names","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"unique":true,"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":false}]},"expectResult":{"insertedCount":{"$numberInt":"2"},"insertedIds":{"0":{"$numberInt":"1"},"1":{"$numberInt":"2"}}}},{"object":"collection0","name":"updateOne","arguments":{"filter":{"_id":{"$numberInt":"2"}},"update":{"$set":{"t":true}}},"expectError":{"isError":true,"errorCode":{"$numberInt":"11000"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":false}]}]},{"description":"a query that leaves the filter's field out still sees past it","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"3"},"a":{"$numberInt":"2"},"t":true}]}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"1"}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"1"},"t":true},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":true}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"1"},"t":false},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"3"},"a":{"$numberInt":"2"},"t":true}]}]},{"description":"an $in straddling the filter still answers every match","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gte":{"$numberInt":"5"}}}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$in":[{"$numberInt":"1"},{"$numberInt":"5"}]}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$in":[{"$numberInt":"5"},{"$numberInt":"9"}]}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a query for null does not belong to an index that requires the field","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"}},{"_id":{"$numberInt":"2"}},{"_id":{"$numberInt":"3"},"a":null}]}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$exists":true}}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":null},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"}},{"_id":{"$numberInt":"3"},"a":null}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"1"}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"}},{"_id":{"$numberInt":"2"}},{"_id":{"$numberInt":"3"},"a":null}]}]},{"description":"an equality inside the filter's range, and one outside it","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"3"}}}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"5"}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"1"}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$gt":{"$numberInt":"4"}}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$gt":{"$numberInt":"0"}}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a sort a partial index could serve","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"3"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"3"},"a":{"$numberInt":"2"},"t":true}]}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"t":true},"sort":{"a":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"3"},"a":{"$numberInt":"2"},"t":true},{"_id":{"$numberInt":"1"},"a":{"$numberInt":"3"},"t":true}]},{"object":"collection0","name":"find","arguments":{"filter":{},"sort":{"a":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"3"},"a":{"$numberInt":"2"},"t":true},{"_id":{"$numberInt":"1"},"a":{"$numberInt":"3"},"t":true}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"3"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"1"},"t":false},{"_id":{"$numberInt":"3"},"a":{"$numberInt":"2"},"t":true}]}]},{"description":"a unique partial index answers the read it constrains","operations":[{"object":"collection0","name":"deleteMany","arguments":{"filter":{}}},{"object":"collection0","name":"insertMany","arguments":{"documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":false}]}},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"unique":true,"partialFilterExpression":{"t":true}},"expectResult":"a_1"},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"9"},"t":true},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true}]},{"object":"collection0","name":"find","arguments":{"filter":{"a":{"$numberInt":"9"}},"sort":{"_id":{"$numberInt":"1"}}},"expectResult":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":false}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"9"},"t":true},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"9"},"t":false}]}]},{"description":"a filter on $exists","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$exists":true}}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"a":{"$exists":true}}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter with two predicates","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}},"s":"x"}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}},"s":"x"}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter with an explicit $and","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"$and":[{"a":{"$gt":{"$numberInt":"0"}}}]}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"$and":[{"a":{"$gt":{"$numberInt":"0"}}}]}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter on a field the index does not name","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"s":"x"}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"s":"x"}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter using $regex is refused","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"s":{"$regex":"x"}}},"expectError":{"isError":true,"errorCode":{"$numberInt":"67"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter using $ne is refused","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$ne":{"$numberInt":"1"}}}},"expectError":{"isError":true,"errorCode":{"$numberInt":"67"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter using $in is refused","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$in":[{"$numberInt":"1"},{"$numberInt":"2"}]}}},"expectResult":"a_1"}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a filter that is not a document is refused","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"$numberInt":"1"}},"expectError":{"isError":true,"errorCode":{"$numberInt":"14"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"an empty filter","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"sparse and a partial filter may not be combined","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"sparse":true,"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectError":{"isError":true,"errorCode":{"$numberInt":"67"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a partial filter with a TTL","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"expireAfterSeconds":{"$numberInt":"100"},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}},"expireAfterSeconds":{"$numberInt":"100"}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a partial index on a compound key","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"},"s":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"a_1_s_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"},"s":{"$numberInt":"1"}},"name":"a_1_s_1","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"two indexes on one key differing only in their filter","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"name":"one","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"one"},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"name":"two","partialFilterExpression":{"a":{"$gt":{"$numberInt":"4"}}}},"expectResult":"two"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"one","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"two","partialFilterExpression":{"a":{"$gt":{"$numberInt":"4"}}}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"the same index twice is idempotent","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"a_1"},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"a_1"},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"a":{"$numberInt":"1"}},"name":"a_1","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"the same name with a different filter conflicts","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"a_1"},{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"partialFilterExpression":{"a":{"$gt":{"$numberInt":"4"}}}},"expectError":{"isError":true,"errorCode":{"$numberInt":"86"}}}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]},{"description":"a partial index is dropped by name","operations":[{"object":"collection0","name":"createIndex","arguments":{"keys":{"a":{"$numberInt":"1"}},"name":"pa","partialFilterExpression":{"a":{"$gt":{"$numberInt":"0"}}}},"expectResult":"pa"},{"object":"collection0","name":"dropIndex","arguments":{"name":"pa"},"expectResult":{}},{"object":"collection0","name":"listIndexes","arguments":{},"expectResult":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}]}],"outcome":[{"collectionName":"coll","databaseName":"index-corpus","documents":[{"_id":{"$numberInt":"1"},"a":{"$numberInt":"1"},"s":"x"},{"_id":{"$numberInt":"2"},"a":{"$numberInt":"5"},"s":"y"},{"_id":{"$numberInt":"3"},"s":"z"},{"_id":{"$numberInt":"4"},"a":{"$numberInt":"5"},"s":"x"}]}]}]}