-
Notifications
You must be signed in to change notification settings - Fork 132
feat: Add support for Explain feature #1852
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
Changes from 1 commit
1ea42dd
8c7a5b0
177f07f
242e351
053dd92
0677368
87069ed
436775b
5047608
f09c6e3
411ca77
f663865
4b7127d
e3614be
e125c42
af79b7b
7a1937a
d0c6abf
9f084ba
0f76847
daddd3e
e38e917
60ad94e
e2813ab
32fc9de
e57da64
b4101ad
c59e964
a767158
1a8fd85
50808f1
1f4aa32
0610cae
faaa7cd
dc9dab2
4177cdd
105d8a5
6162363
d58acc0
638ae76
07e521c
dd9e83e
55f1736
2d7649f
40b3f89
c272165
10f06e8
8695453
0b66c53
a08c293
9996f1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -489,7 +489,7 @@ private String processExecutionStats(PlanNode planNode) { | |
return executionStats.toString(); | ||
} | ||
|
||
private StatementResult getStatementResultFromQueryPlan(QueryPlan queryPlan, boolean isAnalyse) { | ||
private StatementResult getStatementResultFromQueryPlan(QueryPlan queryPlan, boolean isAnalyze) { | ||
ArrayList<Struct> list = new ArrayList<>(); | ||
for (PlanNode planNode : queryPlan.getPlanNodesList()) { | ||
String planNodeDescription = planNode.getDisplayName(); | ||
|
@@ -503,19 +503,19 @@ private StatementResult getStatementResultFromQueryPlan(QueryPlan queryPlan, boo | |
planNodeDescription += " : " + planNode.getShortRepresentation().getDescription(); | ||
} | ||
|
||
if (isAnalyse && !planNode.getExecutionStats().toString().equals("")) { | ||
if (isAnalyze && !planNode.getExecutionStats().toString().equals("")) { | ||
executionStats = processExecutionStats(planNode); | ||
} | ||
Struct.Builder builder = Struct.newBuilder().set("QUERY PLAN").to(planNodeDescription); | ||
|
||
if (isAnalyse) { | ||
if (isAnalyze) { | ||
builder.set("EXECUTION STATS").to(executionStats); | ||
} | ||
list.add(builder.build()); | ||
} | ||
|
||
ResultSet resultSet; | ||
if (isAnalyse) { | ||
if (isAnalyze) { | ||
resultSet = | ||
ResultSets.forRows( | ||
Type.struct( | ||
|
@@ -583,11 +583,11 @@ public StatementResult statementExplain(String sql) { | |
String.format("Missing closing parenthesis in the query: %s", sql)); | ||
} | ||
String options[] = sql.substring(1, index).split("\\s*,\\s*"); | ||
boolean isAnalyse = false, startAfterIndex = false; | ||
boolean isAnalyze = false, startAfterIndex = false; | ||
for (String option : options) { | ||
String optionExpression[] = option.trim().split("\\s+"); | ||
if (optionExpression.length >= 3) { | ||
isAnalyse = false; | ||
isAnalyze = false; | ||
break; | ||
} else if (ClientSideStatementExplainExecutor.EXPLAIN_OPTIONS.contains( | ||
optionExpression[0].toLowerCase())) { | ||
|
@@ -596,27 +596,27 @@ public StatementResult statementExplain(String sql) { | |
String.format("%s is not implemented yet", optionExpression[0])); | ||
} else if (optionExpression[0].equalsIgnoreCase("analyse") | ||
|| optionExpression[0].equalsIgnoreCase("analyze")) { | ||
isAnalyse = true; | ||
isAnalyze = true; | ||
} else { | ||
isAnalyse = false; | ||
isAnalyze = false; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here: I think that an unknown/invalid option expression should cause a failure, not be assumed to mean 'analyze is not in the options expression'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there will be an unknown option like "explain (foo) select * from table", then it will send "(foo) select * from table" as the query, which will eventually cause exception. Its just the error message will not be appropriate (it will be something like "(foo) select * from table" is not a query). Writing code for a solution which distinguishes the error message will be a bit tricky. Because, for the cases like "explain (select * from table)", it will be difficult to identify if the string "select" is an unknown option or a part of some query. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
} | ||
|
||
if (optionExpression.length == 2) { | ||
if (optionExpression[1].equalsIgnoreCase("false") | ||
|| optionExpression[1].equalsIgnoreCase("0") | ||
|| optionExpression[1].equalsIgnoreCase("off")) { | ||
isAnalyse = false; | ||
isAnalyze = false; | ||
startAfterIndex = true; | ||
} else if (!(optionExpression[1].equalsIgnoreCase("true") | ||
|| optionExpression[1].equalsIgnoreCase("1") | ||
|| optionExpression[1].equalsIgnoreCase("on"))) { | ||
isAnalyse = false; | ||
isAnalyze = false; | ||
break; | ||
} | ||
} | ||
} | ||
if (isAnalyse) { | ||
if (isAnalyze) { | ||
String newSql = removeParenthesisAndTrim(sql.substring(index + 1)); | ||
return executeStatement(newSql, QueryAnalyzeMode.PROFILE); | ||
} else if (startAfterIndex) { | ||
|
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 this is correct. If we encounter a string that contains more than 2 words, we will assume that the options expression did not contain
ANALYZE
and that it for the rest was valid. From what I can see in the PostgreSQL documentation, there should be no option expression that contains more than 2 words.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.
If there are 3 strings inside parenthesis like "explain (foo bar foo, analyse true) select * from table", it will send "(foo bar foo, analyse true) select * from table" as the query which will eventually cause exception. Its just the error message will not be appropriate (it will be something like "(foo bar foo, analyse true) select * from table" is not a query).
Writing code for a solution which distinguishes the error message will be a bit tricky. Because, for the cases like "explain (select * from table)", it will be difficult to identify if the string "(select * from table)" is some option with 3 strings or a valid query string.
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.
That sounds reasonable to me.