SlideShare a Scribd company logo
1 of 40
IndicesQuery OptimizerPerformance Tuning Aaron Staple aaron@10gen.com
What is an index? A set of references to your documents, efficiently ordered by key {x:0.5,y:0.5} {x:2,y:0.5} {x:5,y:2} {x:-4,y:10} {x:3,y:’f’}
What is an index? A set of references to your documents, efficiently ordered by key {x:1} {x:0.5,y:0.5} {x:2,y:0.5} {x:5,y:2} {x:-4,y:10} {x:3,y:’f’}
What is an index? A set of references to your documents, efficiently ordered by key {y:1} {x:0.5,y:0.5} {x:2,y:0.5} {x:5,y:2} {x:-4,y:10} {x:3,y:’f’}
How is an index stored? B-tree {x:2} {x:3} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 x>=5 x<0 {x:-4} {x:1}
What if I have multiple indices? {c:1} {a:3} {c:2} {c:3} {b:’x’} {d:null} { a:3, b:’x’, c:[1,2,3] } {a:1} {c:1} {b:1} {d:1}
How does a simple query work? Tree traversal {x:2} {x:3} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 x>=5 x<0 {x:-4} {x:1}
Simple document lookup	 db.c.findOne( {_id:2} ), using index {_id:1} db.c.find( {x:2} ), using index {x:1} db.c.find( {x:{$in:[2,3]}} ), using index {x:1} db.c.find( {‘x.a’:1} ), using index {‘x.a’:1} Matches {_id:1,x:{a:1}} db.c.find( {x:{a:1}} ), using index {x:1} Matches {_id:1,x:{a:1}}, but not {_id:2,x:{a:1,b:2}} QUESTION: What about db.c.find( {$where:“this.x == this.y”} ), using index {x:1}? Indices cannot be used for $where type queries, but if there are non-where elements in the query then indices can be used for the non-where elements.
How does a range query work? Tree traversal + scan: find({x:{$gte:3,$lte:5}}) {x:2} {x:3} {x:4} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 {x:6} x>=5 x<0 {x:-4} {x:1}
Document range scan db.c.find( {x:{$gt:2}} ), using index {x:1} db.c.find( {x:{$gt:2,$lt:5}} ), using index {x:1} db.c.find( {x:/^a/} ), using index {x:1} QUESTION: What about db.c.find( {x:/a/} ), using index {x:1}? The letter ‘a’ can appear anywhere in a matching string, so lexicographic ordering on strings won’t help.  However, we can use the index to find the range of documents where x is string (eg not a number) or x is the regular expression /a/.
Other operations db.c.count( {x:2} ) using index {x:1} db.c.distinct( {x:2} ) using index {x:1} db.c.update( {x:2}, {x:3} ) using index {x:1} db.c.remove( {x:2} ) using index {x:1} QUESTION: What about db.c.update( {x:2}, {$inc:{x:3}} ), using index {x:1}? Older versions of mongoDB didn’t support modifiers on indexed fields, but we now support this.
Missing fields db.c.find( {x:null} ), using index {x:1} Matches {_id:5} Matches {_id:5,x:null} QUESTION: What about db.c.find( {x:{$exists:true}} ), using index {x:1}? The index is not currently used, though we will fix this in MongoDB 1.6.
Array matching All the following match {_id:6,x:[2,10]} and use index {x:1} db.c.find( {x:2} ) db.c.find( {x:10} ) db.c.find( {x:{$gt:5}} ) db.c.find( {x:[2,10]} ) db.c.find( {x:{$in:[2,5]}} ) QUESTION: What about db.c.find( {x:{$all:[2,10]}} )? The index will be used to look up all documents matching {x:2}.
What is a compound index? {x:2,y:3} {x:1,y:5} {x:2,y:9} {x:3,y:1} {x:1,y:1}
How are bounds determined for a compound index? find( {x:{$gte:2,$lte:4},y:6} ) {x:3,y:1} {x:2,y:6} {x:3,y:7} {x:3.5,y:6} {x:2,y:3} {x:4,y:6} {x:1,y:5} {x:5,y:6} {x:1,y:1}
How does an ordered range query work? Simple range scan if index already ensures desired ordering: find( {x:2} ).sort( {y:1} ) {x:2,y:3} {x:1,y:5} {x:2,y:9} {x:3,y:1} {x:1,y:1}
How does an ordered range query work? Otherwise, in-memory sort of matching documents: find( {x:2} ).sort( {y:1} ) {x:2,y:3} {x:2,y:9} {x:1,y:5} {x:2,y:3} {x:2,y:9} … {x:3,y:1} {x:1}
Document ordering db.c.find( {} ).sort( {x:1} ), using index {x:1} db.c.find( {} ).sort( {x:-1} ), using index {x:1} db.c.find( {x:{$gt:4}} ).sort( {x:-1} ), using index {x:1} db.c.find( {} ).sort( {‘x.a’:1} ), using index {‘x.a’:1} QUESTION: What about db.c.find( {y:1} ).sort( {x:1} ), using index {x:1}? The index will be used to ensure ordering, provided there is no better index.
Compound indices and ordering db.c.find( {x:10,y:20} ), using index {x:1,y:1} db.c.find( {x:10,y:20} ), using index {x:1,y:-1} db.c.find( {x:{$in:[10,20]},y:20} ), using index {x:1,y:1} db.c.find().sort( {x:1,y:1} ), using index {x:1,y:1} db.c.find().sort( {x:-1,y:1} ), using index {x:1,y:-1} db.c.find( {x:10} ).sort( {y:1} ), using index {x:1,y:1} QUESTION: What about db.c.find( {y:10} ).sort( {x:1} ), using index {x:1,y:1}? The index will be used to ensure ordering, provided no better index is available.
What if we negate a query? find({x:{$ne:2}}) {x:2} {x:1} {x:2} {x:3} {x:1}
When indices are less helpful db.c.find( {x:{$ne:1}} ) db.c.find( {x:{$mod:[10,1]}} ) Uses index {x:1} to scan numbers only db.c.find( {x:{$not:/a/}} ) db.c.find( {x:{$gte:0,$lte:10},y:5} ) using index {x:1,y:1} Currently must scan all elements from {x:0,y:5} to {x:10,y:5}, but some improvements may be possible db.c.find( {$where:’this.x = 5’} ) QUESTION: What about db.c.find( {x:{$not:/^a/}} ), using index {x:1}? The index is not used currently, but will be used in mongoDB 1.6
How is an index chosen? find( {x:2,y:3} ) {x:2,y:1} {y:3,x:1} {x:2,y:3} {x:2,y:9} {y:3,x:2} {y:9,x:2} {x:1,y:3} {y:1,x:2} {x:1} {y:1} √ {x:2,y:3} {x:2,y:1} {x:2,y:9} {y:3,x:2} {y:3,x:1}
Query pattern matching Very simple algorithm, few complaints so far find({x:1}) find({x:2}) find({x:100}) find({x:{$gt:4}}) find({x:{$gte:6}}) find({x:1,y:2}) find({x:{$gt:4,$lte:10}}) find({x:{$gte:6,$lte:400}}) find({x:1}).sort({y:1})
Query optimizer In charge of picking which index to use for a query/count/update/delete/etc Usually it does a good job, but if you know what you’re doing you can override it db.c.find( {x:2,y:3} ).hint( {y:1} ) Use index {y:1} and avoid trying {x:1} As your data changes, different indices may be chosen.  Ordering requirements should be made explicit using sort(). QUESTION: How can you force a full collection scan instead of using indices? db.c.find( {x:2,y:3} ).hint( {$natural:1} ) to bypass indices
Geospatial indices db.c.find( {a:[50,50]} ) using index {a:’2d’} db.c.find( {a:{$near:[50,50]}} ) using index {a:’2d’} Results are sorted closest - farthest db.c.find( {a:{$within:{$box:[[40,40],[60,60]]}}} ) using index {a:’2d’} db.c.find( {a:{$within:{$center:[[50,50],10]}}} ) using index {a:’2d’} db.c.find( {a:{$near:[50,50]},b:2} ) using index {a:’2d’,b:1} QUESTION: Most queries can be performed with or without an index.  Is this true of geospatial queries? No.  A geospatial query requires an index.
How does an insert work? Tree traversal and insert, split if necessary {x:3.5} {x:2} {x:3} {x:4} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 {x:6} x>=5 x<0 {x:-4} {x:1}
What if my keys are increasing? You’ll always insert on the right {x:2} {x:3} {x:4} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 {x:6} x>=5 x<0 {x:7} {x:-4} {x:8} {x:1} {x:9}
Why is RAM important? RAM is basically used as a LIFO disk cache Whole index in RAM Portion of index in RAM
Creating an index {_id:1} index created automatically For non-capped collections db.c.ensureIndex( {x:1} ) Can create an index at any time, even when you already have plenty of data in your collection Creating an index will block mongoDB unless you specify background index creation db.c.ensureIndex( {x:1}, {background:true} ) Background index creation is a still impacts performance – run at non peak times if you’re concerned QUESTION: Can an index be removed during background creation? Not at this time.
Unique key constraints db.c.ensureIndex( {x:1}, {unique:true} ) Don’t allow {_id:10,x:2} and {_id:11,x:2} Don’t allow {_id:12} and {_id:13} (both match {x:null} What if duplicates exist before index is created? Normally index creation fails and the index is removed db.ensureIndex( {x:1}, {unique:true,dropDups:true} ) QUESTION: In dropDups mode, which duplicates will be removed? The first document according to the collection’s “natural order” will be preserved.
Cleaning up an index db.system.indices.find( {ns:’db.c’} ) db.c.dropIndex( {x:1} ) db.c.dropindices() db.c.reIndex() Rebuilds all indices, removing index cruft that has built up over large numbers of updates and deletes.  Index cruft will not exist in mongoDB 1.6, so this command will be deprecated. QUESTION: Why would you want to drop an index? See next slide…
Limits and tradeoffs Max 40 indices per collection Logically equivalent indices are not prevented (eg {x:1} and {x:-1}) indices can improve speed of queries, but make inserts slower A more specific index {a:1,b:1,c:1} can be more helpful than less specific index {a:1} but the more specific index will be larger, thus harder to fit in RAM QUESTION: Do indices make updates slower?  How about deletes? It depends – finding your document might be faster, but if any indexed fields are changed the indices must be updated.
Mongod log output query test.c ntoreturn:1 reslen:69 nscanned:100000 { i: 99999.0 }  nreturned:1 157ms query test.$cmd ntoreturn:1 command: { count: "c", query: { type: 0.0, i: { $gt: 99000.0 } }, fields: {} } reslen:64 256ms query:{ query: {}, orderby: { i: 1.0 } } ... query test.c ntoreturn:0 exception  1378ms ... User Exception 10128:too much key data for sort() with no index.  add an index or specify a smaller limit query test.c ntoreturn:0 reslen:4783 nscanned:100501 { query: { type: 500.0 }, orderby: { i: 1.0 } }  nreturned:101 390ms Occasionally may see a slow operation as a result of disk activity or mongo cleaning things up – some messages about slow ops are spurious Keep this in mind when running the same op a massive number of times, and it appears slow very rarely
Profiling Record same info as with log messages, but in a database collection > db.system.profile.find() {"ts" : "Thu Jan 29 2009 15:19:32 GMT-0500 (EST)" , "info" : "query test.$cmd ntoreturn:1 reslen:66 nscanned:0  <br>query: { profile: 2 }  nreturned:1 bytes:50" , "millis" : 0}... > db.system.profile.find( { info: /test.foo/ } ) > db.system.profile.find( { millis : { $gt : 5 } } ) > db.system.profile.find().sort({$natural:-1}) Enable explicitly using levels (0:off, 1:slow ops (>100ms), 2:all ops) > db.setProfilingLevel(2); {"was" : 0 , "ok" : 1} > db.getProfilingLevel() 2 > db.setProfilingLevel( 1 , 10 ); // slow means > 10ms Profiling impacts performance, but not severely
Query explain > db.c.find( {x:1000,y:0} ).explain() { 	"cursor" : "BtreeCursor x_1", 	"indexBounds" : [ 		[ 			{ 				"x" : 1000 			}, 			{ 				"x" : 1000 			} 		] 	], 	"nscanned" : 10, 	"nscannedObjects" : 10, 	"n" : 10, 	"millis" : 0, 	"oldPlan" : { 		"cursor" : "BtreeCursor x_1", 		"indexBounds" : [ 			[ 				{ 					"x" : 1000 				}, 				{ 					"x" : 1000 				} 			] 		] 	}, 	"allPlans" : [ 		{ 			"cursor" : "BtreeCursor x_1", 			"indexBounds" : [ 				[ 					{ 						"x" : 1000 					}, 					{ 						"x" : 1000 					} 				] 			] 		}, 		{ 			"cursor" : "BtreeCursor y_1", 			"indexBounds" : [ 				[ 					{ 						"y" : 0 					}, 					{ 						"y" : 0 					} 				] 			] 		}, 		{ 			"cursor" : "BasicCursor", 			"indexBounds" : [ ] 		} 	] }
Example 1 > db.c.findOne( {i:99999} ) { "_id" : ObjectId("4bb962dddfdcf5761c1ec6a3"), "i" : 99999 } query test.c ntoreturn:1 reslen:69 nscanned:100000 { i: 99999.0 }  nreturned:1 157ms > db.c.find( {i:99999} ).limit(1).explain() { 	"cursor" : "BasicCursor", 	"indexBounds" : [ ], 	"nscanned" : 100000, 	"nscannedObjects" : 100000, 	"n" : 1, 	"millis" : 161, 	"allPlans" : [ 		{ 			"cursor" : "BasicCursor", 			"indexBounds" : [ ] 		} 	] } > db.c.ensureIndex( {i:1} ); > for( i = 0; i < 100000; ++i ) { db.c.save( {i:i} ); }
Example 2 > db.c.count( {type:0,i:{$gt:99000}} ) 499 query test.$cmd ntoreturn:1 command: { count: "c", query: { type: 0.0, i: { $gt: 99000.0 } }, fields: {} } reslen:64 256ms > db.c.find( {type:0,i:{$gt:99000}} ).limit(1).explain() { 	"cursor" : "BtreeCursor type_1", 	"indexBounds" : [ 		[ 			{ 				"type" : 0 			}, 			{ 				"type" : 0 			} 		] 	], 	"nscanned" : 49502, 	"nscannedObjects" : 49502, 	"n" : 1, 	"millis" : 349, ... > db.c.ensureIndex( {type:1,i:1} ); > for( i = 0; i < 100000; ++i ) { db.c.save( {type:i%2,i:i} ); }
Example 3 > db.c.find().sort( {i:1} ) error: { 	"$err" : "too much key data for sort() with no index.  add an index or specify a smaller limit" } > db.c.find().sort( {i:1} ).explain() JS Error: uncaught exception: error: { 	"$err" : "too much key data for sort() with no index.  add an index or specify a smaller limit" } > db.c.ensureIndex( {i:1} ); > db.c.find().sort( {i:1} ).limit( 1000 ); //alternatively > for( i = 0; i < 1000000; ++i ) { db.c.save( {i:i} ); }
Example 4 > db.c.find( {type:500} ).sort( {i:1} ) { "_id" : ObjectId("4bba4904dfdcf5761c2f917e"), "i" : 500, "type" : 500 } { "_id" : ObjectId("4bba4904dfdcf5761c2f9566"), "i" : 1500, "type" : 500 } ... query test.c ntoreturn:0 reslen:4783 nscanned:100501 { query: { type: 500.0 }, orderby: { i: 1.0 } }  nreturned:101 390ms > db.c.find( {type:500} ).sort( {i:1} ).explain() { 	"cursor" : "BtreeCursor i_1", 	"indexBounds" : [ 		[ 			{ 				"i" : { 					"$minElement" : 1 				} 			}, 			{ 				"i" : { 					"$maxElement" : 1 				} 			} 		] 	], 	"nscanned" : 1000000, 	"nscannedObjects" : 1000000, 	"n" : 1000, 	"millis" : 5388, ... > db.c.ensureIndex( {type:1,i:1} ); > for( i = 0; i < 1000000; ++i ) { db.c.save( {i:i,type:i%1000} ); }
Questions? Get involved www.mongodb.org Downloads, user group, chat room Follow @mongodb Upcoming events  www.mongodb.org/display/DOCS/Events SF MongoDB office hours  Mondays 4-6pm at Epicenter Café SF MongoDBmeetup May 17 at Engine Yard Commercial support www.10gen.com jobs@10gen.com

More Related Content

What's hot

Indexing and Performance Tuning
Indexing and Performance TuningIndexing and Performance Tuning
Indexing and Performance TuningMongoDB
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationMongoDB
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query OptimizerMongoDB
 
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...MongoDB
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android哲偉 楊
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBBehrouz Bakhtiari
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDBVyacheslav
 
Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012yantoit2011
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of SlickKnoldus Inc.
 

What's hot (20)

Indexing and Performance Tuning
Indexing and Performance TuningIndexing and Performance Tuning
Indexing and Performance Tuning
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and Evaluation
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
Indexing In MongoDB
Indexing In MongoDBIndexing In MongoDB
Indexing In MongoDB
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Green dao
Green daoGreen dao
Green dao
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query Optimizer
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Green dao
Green daoGreen dao
Green dao
 
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
 
MongoDB crud
MongoDB crudMongoDB crud
MongoDB crud
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDB
 
Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
 

Viewers also liked

Breaking the oracle tie
Breaking the oracle tieBreaking the oracle tie
Breaking the oracle tieagiamas
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMike Friedman
 
Webinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDBWebinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDBMongoDB
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema DesignMongoDB
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDBlehresman
 
User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB MongoDB
 
MongoDBを使用したモバイルゲーム開発
MongoDBを使用したモバイルゲーム開発MongoDBを使用したモバイルゲーム開発
MongoDBを使用したモバイルゲーム開発Genki Yamada
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニングYuichi Matsuo
 
MongoDB全機能解説1
MongoDB全機能解説1MongoDB全機能解説1
MongoDB全機能解説1Takahiro Inoue
 
MongoDB for Time Series Data: Schema Design
MongoDB for Time Series Data: Schema DesignMongoDB for Time Series Data: Schema Design
MongoDB for Time Series Data: Schema DesignMongoDB
 
Leveraging MongoDB as a Data Store for Security Data
Leveraging MongoDB as a Data Store for Security DataLeveraging MongoDB as a Data Store for Security Data
Leveraging MongoDB as a Data Store for Security DataMongoDB
 
Geo-Indexing w/MongoDB
Geo-Indexing w/MongoDBGeo-Indexing w/MongoDB
Geo-Indexing w/MongoDBLalit Kapoor
 
MongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative SchemasMongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative SchemasMongoDB
 
NoSQL i dlaczego go nie potrzebujesz? [OlCamp]
NoSQL i dlaczego go nie potrzebujesz? [OlCamp]NoSQL i dlaczego go nie potrzebujesz? [OlCamp]
NoSQL i dlaczego go nie potrzebujesz? [OlCamp]Filip Tepper
 
Webinar: Schema Design and Performance Implications
Webinar: Schema Design and Performance ImplicationsWebinar: Schema Design and Performance Implications
Webinar: Schema Design and Performance ImplicationsMongoDB
 
Mongo at Sailthru (MongoNYC 2011)
Mongo at Sailthru (MongoNYC 2011)Mongo at Sailthru (MongoNYC 2011)
Mongo at Sailthru (MongoNYC 2011)ibwhite
 
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, AnalyticsMongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, AnalyticsMongoDB
 
Performance Tuning on the Fly at CMP.LY
Performance Tuning on the Fly at CMP.LYPerformance Tuning on the Fly at CMP.LY
Performance Tuning on the Fly at CMP.LYMongoDB
 
Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)MongoDB
 

Viewers also liked (20)

Breaking the oracle tie
Breaking the oracle tieBreaking the oracle tie
Breaking the oracle tie
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
Webinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDBWebinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDB
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB
 
MongoDBを使用したモバイルゲーム開発
MongoDBを使用したモバイルゲーム開発MongoDBを使用したモバイルゲーム開発
MongoDBを使用したモバイルゲーム開発
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニング
 
MongoDB全機能解説1
MongoDB全機能解説1MongoDB全機能解説1
MongoDB全機能解説1
 
MongoDB for Time Series Data: Schema Design
MongoDB for Time Series Data: Schema DesignMongoDB for Time Series Data: Schema Design
MongoDB for Time Series Data: Schema Design
 
Leveraging MongoDB as a Data Store for Security Data
Leveraging MongoDB as a Data Store for Security DataLeveraging MongoDB as a Data Store for Security Data
Leveraging MongoDB as a Data Store for Security Data
 
Geo-Indexing w/MongoDB
Geo-Indexing w/MongoDBGeo-Indexing w/MongoDB
Geo-Indexing w/MongoDB
 
MongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative SchemasMongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative Schemas
 
NoSQL i dlaczego go nie potrzebujesz? [OlCamp]
NoSQL i dlaczego go nie potrzebujesz? [OlCamp]NoSQL i dlaczego go nie potrzebujesz? [OlCamp]
NoSQL i dlaczego go nie potrzebujesz? [OlCamp]
 
Webinar: Schema Design and Performance Implications
Webinar: Schema Design and Performance ImplicationsWebinar: Schema Design and Performance Implications
Webinar: Schema Design and Performance Implications
 
Mongo at Sailthru (MongoNYC 2011)
Mongo at Sailthru (MongoNYC 2011)Mongo at Sailthru (MongoNYC 2011)
Mongo at Sailthru (MongoNYC 2011)
 
Phplx mongodb
Phplx mongodbPhplx mongodb
Phplx mongodb
 
MongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, AnalyticsMongoDB Use Cases: Healthcare, CMS, Analytics
MongoDB Use Cases: Healthcare, CMS, Analytics
 
Performance Tuning on the Fly at CMP.LY
Performance Tuning on the Fly at CMP.LYPerformance Tuning on the Fly at CMP.LY
Performance Tuning on the Fly at CMP.LY
 
Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)
 

Similar to Indexing and Query Optimizer (Aaron Staple)

The Query Engine: The Life of a Read
The Query Engine: The Life of a ReadThe Query Engine: The Life of a Read
The Query Engine: The Life of a ReadMongoDB
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDBantoinegirbal
 
Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27MongoDB
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln Hannah
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional ProgrammingEelco Visser
 
Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018
Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018
Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018Alexander Tokarev
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data ManipulationChu An
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchPedro Franceschi
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R langsenthil0809
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29Bilal Ahmed
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterizationRiteshkiit
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimizationJared Rosoff
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 

Similar to Indexing and Query Optimizer (Aaron Staple) (20)

Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
The Query Engine: The Life of a Read
The Query Engine: The Life of a ReadThe Query Engine: The Life of a Read
The Query Engine: The Life of a Read
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Indexing
IndexingIndexing
Indexing
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
 
Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018
Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018
Oracle JSON treatment evolution - from 12.1 to 18 AOUG-2018
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimization
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 

More from MongoSF

Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) MongoSF
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)MongoSF
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)MongoSF
 
Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)MongoSF
 
