Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dex doesn't recommend indexes when sort operation is provided #21

Open
Sirtea opened this issue Nov 4, 2013 · 3 comments
Open

Dex doesn't recommend indexes when sort operation is provided #21

Sirtea opened this issue Nov 4, 2013 · 3 comments

Comments

@Sirtea
Copy link

Sirtea commented Nov 4, 2013

Having the following collection:

> db.people.find()
{ "_id" : ObjectId("52779d40ad2f74e0deb3a7cf"), "name" : "Gerard", "age" : 31 }
{ "_id" : ObjectId("52779d83ad2f74e0deb3a7d0"), "name" : "Rose", "age" : 23 }
{ "_id" : ObjectId("52779d9ead2f74e0deb3a7d1"), "name" : "Yuki", "age" : 30 }
> 

I tried some basic queries, for example:

> db.people.find({age:{$gte:30}}).sort({name:1})
> db.people.find({age:{$gte:30}})

Passing the DEX tool to an empty system.profile collection, I can see that there's a suggestion when issuing the second query, but not when using the first one.

With sort operation:

> db.system.profile.drop()
true
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "ok" : 1 }
> db.people.find({age:{$gte:30}}).sort({name:1})
{ "_id" : ObjectId("52779d40ad2f74e0deb3a7cf"), "name" : "Gerard", "age" : 31 }
{ "_id" : ObjectId("52779d9ead2f74e0deb3a7d1"), "name" : "Yuki", "age" : 30 }
> db.setProfilingLevel(0)
{ "was" : 2, "slowms" : 100, "ok" : 1 }
> 
(env)gerard@antares:~/projects/dextest$ dex -p mongodb://localhost/test
{
    'runStats': {
        'linesRecommended': 0, 
        'linesProcessed': 1, 
        'linesPassed': 2
    }, 
    'results': []
}
(env)gerard@antares:~/projects/dextest$ 

Without sort operation:

> db.system.profile.drop()
true
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "ok" : 1 }
> db.people.find({age:{$gte:30}})
{ "_id" : ObjectId("52779d40ad2f74e0deb3a7cf"), "name" : "Gerard", "age" : 31 }
{ "_id" : ObjectId("52779d9ead2f74e0deb3a7d1"), "name" : "Yuki", "age" : 30 }
> db.setProfilingLevel(0)
{ "was" : 2, "slowms" : 100, "ok" : 1 }
> 
(env)gerard@antares:~/projects/dextest$ dex -p mongodb://localhost/test
{
    'runStats': {
        'linesRecommended': 1, 
        'linesProcessed': 1, 
        'linesPassed': 2
    }, 
    'results': [
        {
            'queryMask': '{"$query":{"age":{"$gte":"<val>"}}}', 
            'namespace': 'test.people', 
            'recommendation': {
                'index': '{"age": 1}', 
                'namespace': 'test.people', 
                'shellCommand': 'db["people"].ensureIndex({"age": 1}, {"background": true})'
            }, 
            'details': {
                'count': 1, 
                'totalTimeMillis': 0, 
                'avgTimeMillis': 0
            }
        }
    ]
}
(env)gerard@antares:~/projects/dextest$ 
@esedor
Copy link
Contributor

esedor commented Nov 4, 2013

Thanks for this detailed report! I'll take a look. One question: Are you working with the HEAD of this Dex repo, or the last release of Dex on pypi?

@Sirtea
Copy link
Author

Sirtea commented Nov 6, 2013

Not sure, it was the pypi version, installed via pip in a virtualenv

(env)gerard@antares:~/projects/dextest$ pip freeze
Dex==0.6
PyYAML==3.10
argparse==1.2.1
dargparse==0.2.3
ordereddict==1.1
pymongo==2.6.3
wsgiref==0.1.2
(env)gerard@antares:~/projects/dextest$ 

@srlowe
Copy link

srlowe commented Jul 29, 2015

Any update on this? I'm having the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants