-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: add explain support for non-cursor commands #2599
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
Merged
HanaPearlman
merged 26 commits into
mongodb:master
from
HanaPearlman:NODE-2852/master/explain-non-cursor
Nov 16, 2020
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a8dfabe
FindOneOperation extends CommandOperation
HanaPearlman 5bded70
implement explain for write commands
HanaPearlman 4374b6b
implement explain for distinct command
HanaPearlman f00fbfe
implement explain for findAndModify commands
HanaPearlman 1d937a8
implement explain for mapReduce command
HanaPearlman 2a9b1be
first attempt: handle removing sessions for write operations
HanaPearlman 237a70f
consider explain during canRetryWrite
HanaPearlman c2d0a53
small enum cleanup
HanaPearlman 0126381
model explain after read concern
HanaPearlman 82715bd
create ExplainableCommand class
HanaPearlman 3bf0d78
check explain value in explain command constructor
HanaPearlman 7090c39
quick cursor fix
HanaPearlman 82f0e60
move explain cmd/options to separate file
HanaPearlman f5e65ed
some commenting
HanaPearlman 4bdf503
respond to comments
HanaPearlman 03333d7
test bug fix
HanaPearlman 20ef5da
Merge branch 'master' into NODE-2852/master/explain-non-cursor
HanaPearlman c1a4ff9
add explain-related exports to index
HanaPearlman 2c7334b
use aspects and throw from fromOptions
HanaPearlman d486214
use expanded explain types for clarity
HanaPearlman ddc9826
change test names and ordering
HanaPearlman 6a17656
clean up
HanaPearlman 7235fb7
Merge branch 'master' into NODE-2852/master/explain-non-cursor
HanaPearlman 001ec2e
fix explain export in index
HanaPearlman 0b37761
check explain supported in individual op classes
HanaPearlman 31bb9eb
Merge branch 'master' into NODE-2852/master/explain-non-cursor
HanaPearlman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { MongoError } from './error'; | ||
|
||
/** @public */ | ||
export const ExplainVerbosity = { | ||
queryPlanner: 'queryPlanner', | ||
queryPlannerExtended: 'queryPlannerExtended', | ||
executionStats: 'executionStats', | ||
allPlansExecution: 'allPlansExecution' | ||
} as const; | ||
|
||
/** | ||
* For backwards compatibility, true is interpreted as | ||
* "allPlansExecution" and false as "queryPlanner". | ||
* @public | ||
*/ | ||
export type ExplainVerbosityLike = keyof typeof ExplainVerbosity | boolean; | ||
|
||
/** @public */ | ||
export interface ExplainOptions { | ||
/** Specifies the verbosity mode for the explain output. */ | ||
explain?: ExplainVerbosityLike; | ||
} | ||
|
||
/** @internal */ | ||
export class Explain { | ||
verbosity: keyof typeof ExplainVerbosity; | ||
|
||
constructor(verbosity: ExplainVerbosityLike) { | ||
if (typeof verbosity === 'boolean') { | ||
this.verbosity = verbosity | ||
? ExplainVerbosity.allPlansExecution | ||
: ExplainVerbosity.queryPlanner; | ||
} else { | ||
this.verbosity = ExplainVerbosity[verbosity]; | ||
} | ||
} | ||
|
||
static fromOptions(options?: ExplainOptions): Explain | undefined { | ||
if (options?.explain === undefined) return; | ||
|
||
const explain = options.explain; | ||
if (typeof explain === 'boolean' || explain in ExplainVerbosity) { | ||
return new Explain(explain); | ||
} | ||
|
||
throw new MongoError(`explain must be one of ${Object.keys(ExplainVerbosity)} or a boolean`); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a stylistic nit, but I think it'd be better to do
cmd.explain ? decorateWithExplain(cmd, cmd.explain) : cmd
here rather than reassigning thecmd
parameter.