diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-02-15 23:58:08 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-02-15 23:58:08 -0500 |
commit | a330ad65dd86a1de3f001c8f21540ae58fa23cb0 (patch) | |
tree | 30ccdc1c7cef3ff027205721fb93a34bb187d13e /db | |
parent | cfec75960b02b456ba6a582dec62ff083de31973 (diff) | |
download | mongo-a330ad65dd86a1de3f001c8f21540ae58fa23cb0.tar.gz |
some thoughts on extending indexing
Diffstat (limited to 'db')
-rw-r--r-- | db/index.cpp | 42 | ||||
-rw-r--r-- | db/index.h | 48 |
2 files changed, 89 insertions, 1 deletions
diff --git a/db/index.cpp b/db/index.cpp index 1b05d19828e..6ad3f43cebf 100644 --- a/db/index.cpp +++ b/db/index.cpp @@ -25,6 +25,23 @@ namespace mongo { + map<string,IndexPlugin*> * IndexPlugin::_plugins; + + IndexType::~IndexType(){ + } + + IndexPlugin::IndexPlugin( const string& name ) + : _name( name ){ + if ( ! _plugins ) + _plugins = new map<string,IndexPlugin*>(); + (*_plugins)[name] = this; + } + + int IndexType::compare( const IndexSpec& spec , const BSONObj& l , const BSONObj& r ) const { + return l.woCompare( r , spec.keyPattern ); + } + + int removeFromSysIndexes(const char *ns, const char *idxName) { string system_indexes = cc().database()->name + ".system.indexes"; BSONObjBuilder b; @@ -81,14 +98,23 @@ namespace mongo { } void IndexSpec::_init(){ + _indexType = 0; assert( keyPattern.objsize() ); + string pluginName = ""; + BSONObjIterator i( keyPattern ); BSONObjBuilder nullKeyB; while( i.more() ) { - _fieldNames.push_back( i.next().fieldName() ); + BSONElement e = i.next(); + _fieldNames.push_back( e.fieldName() ); _fixed.push_back( BSONElement() ); nullKeyB.appendNull( "" ); + if ( e.type() == String ){ + uassert( 13007 , "can only have 1 index plugin" , pluginName.size() == 0 ); + pluginName = e.valuestr(); + } + } _nullKey = nullKeyB.obj(); @@ -97,10 +123,24 @@ namespace mongo { b.appendNull( "" ); _nullObj = b.obj(); _nullElt = _nullObj.firstElement(); + + if ( pluginName.size() ){ + IndexPlugin * plugin = IndexPlugin::get( pluginName ); + if ( ! plugin ){ + log() << "warning: can't find plugin [" << pluginName << "]" << endl; + } + else { + assert(0); + } + } } void IndexSpec::getKeys( const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const { + if ( _indexType ){ + _indexType->getKeys( obj , keys ); + return; + } vector<const char*> fieldNames( _fieldNames ); vector<BSONElement> fixed( _fixed ); _getKeys( fieldNames , fixed , obj, keys ); diff --git a/db/index.h b/db/index.h index 8bd877de4a0..9af4702c64e 100644 --- a/db/index.h +++ b/db/index.h @@ -19,9 +19,55 @@ #pragma once #include "../stdafx.h" +#include "diskloc.h" +#include "jsobj.h" +#include <map> namespace mongo { + class IndexSpec; + class IndexType; // TODO: this name sucks + + /** + * this represents an instance of a index plugin + * done this way so parsing, etc... can be cached + * so if there is a FTS IndexPlugin, for each index using FTS + * there will be 1 of these, and it can have things pre-parsed, etc... + */ + class IndexType : boost::noncopyable { + public: + virtual ~IndexType(); + virtual void getKeys( const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const = 0; + virtual int compare( const IndexSpec& spec , const BSONObj& l , const BSONObj& r ) const; + + }; + + /** + * this represents a plugin + * a plugin could be something like full text search, sparse index, etc... + * 1 of these exists per type of index per server + * 1 IndexType is created per index using this plugin + */ + class IndexPlugin : boost::noncopyable { + public: + IndexPlugin( const string& name ); + virtual ~IndexPlugin(){} + + virtual IndexType* generate( const IndexSpec& spec ) const = 0; + + static IndexPlugin* get( const string& name ){ + if ( ! _plugins ) + return 0; + map<string,IndexPlugin*>::iterator i = _plugins->find( name ); + if ( i == _plugins->end() ) + return 0; + return i->second; + } + private: + string _name; + static map<string,IndexPlugin*> * _plugins; + }; + /* precomputed details about an index, used for inserting keys on updates stored/cached in NamespaceDetailsTransient, or can be used standalone */ @@ -68,6 +114,8 @@ namespace mongo { BSONObj _nullObj; BSONElement _nullElt; + IndexType * _indexType; + void _init(); }; |