[JAVA-2637] access count of compound index in $indexStats java driver Created: 16/Oct/17 Updated: 27/Oct/23 Resolved: 16/Nov/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Query Operations |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Paul Lin | Assignee: | Unassigned |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
CentOS |
||
| Description |
|
I met a strange phenomenon, hope someone can provide a little clue to answer. |
| Comments |
| Comment by Jeffrey Yemin [ 16/Nov/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
paullin as I haven't heard back from you in answer to my most recent question, I'm closing this issue. I'll be happy to re-open it if you can provide more information. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Nov/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Looking at your command line of java -cp . CompoundIndexTest, I wouldn't expect it to work as you don't include the mongo-java-driver JAR file. As for the compilation, you do not need to include both mongo-java-driver and bson JAR files, as the mongo-java-driver JAR file is an Uber jar which contains all the class that are in bson.jar. With regard to index use, please provide a complete working test program for us to try to reproduce the issue, as we have been unable to do so given the information you've provided so far. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Paul Lin [ 18/Oct/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It is my mistake to provide incomplete information. I did run test twice. First test runs with .modifiers(new Document("$explain", true)) and gets result of "index in winningPlan". Second one runs with .iterator() instead and gets "counter didn't changed" by checking $indexStats in shell manually. BTW, I put downloaded bson-3.0.4.jar, mongo-java-driver-3.4.3.jar and the code you provided, saved as CompoundIndexTest.java, in same folder then compiled it in command line: javac -cp ./mongo-java-driver-3.4.3.jar:./bson-3.0.4.jar CompoundIndexTest.java Second error occurred as I executed it in command line: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 17/Oct/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I wouldn't expect this test to hit the index because it's running an explain rather than the actual query. This slightly modified program demonstrates that the index is accessed:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Paul Lin [ 17/Oct/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I did use iterator() in my test code. here is my test code:
Hope this could help to reveal something. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 16/Oct/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have an idea what might be happening. The Java driver has a fluent API for the find() method, and as a result the query is only executed when the application actually starts iterating the results. So:
will not execute the query on the server, while
will. Please confirm whether this might be the root cause. Otherwise, please provide some sample code so we can investigate further. |