-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Profile] Visualize the query plan and query profile #5475
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
37 changes: 37 additions & 0 deletions
37
fe/fe-core/src/main/java/org/apache/doris/analysis/ExplainOptions.java
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,37 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.doris.analysis; | ||
|
|
||
| public class ExplainOptions { | ||
|
|
||
| private boolean isVerbose; | ||
| private boolean isGraph; | ||
|
|
||
| public ExplainOptions(boolean isVerbose, boolean isGraph) { | ||
| this.isVerbose = isVerbose; | ||
| this.isGraph = isGraph; | ||
| } | ||
|
|
||
| public boolean isVerbose() { | ||
| return isVerbose; | ||
| } | ||
|
|
||
| public boolean isGraph() { | ||
| return isGraph; | ||
| } | ||
| } |
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
164 changes: 164 additions & 0 deletions
164
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryProfileStmt.java
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,164 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.doris.analysis; | ||
|
|
||
| import org.apache.doris.catalog.Column; | ||
| import org.apache.doris.catalog.ScalarType; | ||
| import org.apache.doris.common.AnalysisException; | ||
| import org.apache.doris.common.UserException; | ||
| import org.apache.doris.qe.ShowResultSetMetaData; | ||
|
|
||
| import com.google.common.base.Strings; | ||
|
|
||
| // For stmt like: | ||
| // show query profile "/"; # list all saving query ids | ||
| // show query profile "/e0f7390f5363419e-b416a2a79996083e" # show graph of fragments of the query | ||
| // show query profile "/e0f7390f5363419e-b416a2a79996083e/0" # show instance list of the specified fragment | ||
| // show query profile "/e0f7390f5363419e-b416a2a79996083e/0/e0f7390f5363419e-b416a2a799960906" # show graph of the instance | ||
| public class ShowQueryProfileStmt extends ShowStmt { | ||
| // This should be same as ProfileManager.PROFILE_HEADERS | ||
| private static final ShowResultSetMetaData META_DATA_QUERYIDS = | ||
| ShowResultSetMetaData.builder() | ||
| .addColumn(new Column("QueryId", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("User", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("DefaultDb", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("SQL", ScalarType.createVarchar(65535))) | ||
| .addColumn(new Column("QueryType", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("StartTime", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("EndTime", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("TotalTime", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("QueryState", ScalarType.createVarchar(128))) | ||
| .build(); | ||
|
|
||
| private static final ShowResultSetMetaData META_DATA_FRAGMENTS = | ||
| ShowResultSetMetaData.builder() | ||
| .addColumn(new Column("Fragments", ScalarType.createVarchar(65535))) | ||
| .build(); | ||
| private static final ShowResultSetMetaData META_DATA_INSTANCES = | ||
| ShowResultSetMetaData.builder() | ||
| .addColumn(new Column("Instances", ScalarType.createVarchar(128))) | ||
| .addColumn(new Column("Host", ScalarType.createVarchar(64))) | ||
| .addColumn(new Column("ActiveTime", ScalarType.createVarchar(64))) | ||
| .build(); | ||
| private static final ShowResultSetMetaData META_DATA_SINGLE_INSTANCE = | ||
| ShowResultSetMetaData.builder() | ||
| .addColumn(new Column("Instance", ScalarType.createVarchar(65535))) | ||
| .build(); | ||
|
|
||
| public enum PathType { | ||
| QUERY_IDS, | ||
| FRAGMETNS, | ||
| INSTANCES, | ||
| SINGLE_INSTANCE | ||
| } | ||
|
|
||
| private String queryIdPath; | ||
| private PathType pathType; | ||
|
|
||
| private String queryId = ""; | ||
| private String fragmentId = ""; | ||
| private String instanceId = ""; | ||
|
|
||
| public ShowQueryProfileStmt(String queryIdPath) { | ||
| this.queryIdPath = queryIdPath; | ||
| } | ||
|
|
||
| public PathType getPathType() { | ||
| return pathType; | ||
| } | ||
|
|
||
| public String getQueryId() { | ||
| return queryId; | ||
| } | ||
|
|
||
| public String getFragmentId() { | ||
| return fragmentId; | ||
| } | ||
|
|
||
| public String getInstanceId() { | ||
| return instanceId; | ||
| } | ||
|
|
||
| @Override | ||
| public void analyze(Analyzer analyzer) throws UserException { | ||
| super.analyze(analyzer); | ||
| if (Strings.isNullOrEmpty(queryIdPath)) { | ||
| // list all query ids | ||
| pathType = PathType.QUERY_IDS; | ||
| return; | ||
| } | ||
|
|
||
| if (!queryIdPath.startsWith("/")) { | ||
| throw new AnalysisException("Query path must starts with '/'"); | ||
| } | ||
| pathType = PathType.QUERY_IDS; | ||
| String[] parts = queryIdPath.split("/"); | ||
| if (parts.length > 4) { | ||
| throw new AnalysisException("Query path must in format '/queryId/fragmentId/instanceId'"); | ||
| } | ||
|
|
||
| for (int i = 0; i < parts.length; i++) { | ||
| switch (i) { | ||
| case 0: | ||
| pathType = PathType.QUERY_IDS; | ||
| continue; | ||
| case 1: | ||
| queryId = parts[i]; | ||
| pathType = PathType.FRAGMETNS; | ||
| break; | ||
| case 2: | ||
| fragmentId = parts[i]; | ||
| pathType = PathType.INSTANCES; | ||
| break; | ||
| case 3: | ||
| instanceId = parts[i]; | ||
| pathType = PathType.SINGLE_INSTANCE; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toSql() { | ||
| StringBuilder sb = new StringBuilder("SHOW QUERY PROFILE ").append(queryIdPath); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return toSql(); | ||
| } | ||
|
|
||
| @Override | ||
| public ShowResultSetMetaData getMetaData() { | ||
| switch (pathType) { | ||
| case QUERY_IDS: | ||
| return META_DATA_QUERYIDS; | ||
| case FRAGMETNS: | ||
| return META_DATA_FRAGMENTS; | ||
| case INSTANCES: | ||
| return META_DATA_INSTANCES; | ||
| case SINGLE_INSTANCE: | ||
| return META_DATA_SINGLE_INSTANCE; | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
| } |
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.
Change
KW_DESCRIBEtoKW_EXPLAINThere 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.
KW_DESCRIBE means both "desc" and "explain",
see
fe/fe-core/src/main/jflex/sql_scanner.flex