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

Compound index is not being used for query #2448

Open
thegithubuserguy opened this issue Mar 14, 2024 · 0 comments
Open

Compound index is not being used for query #2448

thegithubuserguy opened this issue Mar 14, 2024 · 0 comments
Labels

Comments

@thegithubuserguy
Copy link

thegithubuserguy commented Mar 14, 2024

I have larger documents I'm storing in a collection, so I'm working hard to avoid full document scans.
Using v5.0.17
The documents each have 2 numeric fields: Unit and StepNumber. I'm using the following to create the index:

dbCollection.EnsureIndex(x => new { x.Unit, x.StepNumber });

I've confirmed that the index exists in the System $indexes table:
"units" "UnitUnitStepNumberStepNumber" "{Unit:$.Unit,StepNumber:$.StepNumber}" false 15

However, when I view the query execution plan it is clearly not using this index:

EXPLAIN
SELECT $ FROM units
where Unit = 38
AND StepNumber >= 356
AND StepNumber <= 360

Results - index:
{"name":"Unit","expr":"$.Unit","order":1,"mode":"INDEX SEEK(Unit = 38)","cost":10}

Any ideas on why it would not be using the compound index?

@mbdavid - any thoughts?

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

No branches or pull requests

1 participant