49
50
virtual ~IndexType();
51
52
virtual void getKeys( const BSONObj &obj, BSONObjSet &keys ) const = 0;
55
* Returns the element placed in an index key when indexing a field absent from a document.
56
* By default this is a null BSONElement.
58
virtual BSONElement missingField() const;
60
/* Full semantics of numWanted:
61
* numWanted == 0 : Return any number of results, but try to return in batches of 101.
62
* numWanted == 1 : Return exactly one result.
63
* numWanted > 1 : Return any number of results, but try to return in batches of numWanted.
65
* In practice, your cursor can ignore numWanted, as enforcement of limits is done
52
68
virtual shared_ptr<Cursor> newCursor( const BSONObj& query , const BSONObj& order , int numWanted ) const = 0;
54
70
/** optional op : changes query to match what's in the index */
63
79
const BSONObj& keyPattern() const;
65
virtual IndexSuitability suitability( const BSONObj& query , const BSONObj& order ) const ;
81
/* Determines the suitability level of this index for answering a given query. The query is
82
* represented as a set of constraints given by a FieldRangeSet, and a desired ordering of
85
* Note: it is the responsibility of the caller to pass in the correct FieldRangeSet, which
86
* may depend upon whether this is a single or multi-key index at the time of calling.
88
virtual IndexSuitability suitability( const FieldRangeSet& queryConstraints ,
89
const BSONObj& order ) const;
67
91
virtual bool scanAndOrderRequired( const BSONObj& query , const BSONObj& order ) const ;
93
117
virtual BSONObj adjustIndexSpec( const BSONObj& spec ) const { return spec; }
120
* Hook function to run after an index that uses this plugin is built.
122
* This will be called with an active write context (and lock) on the database.
124
* @param spec The IndexSpec of the newly built index.
126
virtual void postBuildHook( const IndexSpec& spec ) const { }
95
128
// ------- static below -------
97
130
static IndexPlugin* get( const string& name ) {
110
143
static string findPluginName( const BSONObj& keyPattern );
146
* True if is a regular (non-plugin) index or uses a plugin that existed before 2.4.
147
* These plugins are grandfathered in and allowed to exist in DBs with
148
* PDFILE_MINOR_VERSION_22_AND_OLDER
150
static bool existedBefore24(const string& name) {
153
|| name == "geoHaystack"
114
160
static map<string,IndexPlugin*> * _plugins;
120
166
class IndexSpec {
170
RulesFor22, // if !IndexPlugin::existedBefore24() treat as ascending
171
RulesFor24, // allow new plugins but error if unknown
122
174
BSONObj keyPattern; // e.g., { name : 1 }
123
175
BSONObj info; // this is the same as IndexDetails::info.obj()
126
178
: _details(0) , _finishedInit(false) {
129
explicit IndexSpec( const BSONObj& k , const BSONObj& m = BSONObj() )
181
explicit IndexSpec(const BSONObj& k, const BSONObj& m=BSONObj(),
182
PluginRules rules=RulesFor24)
130
183
: keyPattern(k) , info(m) , _details(0) , _finishedInit(false) {
135
188
this is a DiscLoc of an IndexDetails info
136
189
should have a key field
138
explicit IndexSpec( const DiskLoc& loc ) {
191
explicit IndexSpec(const DiskLoc& loc, PluginRules rules=RulesFor24) {
142
void reset( const BSONObj& info );
143
void reset( const DiskLoc& infoLoc ) { reset(infoLoc.obj()); }
144
void reset( const IndexDetails * details );
195
void reset(const BSONObj& info, PluginRules rules=RulesFor24);
196
void reset(const IndexDetails * details); // determines rules based on pdfile version
197
void reset(const DiskLoc& infoLoc, PluginRules rules=RulesFor24) {
198
reset(infoLoc.obj(), rules);
146
201
void getKeys( const BSONObj &obj, BSONObjSet &keys ) const;
148
BSONElement missingField() const { return _nullElt; }
204
* Returns the element placed in an index key when indexing a field absent from a document.
205
* By default this is a null BSONElement.
207
BSONElement missingField() const {
208
if ( _indexType.get() )
209
return _indexType->missingField();
150
213
string getTypeName() const {
151
214
if ( _indexType.get() )
164
IndexSuitability suitability( const BSONObj& query , const BSONObj& order ) const ;
227
IndexSuitability suitability( const FieldRangeSet& queryConstraints ,
228
const BSONObj& order ) const ;
166
230
bool isSparse() const { return _sparse; }
232
string toString() const;
170
236
int indexVersion() const;
172
IndexSuitability _suitability( const BSONObj& query , const BSONObj& order ) const ;
238
IndexSuitability _suitability( const FieldRangeSet& queryConstraints ,
239
const BSONObj& order ) const ;
174
241
BSONSizeTracker _sizeTracker;
175
242
vector<const char*> _fieldNames;