Administration (Eliot Horowitz)
Administration (Eliot Horowitz)Administration (Eliot Horowitz)
Administration (Eliot Horowitz)MongoSF
 
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)MongoSF
 
MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)MongoSF
 
Administration
AdministrationAdministration
AdministrationMongoSF
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)MongoSF
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)MongoSF
 
Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)MongoSF
 
Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)MongoSF
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoSF
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 HoursMongoSF
 
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)MongoSF
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)MongoSF
 
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...MongoSF
 
From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)MongoSF
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 

More from MongoSF (20)

Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)
 
Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)
 
Administration (Eliot Horowitz)
Administration (Eliot Horowitz)Administration (Eliot Horowitz)
Administration (Eliot Horowitz)
 
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
 
MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)
 
Administration
AdministrationAdministration
Administration
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)
 
Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)
 
Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 Hours
 
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
 
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
 
From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 

Recently uploaded

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Indexing and Query Optimizer (Aaron Staple)

  • 1. IndicesQuery OptimizerPerformance Tuning Aaron Staple aaron@10gen.com
  • 2. What is an index? A set of references to your documents, efficiently ordered by key {x:0.5,y:0.5} {x:2,y:0.5} {x:5,y:2} {x:-4,y:10} {x:3,y:’f’}
  • 3. What is an index? A set of references to your documents, efficiently ordered by key {x:1} {x:0.5,y:0.5} {x:2,y:0.5} {x:5,y:2} {x:-4,y:10} {x:3,y:’f’}
  • 4. What is an index? A set of references to your documents, efficiently ordered by key {y:1} {x:0.5,y:0.5} {x:2,y:0.5} {x:5,y:2} {x:-4,y:10} {x:3,y:’f’}
  • 5. How is an index stored? B-tree {x:2} {x:3} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 x>=5 x<0 {x:-4} {x:1}
  • 6. What if I have multiple indices? {c:1} {a:3} {c:2} {c:3} {b:’x’} {d:null} { a:3, b:’x’, c:[1,2,3] } {a:1} {c:1} {b:1} {d:1}
  • 7. How does a simple query work? Tree traversal {x:2} {x:3} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 x>=5 x<0 {x:-4} {x:1}
  • 8. Simple document lookup db.c.findOne( {_id:2} ), using index {_id:1} db.c.find( {x:2} ), using index {x:1} db.c.find( {x:{$in:[2,3]}} ), using index {x:1} db.c.find( {‘x.a’:1} ), using index {‘x.a’:1} Matches {_id:1,x:{a:1}} db.c.find( {x:{a:1}} ), using index {x:1} Matches {_id:1,x:{a:1}}, but not {_id:2,x:{a:1,b:2}} QUESTION: What about db.c.find( {$where:“this.x == this.y”} ), using index {x:1}? Indices cannot be used for $where type queries, but if there are non-where elements in the query then indices can be used for the non-where elements.
  • 9. How does a range query work? Tree traversal + scan: find({x:{$gte:3,$lte:5}}) {x:2} {x:3} {x:4} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 {x:6} x>=5 x<0 {x:-4} {x:1}
  • 10. Document range scan db.c.find( {x:{$gt:2}} ), using index {x:1} db.c.find( {x:{$gt:2,$lt:5}} ), using index {x:1} db.c.find( {x:/^a/} ), using index {x:1} QUESTION: What about db.c.find( {x:/a/} ), using index {x:1}? The letter ‘a’ can appear anywhere in a matching string, so lexicographic ordering on strings won’t help. However, we can use the index to find the range of documents where x is string (eg not a number) or x is the regular expression /a/.
  • 11. Other operations db.c.count( {x:2} ) using index {x:1} db.c.distinct( {x:2} ) using index {x:1} db.c.update( {x:2}, {x:3} ) using index {x:1} db.c.remove( {x:2} ) using index {x:1} QUESTION: What about db.c.update( {x:2}, {$inc:{x:3}} ), using index {x:1}? Older versions of mongoDB didn’t support modifiers on indexed fields, but we now support this.
  • 12. Missing fields db.c.find( {x:null} ), using index {x:1} Matches {_id:5} Matches {_id:5,x:null} QUESTION: What about db.c.find( {x:{$exists:true}} ), using index {x:1}? The index is not currently used, though we will fix this in MongoDB 1.6.
  • 13. Array matching All the following match {_id:6,x:[2,10]} and use index {x:1} db.c.find( {x:2} ) db.c.find( {x:10} ) db.c.find( {x:{$gt:5}} ) db.c.find( {x:[2,10]} ) db.c.find( {x:{$in:[2,5]}} ) QUESTION: What about db.c.find( {x:{$all:[2,10]}} )? The index will be used to look up all documents matching {x:2}.
  • 14. What is a compound index? {x:2,y:3} {x:1,y:5} {x:2,y:9} {x:3,y:1} {x:1,y:1}
  • 15. How are bounds determined for a compound index? find( {x:{$gte:2,$lte:4},y:6} ) {x:3,y:1} {x:2,y:6} {x:3,y:7} {x:3.5,y:6} {x:2,y:3} {x:4,y:6} {x:1,y:5} {x:5,y:6} {x:1,y:1}
  • 16. How does an ordered range query work? Simple range scan if index already ensures desired ordering: find( {x:2} ).sort( {y:1} ) {x:2,y:3} {x:1,y:5} {x:2,y:9} {x:3,y:1} {x:1,y:1}
  • 17. How does an ordered range query work? Otherwise, in-memory sort of matching documents: find( {x:2} ).sort( {y:1} ) {x:2,y:3} {x:2,y:9} {x:1,y:5} {x:2,y:3} {x:2,y:9} … {x:3,y:1} {x:1}
  • 18. Document ordering db.c.find( {} ).sort( {x:1} ), using index {x:1} db.c.find( {} ).sort( {x:-1} ), using index {x:1} db.c.find( {x:{$gt:4}} ).sort( {x:-1} ), using index {x:1} db.c.find( {} ).sort( {‘x.a’:1} ), using index {‘x.a’:1} QUESTION: What about db.c.find( {y:1} ).sort( {x:1} ), using index {x:1}? The index will be used to ensure ordering, provided there is no better index.
  • 19. Compound indices and ordering db.c.find( {x:10,y:20} ), using index {x:1,y:1} db.c.find( {x:10,y:20} ), using index {x:1,y:-1} db.c.find( {x:{$in:[10,20]},y:20} ), using index {x:1,y:1} db.c.find().sort( {x:1,y:1} ), using index {x:1,y:1} db.c.find().sort( {x:-1,y:1} ), using index {x:1,y:-1} db.c.find( {x:10} ).sort( {y:1} ), using index {x:1,y:1} QUESTION: What about db.c.find( {y:10} ).sort( {x:1} ), using index {x:1,y:1}? The index will be used to ensure ordering, provided no better index is available.
  • 20. What if we negate a query? find({x:{$ne:2}}) {x:2} {x:1} {x:2} {x:3} {x:1}
  • 21. When indices are less helpful db.c.find( {x:{$ne:1}} ) db.c.find( {x:{$mod:[10,1]}} ) Uses index {x:1} to scan numbers only db.c.find( {x:{$not:/a/}} ) db.c.find( {x:{$gte:0,$lte:10},y:5} ) using index {x:1,y:1} Currently must scan all elements from {x:0,y:5} to {x:10,y:5}, but some improvements may be possible db.c.find( {$where:’this.x = 5’} ) QUESTION: What about db.c.find( {x:{$not:/^a/}} ), using index {x:1}? The index is not used currently, but will be used in mongoDB 1.6
  • 22. How is an index chosen? find( {x:2,y:3} ) {x:2,y:1} {y:3,x:1} {x:2,y:3} {x:2,y:9} {y:3,x:2} {y:9,x:2} {x:1,y:3} {y:1,x:2} {x:1} {y:1} √ {x:2,y:3} {x:2,y:1} {x:2,y:9} {y:3,x:2} {y:3,x:1}
  • 23. Query pattern matching Very simple algorithm, few complaints so far find({x:1}) find({x:2}) find({x:100}) find({x:{$gt:4}}) find({x:{$gte:6}}) find({x:1,y:2}) find({x:{$gt:4,$lte:10}}) find({x:{$gte:6,$lte:400}}) find({x:1}).sort({y:1})
  • 24. Query optimizer In charge of picking which index to use for a query/count/update/delete/etc Usually it does a good job, but if you know what you’re doing you can override it db.c.find( {x:2,y:3} ).hint( {y:1} ) Use index {y:1} and avoid trying {x:1} As your data changes, different indices may be chosen. Ordering requirements should be made explicit using sort(). QUESTION: How can you force a full collection scan instead of using indices? db.c.find( {x:2,y:3} ).hint( {$natural:1} ) to bypass indices
  • 25. Geospatial indices db.c.find( {a:[50,50]} ) using index {a:’2d’} db.c.find( {a:{$near:[50,50]}} ) using index {a:’2d’} Results are sorted closest - farthest db.c.find( {a:{$within:{$box:[[40,40],[60,60]]}}} ) using index {a:’2d’} db.c.find( {a:{$within:{$center:[[50,50],10]}}} ) using index {a:’2d’} db.c.find( {a:{$near:[50,50]},b:2} ) using index {a:’2d’,b:1} QUESTION: Most queries can be performed with or without an index. Is this true of geospatial queries? No. A geospatial query requires an index.
  • 26. How does an insert work? Tree traversal and insert, split if necessary {x:3.5} {x:2} {x:3} {x:4} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 {x:6} x>=5 x<0 {x:-4} {x:1}
  • 27. What if my keys are increasing? You’ll always insert on the right {x:2} {x:3} {x:4} 3<=x<4 4<=x<5 {x:0.5} 2<=x<5 {x:5} 0<=x<1 {x:6} x>=5 x<0 {x:7} {x:-4} {x:8} {x:1} {x:9}
  • 28. Why is RAM important? RAM is basically used as a LIFO disk cache Whole index in RAM Portion of index in RAM
  • 29. Creating an index {_id:1} index created automatically For non-capped collections db.c.ensureIndex( {x:1} ) Can create an index at any time, even when you already have plenty of data in your collection Creating an index will block mongoDB unless you specify background index creation db.c.ensureIndex( {x:1}, {background:true} ) Background index creation is a still impacts performance – run at non peak times if you’re concerned QUESTION: Can an index be removed during background creation? Not at this time.
  • 30. Unique key constraints db.c.ensureIndex( {x:1}, {unique:true} ) Don’t allow {_id:10,x:2} and {_id:11,x:2} Don’t allow {_id:12} and {_id:13} (both match {x:null} What if duplicates exist before index is created? Normally index creation fails and the index is removed db.ensureIndex( {x:1}, {unique:true,dropDups:true} ) QUESTION: In dropDups mode, which duplicates will be removed? The first document according to the collection’s “natural order” will be preserved.
  • 31. Cleaning up an index db.system.indices.find( {ns:’db.c’} ) db.c.dropIndex( {x:1} ) db.c.dropindices() db.c.reIndex() Rebuilds all indices, removing index cruft that has built up over large numbers of updates and deletes. Index cruft will not exist in mongoDB 1.6, so this command will be deprecated. QUESTION: Why would you want to drop an index? See next slide…
  • 32. Limits and tradeoffs Max 40 indices per collection Logically equivalent indices are not prevented (eg {x:1} and {x:-1}) indices can improve speed of queries, but make inserts slower A more specific index {a:1,b:1,c:1} can be more helpful than less specific index {a:1} but the more specific index will be larger, thus harder to fit in RAM QUESTION: Do indices make updates slower? How about deletes? It depends – finding your document might be faster, but if any indexed fields are changed the indices must be updated.
  • 33. Mongod log output query test.c ntoreturn:1 reslen:69 nscanned:100000 { i: 99999.0 } nreturned:1 157ms query test.$cmd ntoreturn:1 command: { count: "c", query: { type: 0.0, i: { $gt: 99000.0 } }, fields: {} } reslen:64 256ms query:{ query: {}, orderby: { i: 1.0 } } ... query test.c ntoreturn:0 exception 1378ms ... User Exception 10128:too much key data for sort() with no index. add an index or specify a smaller limit query test.c ntoreturn:0 reslen:4783 nscanned:100501 { query: { type: 500.0 }, orderby: { i: 1.0 } } nreturned:101 390ms Occasionally may see a slow operation as a result of disk activity or mongo cleaning things up – some messages about slow ops are spurious Keep this in mind when running the same op a massive number of times, and it appears slow very rarely
  • 34. Profiling Record same info as with log messages, but in a database collection > db.system.profile.find() {"ts" : "Thu Jan 29 2009 15:19:32 GMT-0500 (EST)" , "info" : "query test.$cmd ntoreturn:1 reslen:66 nscanned:0 <br>query: { profile: 2 } nreturned:1 bytes:50" , "millis" : 0}... > db.system.profile.find( { info: /test.foo/ } ) > db.system.profile.find( { millis : { $gt : 5 } } ) > db.system.profile.find().sort({$natural:-1}) Enable explicitly using levels (0:off, 1:slow ops (>100ms), 2:all ops) > db.setProfilingLevel(2); {"was" : 0 , "ok" : 1} > db.getProfilingLevel() 2 > db.setProfilingLevel( 1 , 10 ); // slow means > 10ms Profiling impacts performance, but not severely
  • 35. Query explain > db.c.find( {x:1000,y:0} ).explain() { "cursor" : "BtreeCursor x_1", "indexBounds" : [ [ { "x" : 1000 }, { "x" : 1000 } ] ], "nscanned" : 10, "nscannedObjects" : 10, "n" : 10, "millis" : 0, "oldPlan" : { "cursor" : "BtreeCursor x_1", "indexBounds" : [ [ { "x" : 1000 }, { "x" : 1000 } ] ] }, "allPlans" : [ { "cursor" : "BtreeCursor x_1", "indexBounds" : [ [ { "x" : 1000 }, { "x" : 1000 } ] ] }, { "cursor" : "BtreeCursor y_1", "indexBounds" : [ [ { "y" : 0 }, { "y" : 0 } ] ] }, { "cursor" : "BasicCursor", "indexBounds" : [ ] } ] }
  • 36. Example 1 > db.c.findOne( {i:99999} ) { "_id" : ObjectId("4bb962dddfdcf5761c1ec6a3"), "i" : 99999 } query test.c ntoreturn:1 reslen:69 nscanned:100000 { i: 99999.0 } nreturned:1 157ms > db.c.find( {i:99999} ).limit(1).explain() { "cursor" : "BasicCursor", "indexBounds" : [ ], "nscanned" : 100000, "nscannedObjects" : 100000, "n" : 1, "millis" : 161, "allPlans" : [ { "cursor" : "BasicCursor", "indexBounds" : [ ] } ] } > db.c.ensureIndex( {i:1} ); > for( i = 0; i < 100000; ++i ) { db.c.save( {i:i} ); }
  • 37. Example 2 > db.c.count( {type:0,i:{$gt:99000}} ) 499 query test.$cmd ntoreturn:1 command: { count: "c", query: { type: 0.0, i: { $gt: 99000.0 } }, fields: {} } reslen:64 256ms > db.c.find( {type:0,i:{$gt:99000}} ).limit(1).explain() { "cursor" : "BtreeCursor type_1", "indexBounds" : [ [ { "type" : 0 }, { "type" : 0 } ] ], "nscanned" : 49502, "nscannedObjects" : 49502, "n" : 1, "millis" : 349, ... > db.c.ensureIndex( {type:1,i:1} ); > for( i = 0; i < 100000; ++i ) { db.c.save( {type:i%2,i:i} ); }
  • 38. Example 3 > db.c.find().sort( {i:1} ) error: { "$err" : "too much key data for sort() with no index. add an index or specify a smaller limit" } > db.c.find().sort( {i:1} ).explain() JS Error: uncaught exception: error: { "$err" : "too much key data for sort() with no index. add an index or specify a smaller limit" } > db.c.ensureIndex( {i:1} ); > db.c.find().sort( {i:1} ).limit( 1000 ); //alternatively > for( i = 0; i < 1000000; ++i ) { db.c.save( {i:i} ); }
  • 39. Example 4 > db.c.find( {type:500} ).sort( {i:1} ) { "_id" : ObjectId("4bba4904dfdcf5761c2f917e"), "i" : 500, "type" : 500 } { "_id" : ObjectId("4bba4904dfdcf5761c2f9566"), "i" : 1500, "type" : 500 } ... query test.c ntoreturn:0 reslen:4783 nscanned:100501 { query: { type: 500.0 }, orderby: { i: 1.0 } } nreturned:101 390ms > db.c.find( {type:500} ).sort( {i:1} ).explain() { "cursor" : "BtreeCursor i_1", "indexBounds" : [ [ { "i" : { "$minElement" : 1 } }, { "i" : { "$maxElement" : 1 } } ] ], "nscanned" : 1000000, "nscannedObjects" : 1000000, "n" : 1000, "millis" : 5388, ... > db.c.ensureIndex( {type:1,i:1} ); > for( i = 0; i < 1000000; ++i ) { db.c.save( {i:i,type:i%1000} ); }
  • 40. Questions? Get involved www.mongodb.org Downloads, user group, chat room Follow @mongodb Upcoming events www.mongodb.org/display/DOCS/Events SF MongoDB office hours Mondays 4-6pm at Epicenter Café SF MongoDBmeetup May 17 at Engine Yard Commercial support www.10gen.com jobs@10gen.com