[DOCS-11634] Improve Performance with Indexes Created: 18/Apr/18  Updated: 30/Oct/23  Resolved: 09/Oct/19

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Shinyou Hwang Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: nyu
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
backported by JAVA-2104 Add explain() capability for new Java... Closed
Participants:
Days since reply: 5 years, 42 weeks, 6 days ago
Epic Link: NYU Sample Apps Project

 Description   

Use indexes to improve querying of data

Use explain feature to look into how indexes are being used (refer linked issue)



 Comments   
Comment by Shinyou Hwang [ 19/Apr/18 ]

shannon.bradshaw

For checking the performance of indexing, I have written a small code that iterates through the data and displays if the indexes are used or not, and the execution stats.
https://github.com/mongodb/sample-apps-nyu/blob/hsy-docs-11634/Index/src/DataIndex.java

I have used the work around option to display $explain in Java program as mentioned in https://jira.mongodb.org/browse/JAVA-2104

However the execution stats displayed in Java program and the console is different. The console displays the change in the number of total docs examined as 99 before indexing and 7 after indexing. However in the Java program, when I am displaying the execution stats, the docs examined before and after indexing is displayed as 1.
Not sure where I am going wrong. Could you please have a look?

for console:
mongo "mongodb+srv://sandbox-trhqa.mongodb.net/test" --username m001-student --password student123#
use stores
db.orders.find({'shippingAddress.state': 'Texas',tax: {$gt: 50}}).explain("executionStats")
db.orders.createIndex(

{"shippingAddress.state":1}

)
db.orders.find({'shippingAddress.state': 'Texas',tax: {$gt: 50}}).explain("executionStats")
db.orders.dropIndex(

{"shippingAddress.state":1}

)

Generated at Thu Feb 08 08:03:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.