indexing - Mongodb - increasing performance using compound index when pagination -
i'm newbie mongodb , need increasing performance queries using compound indexes.
i using pagination using "_id" field. query:
db.data.find( {"$or": [ { "cat": "5" }, {"cat": "6" } ] }, {"style": "3"}, {"area": "london"}, {"_id": {"$lt": 103}).sort( { "_id": 1 } ).limit(30)
style
, area
can optional these possible.
db.data.find( {"$or": [ { "cat": "5" }, {"cat": "6" } ] }, {"area": "london"}, {"_id": {"$lt": 103}).sort( { "_id": 1 } ).limit(30) db.data.find( {"$or": [ { "cat": "5" }, {"cat": "6" } ] }, {"style": "3"}, {"_id": {"$lt": 103}).sort( { "_id": 1 } ).limit(30) db.data.find( {"$or": [ { "cat": "5" }, {"cat": "6" } ] }, {"_id": {"$lt": 103}).sort( { "_id": 1 } ).limit(30)
will these queries ok compound index, or need more additional index?
{ "cat": 1, "style": 1, "area": 1, "_id": 1 }
edit
i'm not sure of these index efficient queries.
{ "cat": 1, "style": 1, "area": 1, "_id": 1 } or { "_id": 1, "cat": 1, "style": 1, "area": 1 }
number of styles: 16
number of areas: 50
number of id: 10 million
use
{ "_id": 1, "cat": 1, "style": 1, "area": 1 }
objectid has structure:
0 1 2 3 | 4 5 6 | 7 8 | 9 10 11 timestamp | machine | pid | increment
because timestamp
comes first in above structure, sort in insertion order.
when id came first in index, reduce looking objects.
Comments
Post a Comment