[CSHARP-4008] Provide more flexible public API for $explain Created: 06/Jan/22  Updated: 11/Jan/22  Resolved: 11/Jan/22

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Dmitry Lukyanov (Inactive) Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Issue split
split from CSHARP-3980 Remove reliance on "$explain" modifie... Closed

 Description   

In the scope of CSHARP-3980, we've added supporting for $explain modifier for OP_MSG. We should consider adding richer public API including fluent API Explain method.

Also, only Find command currently supports $explain in the modern driver, we should consider adding this modifier at least to Aggregate.



 Comments   
Comment by Dmitry Lukyanov (Inactive) [ 11/Jan/22 ]

At this point, we've decided to not introduce any new public API for explain and stick to what CRUD spec recommend, see What about explain? here

Comment by Robert Stam [ 07/Jan/22 ]

This is a much larger task than it might appear at first glance. There are many operations that could be "explained". How many of them should we support? If we support some shouldn't we support all?

Here's a first level approximation of the methods that might potentially be required:

IAggregateFluentExtensions.Explain
IFindFluentExtensions.Explain
IMongoCollection.ExplainAggregate
IMongoCollection.ExplainAggregateToCollection
IMongoCollection.ExplainBulkWrite
IMongoCollection.ExplainCount
IMongoCollection.ExplainDeleteOne
IMongoCollection.ExplainDeleteMany
IMongoCollection.ExplainDistinct
IMongoCollection.ExplainFindSync
IMongoCollection.ExplainFindOneAndDelete
IMongoCollection.ExplainFindOneAndReplace
IMongoCollection.ExplainFindOneAndUpdate
IMongoCollection.ExplainMapReduce
IMongoCollection.ExplainReplaceOne
IMongoCollection.ExplainUpdateMany
IMongoCollection.ExplainUpdateOne
IMongoCollection.ExplainAggregate
IMongoCollection.ExplainAggregateToCollection
MongoQueryable.Explain (plus dozens more like ExplainAll, ExplainAny, ExplainAverage, ExplainCount, etc... for all the scalar LINQ methods)

Then we need to consider that many of these methods have multiple overloads (with/without session, Definition vs Expression, etc...) and figure out whether they all need to be supported as well. Most likely the session overloads are not needed for Explain, but the Definition vs Expression overloads would be.

Also, all of those methods have Async versions as well. It would probably be acceptable to not provide async versions of Explain methods, since Explain methods should only be used during development and forcing the use of sync Explain methods (even in async programs) is probably OK.

Lastly, there is the question whether all these helper methods should be added at all.

Quoting from the CRUD spec:

Explain has been determined to be not a normal use-case for a driver. We'd like users to use the shell for this purpose.

The counter argument is that it might not be easy for the application developer to know exactly what query is actually being sent to the server, which would be required in order to use the shell for this purpose.

 

Generated at Wed Feb 07 21:46:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.