feat: EXPOSED-238 Support EXPLAIN statements #2022
Merged
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.
explain()
takes any valid SELECT, INSERT, UPDATE, DELETE etc statement in its lambda body.It blocks the execution of this internal statement and uses it to prepare an EXPLAIN query, which returns a result set of query execution path details (very different depending on database).
It acts like a standard
Query
in that it will not be executed until it is iterated over in some way:explain()
blocks execution of the lambda statement by using 2 new Transaction properties.1 of these properties makes sure that the lambda statement is captured so it can be passed to the
ExplainQuery
constructor, since not all statement functions returnStatement<*>
(namelyupdate()
anddelete()
return numbers).Next steps:
ResultSet
. Instead, EXPLAIN PLAN expects an output table to exist for holding the result rows. Still need to decide if this is a table Exposed should create (and later drop) or if responsibility should go to the user. More details at EXPOSED-308.ResultRow
's logic is too specific to Exposed table columns and expressions. It acts in a very similar way but is currently only set up to output the string results (as above) and should have getters and some API functions added. More details at EXPOSED-309.Not supported:
explain()
, but this view may be wrong. Blocking execution would also mean blocking all the extra entity steps under-the-hood and in the cache. If requested, starting with SELECT would be the easiest to support (and its the most common use for EXPLAIN).