-
Notifications
You must be signed in to change notification settings - Fork 111
Enhancement #3028: Add verbosity-level option to SQL EXPLAIN #3485
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
base: main
Are you sure you want to change the base?
Conversation
@alecgrieser @ohadzeliger @normen662 @arnaud-lacurie My first PR - please review at your convenience. |
…sitFullDescribeStatement
/** | ||
* Explain level. Adjusts the granularity of explain output. | ||
*/ | ||
public final class ExplainLevel { | ||
public enum ExplainLevel { |
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.
Let's not introduce yet another naming of the same underlying thing. Can't you make the ExplainLevel an enum directly?
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.
Done!
@@ -1346,8 +1348,6 @@ fragment INT_TYPE_MODIFIER: ('I' | 'i'); | |||
fragment LONG_TYPE_MODIFIER: ('L' | 'l'); | |||
fragment DECIMAL_TYPE_MODIFIER: (INT_TYPE_MODIFIER | LONG_TYPE_MODIFIER); | |||
|
|||
|
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.
please undo
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.
Done!
@@ -1352,4 +1354,4 @@ fragment DECIMAL_TYPE_MODIFIER: (INT_TYPE_MODIFIER | LONG_TYPE_MODIFIER); | |||
|
|||
ERROR_RECOGNITION | |||
: . { this.notifyListeners(new LexerNoViableAltException(this, _input, _tokenStartCharIndex, null)); } | |||
; | |||
; |
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.
@normen662 Done!
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.
@normen662 I undid my changes to ExplainLevel as suggested.
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.
Thank you for creating the PR, nice work, I left few comments.
Please align your PR description with the conventions in this repo adding explanation, and referencing the corresponding GitHub issue with a hyperlink, this is important for other downstream GitHub tasks that generate the changelog, you can look here for example:
#3511
@@ -89,6 +88,8 @@ public class MutablePlanGenerationContext implements QueryExecutionContext { | |||
|
|||
private boolean forExplain; | |||
|
|||
private int explainLevel; |
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.
would be nicer to use an enum instead of int
to make the intention clear, you can also use a boolean if choices degenerate to two (verbose / not verbose)
@@ -645,7 +645,8 @@ helpStatement | |||
// details | |||
|
|||
describeObjectClause | |||
: ( | |||
: level=(VERBOSE | MINIMAL)? |
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.
I don't think we want MINIMAL
verbosity here. Please remove it and leave an optional VERBOSE
.
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.
Done!
@@ -261,6 +262,7 @@ public MutablePlanGenerationContext(@Nonnull PreparedParams preparedParams, | |||
constantObjectValues = new LinkedList<>(); | |||
shouldProcessLiteral = true; | |||
forExplain = false; | |||
this.explainLevel = ExplainLevel.SOME_DETAILS; |
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.explainLevel = ExplainLevel.SOME_DETAILS; | |
explainLevel = ExplainLevel.SOME_DETAILS; |
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.
Done!
@@ -372,6 +378,10 @@ public void setForExplain(boolean forExplain) { | |||
this.forExplain = forExplain; | |||
} | |||
|
|||
public void setExplainLevel(final int explainLevel) { |
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.
public void setExplainLevel(final int explainLevel) { | |
public void setExplainLevel(int explainLevel) { |
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.
Done!
@@ -146,6 +159,12 @@ public Builder setForExplain(boolean isForExplain) { | |||
return this; | |||
} | |||
|
|||
@Nonnull | |||
public Builder setExplainLevel(int level) { | |||
this.explainLevel = level; |
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.explainLevel = level; | |
explainLevel = level; |
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.
Done!
@@ -107,6 +117,8 @@ public static final class Builder { | |||
|
|||
private boolean isForExplain; | |||
|
|||
private int explainLevel; |
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.
private int explainLevel; | |
private boolean isVerboseExplain; |
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.
Done!
@@ -73,7 +73,7 @@ void explainResultSetMetadataTest() throws Exception { | |||
final var expectedContTypes = List.of(Types.BINARY, Types.INTEGER, Types.VARCHAR); | |||
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) { | |||
executeInsert(ddl); | |||
try (RelationalPreparedStatement ps = ddl.setSchemaAndGetConnection().prepareStatement("EXPLAIN SELECT * FROM RestaurantComplexRecord")) { | |||
try (RelationalPreparedStatement ps = ddl.setSchemaAndGetConnection().prepareStatement("EXPLAIN VERBOSE SELECT * FROM RestaurantComplexRecord")) { |
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.
please revert, and add targeted tests for verbose
in separate tests
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.
Done!
getDelegate().getPlanGenerationContext().setExplainLevel(ExplainLevel.ALL_DETAILS); | ||
} else if (!ctx.describeObjectClause().getTokens(RelationalLexer.MINIMAL).isEmpty()) { | ||
getDelegate().getPlanGenerationContext().setExplainLevel(ExplainLevel.STRUCTURE); |
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.
I don't think we care about this level of distinction here, only an optional verbose
, it is aligned with Postgres.
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.
Done!
@hatyo Thanks for the feedback - I will work on the suggestions. |
@hatyo I updated the PR with the suggested changes. Please review at your convenience. |
No description provided.