-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 3.2.12, 3.4.3
-
Component/s: Index Maintenance
-
None
-
Fully Compatible
-
ALL
-
v3.4, v3.2
-
-
Storage 2017-04-17
-
(copied to CRM)
ISSUE DESCRIPTION
This issue only affects deployments that:
- use the WiredTiger storage engine, and
- remove documents from collections that have at least one index with a {unique: true} specification, and
- those indexes use a partialFilterExpression
Deployments that do not meet all three conditions are not affected.
ISSUE IMPACT
In affected deployments, when a document that does not pass the partial index filter is removed from a collection, other documents that contain matching keys to the removed document and do pass the partial index filter are erroneously unindexed from the partial index.
Consequently, queries that utilize this index may not return all stored results. This also has the effect of being able to successfully insert documents that violate the unique key constraint of the index and also pass the index's filter.
Please see the reproduction steps above for an illustrative example.
DIAGNOSIS AND AFFECTED VERSIONS
Indexes created on MongoDB 3.2.0 to 3.2.12 or 3.4.0 to 3.4.3 with the WiredTiger storage engine may be affected.
Additionally, the index must match both of the following criteria:
- Is a unique index, e.g. created with {unique: true}
- Is a partial index, e.g. created with { partialFilterExpression: { foo: bar } }
To determine if an index matching the criteria above has been affected by this bug, execute db.foo.validate(true). The validation will fail for affected indexes.
REMEDIATION AND WORKAROUNDS
The fix is included in the 3.2.13 and 3.4.4 production release. To resolve this issue, affected indexes should be rebuilt after upgrading to a version of MongoDB containing the fix.
Original description
This issue affects WiredTiger only. It only affects indexes with {unique: true}, and it only affects indexes using a partialFilterExpression.
Removing a document that does not pass the filter, and thus is not indexed, will erroneously unindex documents that do pass the filter and contain matching keys to the removed document. See the reproduction steps for an illustrative example.
This has the effect of being able to successfully insert documents that violate the unique key constraint of the index and also pass the index's filter.
- causes
-
SERVER-32001 unindexing a key in a partial unique index may cause server crash
- Closed
- is duplicated by
-
SERVER-28153 Duplicate data is sometimes inserted with unique index
- Closed
-
SERVER-28516 index corruption
- Closed
-
SERVER-25791 Unique index becomes inconsistent with collection data
- Closed
- related to
-
SERVER-75922 Partial unique indexes created on MongoDB 4.0 can be missing index keys after upgrade to 4.2 and later, leading to uniqueness violations
- Closed
-
SERVER-85536 [4.4] removing unindexed unique partial index entries generates write conflicts
- Closed