got index?

50

Upload: mongodb

Post on 22-Jan-2015

580 views

Category:

Technology


0 download

DESCRIPTION

Do all your queries use proper indexes? Really? A real life experience: In this talk I will reveal what might happen to your system if your queries do not use indexes and how to avoid this situation. I will show you different "built-in" possibilities to prevent missing indexes, and why they did not work for us! To solve the indexing issues we encountered at our company, I created a tool called "Mongo Query Inspector", which will be the main focus in this talk.

TRANSCRIPT

Page 1: Got Index?
Page 2: Got Index?
Page 3: Got Index?
Page 4: Got Index?
Page 5: Got Index?
Page 6: Got Index?
Page 7: Got Index?
Page 8: Got Index?
Page 9: Got Index?
Page 10: Got Index?

Investigation

Page 11: Got Index?
Page 12: Got Index?

1

Page 13: Got Index?
Page 14: Got Index?

2

Page 15: Got Index?

It is not cool when queries do not use indexes

3

Page 16: Got Index?
Page 17: Got Index?

1

Page 18: Got Index?
Page 19: Got Index?

notablescan

2

Page 20: Got Index?
Page 21: Got Index?

Regression tests will fail on all CI environments due to

missing index exceptions

Page 22: Got Index?

notablescan can only be set on the mongod

process

Integration andacceptance tests

fail due to missingindexes in test DBs

Page 23: Got Index?

3

ENABLEPROFILING

Page 24: Got Index?

Set profiling level to 1

in order to log all queries that run longer

than 100ms

Page 25: Got Index?

If there isno traffic,queries without index

only need 2ms

Page 26: Got Index?

4 explain()

Page 27: Got Index?

We could use theexplain()

command to analyzeQueries

Page 28: Got Index?

query

Page 29: Got Index?
Page 30: Got Index?

A TOOL THAT:

logs queries that did not use an index

inspectsexecuted

queries formissingindexes

___is writtenin node.js

Page 31: Got Index?

A TOOL THAT:

logs queries that did not use an index

inspectsexecuted

queries formissingindexes

___is writtenin node.js

Page 32: Got Index?

A TOOL THAT:

Logs queries that didnot use an index

inspectsexecuted

queries formissingindexes

is writtenin node.js

Page 33: Got Index?
Page 34: Got Index?

Application

MongoDB

system.profile

Mongo Query

Inspector

execute queries

collect profiling data (profiling level: 2)

read profiling data

Page 35: Got Index?

Application

MongoDB

system.profile

Mongo Query

Inspector

execute queries

collect profiling data (profiling level: 2)

read profiling data

Page 36: Got Index?

Application

MongoDB

system.profile

Mongo Query

Inspector

execute queries

collect profiling data (profiling level: 2)

read profiling data

Page 37: Got Index?

run explain on query

Query

Explainresult

analyzeexplain result

Keep calm andcarry on!

log queryand fields toapply index

on

Index missing?

YES NO

Page 38: Got Index?

run explain on query

Query

Explainresult

analyzeexplain result

keepcalm andcarry on!

log queryand fields toapply index

on

Index missing?

YES NO

Page 39: Got Index?
Page 40: Got Index?
Page 41: Got Index?
Page 42: Got Index?

Integrate the Inspector in your build pipeline…

Page 43: Got Index?
Page 44: Got Index?
Page 45: Got Index?

SUMMARY:

Problem approach Solution

notablescanprofilingexplain()

Page 46: Got Index?

SUMMARY:

Problem approach Solution

notablescanprofilingexplain()

Page 47: Got Index?

SUMMARY:

Problem approach Solution

notablescanprofilingexplain()

Page 48: Got Index?

https://github.com/meckert/mongoQueryInspector

Page 49: Got Index?

Index optimization

detectobsolete indexes

contributers

Page 50: Got Index?