mongo performance optimization using indexing

30
Performance Optimization Strategies for MongoDB choosing right database server hardware schema design (denormalizing schema) query optimization ($in, $nin) Indexing choosing approapriate shard key in sharding clusters

Upload: chinmay-naik

Post on 14-May-2015

591 views

Category:

Technology


1 download

DESCRIPTION

Mongo Performance Optimization Using Indexing

TRANSCRIPT

Page 1: Mongo Performance Optimization Using Indexing

Performance Optimization Strategies for MongoDB

choosing right database server hardware

schema design (denormalizing schema)

query optimization ($in, $nin)

Indexing

choosing approapriate shard key in sharding clusters

Page 2: Mongo Performance Optimization Using Indexing

What are indexes?

Page 3: Mongo Performance Optimization Using Indexing

Chemist Drawer

Page 4: Mongo Performance Optimization Using Indexing

Indexing = technique used to make search faster

Page 5: Mongo Performance Optimization Using Indexing

Computer Science definition

Index = any data structure that improves the performance of lookup.

Page 6: Mongo Performance Optimization Using Indexing

DB Index datastructures

Binary Tree B+ Tree Balanced Tree Hashes

Page 7: Mongo Performance Optimization Using Indexing

Binary Search Tree

Page 8: Mongo Performance Optimization Using Indexing

Our Favourite Employee Table

Page 9: Mongo Performance Optimization Using Indexing
Page 10: Mongo Performance Optimization Using Indexing
Page 11: Mongo Performance Optimization Using Indexing
Page 12: Mongo Performance Optimization Using Indexing
Page 13: Mongo Performance Optimization Using Indexing
Page 14: Mongo Performance Optimization Using Indexing
Page 15: Mongo Performance Optimization Using Indexing
Page 16: Mongo Performance Optimization Using Indexing
Page 17: Mongo Performance Optimization Using Indexing
Page 18: Mongo Performance Optimization Using Indexing

Search By Employee Id

select * from employee where employee_id= 3

Page 19: Mongo Performance Optimization Using Indexing
Page 20: Mongo Performance Optimization Using Indexing

B+ Tree

The B-tree is a generalization of a binary search tree in that a node can have more than two children

Order of B-Tree= max no of child nodes The left subtree of a node contains only nodes

with keys less than the node's key. he right subtree of a node contains only nodes

with keys greater than the node's key.

Page 21: Mongo Performance Optimization Using Indexing
Page 22: Mongo Performance Optimization Using Indexing

A database index improves data retrieval operations but they come up

with the cost. slower writes and the use of more

storage space.

3 Gigabytes of collection, if you have 1 index, approx it uses 500 Mb for that index

Page 23: Mongo Performance Optimization Using Indexing

INDEX CARDINALITY

Cardinality: Unique values in the column

Page 24: Mongo Performance Optimization Using Indexing
Page 25: Mongo Performance Optimization Using Indexing
Page 26: Mongo Performance Optimization Using Indexing

MONGO DOCUMENT

{

employee_id : 8

Name : “john”

Salary : 2000

}

{

employee_id : 5

Name : “james”

Salary : 3000

}

Page 27: Mongo Performance Optimization Using Indexing
Page 28: Mongo Performance Optimization Using Indexing
Page 29: Mongo Performance Optimization Using Indexing

TAKE AWAY...

Index Datastructure Index Cardinality Indexing is not the only solution to improve the

performance

Page 30: Mongo Performance Optimization Using Indexing

Points to consider while creating index

Keys (columns) frequently involved in search conditions of a query

Indexes can be created on Array, Sub-documents and also Embedded Fields

Use Indexes to Sort Query Results Queries that return a range of values using operators such as $gt,$lt Negation: Inequality queries are inefficient with respect to indexes

High cardinality (firstname). If low cardinality (gender) then indexing is not efficient Low selectivity indexes: An index should radically reduce the set of possible documents to select

from. Creating multiple indexes in support of a single query: MongoDB will use a single index to optimize a

query. If you need

to specify multiple predicates, you need a compound index. Compound index are ordered by field and order matters

Indexes have storage requirements, and impacts insert/update speed to some degree

For queries with the $or operator, each clause of an $or query executes in parallel, and can each use a different index.