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

Matcher to test that a query is covered by an index (covered query) #238

Open
Startouf opened this issue Nov 13, 2020 · 1 comment
Open

Comments

@Startouf
Copy link

Startouf commented Nov 13, 2020

Would it be possible to make make a matcher to ensure that a given request is a covered query ?

We could take advantage of mongodb's explain feature to check this.

I have written some basic tests that make sure the winning plan relies on an IXSCAN, I believe it would be possible to build more advanced matchers based on this ?

I know it mainly depends on what data you need to retrieve, but it could prove very useful to ensure the code is fast.
Note that it may be slightly more difficult for special queries like count

let(:winning_plan) { criteria.explain.dig('queryPlanner', 'winningPlan') }
expect(winning_plan).to include('stage' => 'IXSCAN')
@Startouf Startouf changed the title Matcher to test that a query is covered by an index Matcher to test that a query is covered by an index (covered query) Nov 13, 2020
@dblock
Copy link
Collaborator

dblock commented Nov 13, 2020

Good idea.

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

No branches or pull requests

2 participants