-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Index Maintenance
-
None
-
(copied to CRM)
When writes default to getting errors, we should just fail fast.
Behavior when a document with an index key is found to exceed the maximum key size:
- insert new document with over-size index key fails with error msg. The document is not inserted.
- update existing document with over-size index key fails with error msg. The existing document remains unchanged.
- ensureIndex / reIndex on a collection with over-size index key fails with error msg. The index is not created.
- compact on a collection with over-size index key succeeds. Documents with over-size keys are not inserted into the index.
- mongorestore / mongoimport with indexed values too large rejects objects which do not suit. Effectively the result of doing an insert of each individual object.
Behavior on secondary nodes:
- New replica set secondaries will insert document and build indexes on initial sync with an warning in the logs.
- Replica set secondaries will replicate documents insert to a 2.4 primary, but print an error msg in the log.
- Replica set secondaries will update documents updated on a 2.4 primary, but print an error msg in the log.
OLD DESCRIPTION:
When inserting a new document, if an indexed field is too long to store in the btree, we don't add the doc to the index, but do store the doc. This leads to peculiar behaviors (examples below). It would be good to have a mechanism to make these insertions just be errors and not store the document (we already do this for unique indexes, after all, so programmers using fire and forget can't really expect the docs to be present if they haven't checked).
// Create a document with too long an _id, but note that // any indexed field can evince this problem. var s="a"; for (i=0;i<10;i++) s+=s; print(s.length); print(s+=s; s.length); db.foo.insert({ _id : s}); // You can find the document if you do a tablescan db.foo.find(); db.foo.count(); // But you can't find the document if you use the _id index. db.foo.find().hint({_id:1}); // You also can't find the document if you're looking for it // by _id: db.foo.find({ _id : s }); db.foo.find({ _id : s }).hint({ $natural : 1});
The fix for this issue must encompass both insert/update as well as failing during ensureIndex calls if this condition is violated (similar to a unique index constraint failing).
Need to think hard about how this will work when a user upgrades a node with indexes built on top of invalid data. When they re-sync a new replset member the index create step would fail.
- is duplicated by
-
SERVER-10749 Query results differ depending on the utilized index
- Closed
-
SERVER-9256 update fails when field contains more than 1012 characters
- Closed
-
SERVER-11209 ERROR: key too large len:6597 max:1024 6597
- Closed
-
SERVER-14976 Ghost Documents
- Closed
-
SERVER-15464 Mongodb cannot find document with long string index
- Closed
-
SERVER-16487 Regex not working properly on indexed fields..
- Closed
-
SERVER-16900 regex query fails on 2.4.5 when field's value is above a certain size
- Closed
-
SERVER-2633 getLastError and Btree::insert failure
- Closed
-
SERVER-9447 Key values too large to index
- Closed
- is related to
-
SERVER-1716 Key too large to index / re-index inconsistency
- Closed
-
SERVER-6417 duplicate _ids possible when values exceed max index key size
- Closed
-
SERVER-12247 Write commands allow un-indexable document to be replicated
- Closed
-
SERVER-12406 Replication fails to remove document if _id value is too long to index
- Closed
-
SERVER-3372 Allow indexing fields of arbitrary length
- Closed
-
SERVER-4271 Shard key (512 bytes) maximum is less than Index key (1024 bytes) maximum
- Closed
-
SERVER-1016 when a key too large for index how does it affect queries
- Closed
-
SERVER-35218 different result when query hint hint different indexes
- Closed
- related to
-
SERVER-12828 Reindexing drops indexes if key contains values too large to index
- Closed
-
SERVER-12982 Could not restore backup data due to "key too large to index"
- Closed
-
SERVER-8391 Pre-flight upgrade tool to check for changes breaking backwards compatibility or introducing regressions
- Closed
-
SERVER-12834 Create flag to allow mongod to ignore "index too long" errors
- Closed
-
SERVER-12233 Command to check for over-long index keys
- Closed