Comment 14 for bug 1597679

Revision history for this message
Igor Degtiarov (idegtiarov) wrote :

@magicboiz

Hi! Let me explain why we've propose patch with moving from compound indexes to set of single ones. The main reason was avoid whole database scanning in requests when used only one or several fields without compound's "prefix". For example it was happened in almost all sample-list queries. The pretty same situation we had in statistic queries when "prefix" part of compound index wasn't used in query. That is why by default we create single indexes instead of compound.

From other side if we know that main use case is getting statistics and we have field that will be used in every request - indexes should be changed to compound. Your proposition is not good enough I need to emphasize that timestamp as a "prefix" field is a bad choice. Field that will have bounds in request should be the last in index creation list. So it seems that in your case when project_id and resource_id could be absent in request the best choice will be:

db.meter.createIndex({counter_name:1, resource_id:1, project_id:1, timestamp:-1}, {name: "statistic_idx", background: true})

If statistics is the main and exclusive use case other meter indexes except ttl should be dropped to release occupied memory.