Storage Engine API
index_entry_comparison.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <iosfwd>
32 #include <tuple>
33 #include <vector>
34 
35 #include "mongo/bson/simple_bsonobj_comparator.h"
36 #include "mongo/db/jsobj.h"
37 #include "mongo/db/record_id.h"
38 
39 namespace mongo {
40 
45 struct IndexKeyEntry {
46  IndexKeyEntry(BSONObj key, RecordId loc) : key(std::move(key)), loc(std::move(loc)) {}
47 
48  BSONObj key;
49  RecordId loc;
50 };
51 
52 std::ostream& operator<<(std::ostream& stream, const IndexKeyEntry& entry);
53 
54 inline bool operator==(const IndexKeyEntry& lhs, const IndexKeyEntry& rhs) {
55  return SimpleBSONObjComparator::kInstance.evaluate(lhs.key == rhs.key) && (lhs.loc == rhs.loc);
56 }
57 
58 inline bool operator!=(const IndexKeyEntry& lhs, const IndexKeyEntry& rhs) {
59  return !(lhs == rhs);
60 }
61 
105  BSONObj keyPrefix;
106 
110  int prefixLen = 0;
111 
115  bool prefixExclusive = false;
116 
121  std::vector<const BSONElement*> keySuffix;
122 
130  std::vector<bool> suffixInclusive;
131 };
132 
141 public:
142  IndexEntryComparison(Ordering order) : _order(order) {}
143 
144  bool operator()(const IndexKeyEntry& lhs, const IndexKeyEntry& rhs) const;
145 
155  int compare(const IndexKeyEntry& lhs, const IndexKeyEntry& rhs) const;
156 
185  static BSONObj makeQueryObject(const BSONObj& keyPrefix,
186  int prefixLen,
187  bool prefixExclusive,
188  const std::vector<const BSONElement*>& keySuffix,
189  const std::vector<bool>& suffixInclusive,
190  const int cursorDirection);
191 
192  static BSONObj makeQueryObject(const IndexSeekPoint& seekPoint, bool isForward) {
193  return makeQueryObject(seekPoint.keyPrefix,
194  seekPoint.prefixLen,
195  seekPoint.prefixExclusive,
196  seekPoint.keySuffix,
197  seekPoint.suffixInclusive,
198  isForward ? 1 : -1);
199  }
200 
201 private:
202  // Ordering is used in comparison() to compare BSONElements
203  const Ordering _order;
204 
205 }; // struct IndexEntryComparison
206 
207 } // namespace mongo
bool prefixExclusive
If true, compare exclusively on just the fields on keyPrefix and ignore the suffix.
Definition: index_entry_comparison.h:115
const Ordering _order
Definition: index_entry_comparison.h:203
bool operator==(const IndexKeyEntry &lhs, const IndexKeyEntry &rhs)
Definition: index_entry_comparison.h:54
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
static BSONObj makeQueryObject(const IndexSeekPoint &seekPoint, bool isForward)
Definition: index_entry_comparison.h:192
static int compare(const unsigned char *&l, const unsigned char *&r)
Definition: key.cpp:468
bool operator!=(const IndexKeyEntry &lhs, const IndexKeyEntry &rhs)
Definition: index_entry_comparison.h:58
BSONObj key
Definition: index_entry_comparison.h:48
Compares two different IndexKeyEntry instances.
Definition: index_entry_comparison.h:140
IndexKeyEntry(BSONObj key, RecordId loc)
Definition: index_entry_comparison.h:46
std::ostream & operator<<(std::ostream &stream, const IndexKeyEntry &entry)
Definition: index_entry_comparison.cpp:37
int prefixLen
Use this many fields in &#39;keyPrefix&#39;.
Definition: index_entry_comparison.h:110
Ordering _order
Definition: ephemeral_for_test_btree_impl_test.cpp:57
std::vector< bool > suffixInclusive
If the ith element is false, ignore indexes > i in keySuffix and treat the concatenated key as exclus...
Definition: index_entry_comparison.h:130
RecordId loc
Definition: index_entry_comparison.h:49
IndexEntryComparison(Ordering order)
Definition: index_entry_comparison.h:142
BSONObj keyPrefix
Definition: index_entry_comparison.h:105
Describes a query that can be compared against an IndexKeyEntry in a way that allows expressing exclu...
Definition: index_entry_comparison.h:104
Represents a single item in an index.
Definition: index_entry_comparison.h:45
std::vector< const BSONElement * > keySuffix
Elements starting at index &#39;prefixLen&#39; are logically appended to the prefix.
Definition: index_entry_comparison.h:121