-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Include statement attributes in EXPLAIN PLAN
output
#14074
Include statement attributes in EXPLAIN PLAN
output
#14074
Conversation
… and assert on it.
sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java
Outdated
Show resolved
Hide resolved
// Use testQuery for EXPLAIN (not testIngestionQuery). | ||
testQuery( | ||
PlannerConfig.builder().useNativeQueryExplain(false).build(), | ||
PLANNER_CONFIG_LEGACY_QUERY_EXPLAIN, |
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.
Nice test!
sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java
Outdated
Show resolved
Hide resolved
Seems like the explain plan output would look something like this:
I'm wondering if the |
e1ab0d3
to
73fc9de
Compare
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.
Mainly reviewed the API design; I just skimmed the code. For the API, a few comments:
- For best backwards compat with existing clients, we should add the new info as a third column in the
EXPLAIN PLAN
result rather than adding it to the queries array. - We may want to add more statement-related attributes to
EXPLAIN PLAN
in the future (for example: partitioning forINSERT
/REPLACE
, or time chunks forREPLACE
). So I suggest wrapping all of these into a model object that we can add more fields to over time. - This is a change to a user-facing API, so it needs a documentation update. The relevant docs are
querying/sql-translation.md
andquerying/sql.md
. - There's also some doc debt on
querying/sql.md
, as it doesn't mention the newEXPLAIN PLAN
format, and has a warning box that seems only relevant to the legacy format. If you fix this in this PR, great, if not please raise a follow-up issue and tag it with Documentation.
4f3d036
to
5afaeed
Compare
EXPLAIN PLAN
enhancementsEXPLAIN PLAN
output
5afaeed
to
14ba102
Compare
7caa193
to
9894710
Compare
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.
LGTM
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.
Overall LGTM, left some minor comments.
sql/src/main/java/org/apache/druid/sql/calcite/planner/StatementAttributes.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
Outdated
Show resolved
Hide resolved
This PR adds the following to the ATTRIBUTES column in the explain plan output: - partitionedBy - clusteredBy - replaceTimeChunks This PR leverages the work done in #14074, which added a new column ATTRIBUTES to encapsulate all the statement-related attributes.
This PR adds attributes that contain metadata information about the query in the
EXPLAIN PLAN
output. The attributes currently contain two items:statementKind
: denotes the overall statement type -- possible valuesSELECT
,INSERT
,REPLACE
targetDataSource
: provides the target datasource name for DML statementsA new method
explainAttributes
, is added to theSqlStatementHandler
interface, and the Select, Insert, and Replace handlers implement the methods. The value is then obtained from the statement handler during query planning and set in the planner context.For backward compatibility, these attributes are included as a third column to the output—updated docs to reflect the output changes. Also, it is added to both the legacy and native query plan outputs.
The
EXPLAIN PLAN
output for aSELECT
query is in the README. Below is the output for anINSERT
query:This PR has: