Closed hmatanock closed 3 years ago
Looking at https://docs.mongodb.com/php-library/v1.4/reference/method/MongoDBCollection-find/ this is definitely an oversight, find
is accepting the hint
option. @hmatanock would you be up for a PR fixing the issue and covering it with a test so we won't lose this again?
EDIT: actually I'm not sure if a test can be written easily, still worth exploring tho
actually I'm not sure if a test can be written easily, still worth exploring tho
Here's a test plan:
find
command sent to the server contains the correct hint
query option
BC Break Report
Summary
The database for our project is actually AWS's DocumentDB service. I will say off the bat that I do understand that it's not technically MongoDB, and there are some feature differences - however, we recently upgraded our Symfony project from v 1.1 to v2.0 (technically we upgraded doctrine/mongo-odm-bundle from ^3.5 to ^4.3) and things were working much better before the upgrade.
We are experiencing very long query times on some particular queries, that are definitely covered by indexes. Performance logging in AWS indicates that Document DB is choosing to not use any indexes for the query, and so in this case the AWS documentation recommends using index hints on the queries to force DocumentDB to use the index.
Previous behavior
Before we upgraded, the hints were being added to the find query
Current behavior
Index hints are not passing through to the query.
How to reproduce
I'm actually not totally sure how to describe how to reproduce the behavior, but I've identified where in the code this is going wrong.
First, we use DoctrineQueryBuilder->hint() method to create a query, and add an index hint.
https://github.com/doctrine/mongodb-odm/blob/2.2.x/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L782
In that MongoDB/Query/Query object that is created, the hint is definitely present, but when it comes time to pass the data to the collection->find(), the hint is not added to the $queryOptions https://github.com/doctrine/mongodb-odm/blob/2.2.x/lib/Doctrine/ODM/MongoDB/Query/Query.php#L427
For some reason the hint IS being added to count queries later in that same switch, so I'm not sure if it's being intentionally left off of the finds: https://github.com/doctrine/mongodb-odm/blob/2.2.x/lib/Doctrine/ODM/MongoDB/Query/Query.php#L508
In my test server, if I manually add 'hint' to line#427 above, my page load time goes from around 14803ms to 505ms.