Skip to content

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

satishsuryanarayan
Copy link

No description provided.

@satishsuryanarayan
Copy link
Author

@alecgrieser @ohadzeliger @normen662 @arnaud-lacurie My first PR - please review at your convenience.

/**
* Explain level. Adjusts the granularity of explain output.
*/
public final class ExplainLevel {
public enum ExplainLevel {
Copy link
Contributor

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?

Copy link
Author

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);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please undo

Copy link
Author

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)); }
;
;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normen662 Done!

Copy link
Author

@satishsuryanarayan satishsuryanarayan left a 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.

Copy link
Contributor

@hatyo hatyo left a 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;
Copy link
Contributor

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)?
Copy link
Contributor

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.

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.explainLevel = ExplainLevel.SOME_DETAILS;
explainLevel = ExplainLevel.SOME_DETAILS;

Copy link
Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void setExplainLevel(final int explainLevel) {
public void setExplainLevel(int explainLevel) {

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.explainLevel = level;
explainLevel = level;

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private int explainLevel;
private boolean isVerboseExplain;

Copy link
Author

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")) {
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment on lines 541 to 543
getDelegate().getPlanGenerationContext().setExplainLevel(ExplainLevel.ALL_DETAILS);
} else if (!ctx.describeObjectClause().getTokens(RelationalLexer.MINIMAL).isEmpty()) {
getDelegate().getPlanGenerationContext().setExplainLevel(ExplainLevel.STRUCTURE);
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@satishsuryanarayan
Copy link
Author

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

@hatyo Thanks for the feedback - I will work on the suggestions.

@satishsuryanarayan
Copy link
Author

@hatyo I updated the PR with the suggested changes. Please review at your convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants