fix: EXPLAIN CREATE TABLE to show IF NOT EXISTS clause#27138
Merged
feilong-liu merged 1 commit intoprestodb:masterfrom Feb 19, 2026
Merged
fix: EXPLAIN CREATE TABLE to show IF NOT EXISTS clause#27138feilong-liu merged 1 commit intoprestodb:masterfrom
feilong-liu merged 1 commit intoprestodb:masterfrom
Conversation
Contributor
Reviewer's GuideAdjusts EXPLAIN output for CREATE TABLE to include the IF NOT EXISTS clause when present, and expands DDL explain tests to cover various CREATE/DROP TABLE cases and other DDL statements. Sequence diagram for EXPLAIN CREATE TABLE IF NOT EXISTS handlingsequenceDiagram
actor User
participant PrestoClient
participant Coordinator
participant Analyzer
participant CreateTableTask
User->>PrestoClient: send SQL EXPLAIN CREATE TABLE IF NOT EXISTS table
PrestoClient->>Coordinator: submit query
Coordinator->>Analyzer: analyze EXPLAIN statement
Analyzer->>CreateTableTask: call explain(statement, parameters)
CreateTableTask->>CreateTableTask: check statement.isNotExists()
CreateTableTask-->>Analyzer: CREATE TABLE IF NOT EXISTS table
Analyzer-->>Coordinator: formatted EXPLAIN output
Coordinator-->>PrestoClient: EXPLAIN result
PrestoClient-->>User: render EXPLAIN output
Class diagram for CreateTableTask explain method updateclassDiagram
class CreateTableTask {
+String getName()
+String explain(CreateTable statement, List_Expression parameters)
}
class CreateTable {
+String getName()
+boolean isNotExists()
}
class Expression
class List_Expression {
+add(Expression element)
+get(int index) Expression
+size() int
}
CreateTableTask --> CreateTable : uses
CreateTableTask --> List_Expression : uses
List_Expression --> Expression : contains
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
CreateTableTask.explain, you can avoid duplicating the"CREATE TABLE"prefix by constructing the string once and conditionally appending"IF NOT EXISTS ", e.g.,"CREATE TABLE " + (statement.isNotExists() ? "IF NOT EXISTS " : "") + statement.getName();.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `CreateTableTask.explain`, you can avoid duplicating the `"CREATE TABLE"` prefix by constructing the string once and conditionally appending `"IF NOT EXISTS "`, e.g., `"CREATE TABLE " + (statement.isNotExists() ? "IF NOT EXISTS " : "") + statement.getName();`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
Opened #27148 to track the missing documentation for |
Contributor
Author
@steveburnett Thanks! Once the behavior for CREATE TABLE IF NOT EXISTS is decided, I can add that info. Please let me know if you have any thoughts on the behavior of this |
Summary:
The existing special handling for EXPLAIN CREATE TABLE deliberately simplifies the output to just show CREATE TABLE <name> rather than the full DDL with columns, constraints, and properties. This is reasonable since the full column definitions can be quite verbose and aren't as useful for understanding what the statement will do.
However, the current implementation omits the IF NOT EXISTS clause, which is semantically important - it changes whether the statement will fail or succeed if the table already exists. This is inconsistent with EXPLAIN DROP TABLE IF EXISTS, which does show the IF EXISTS clause (since DROP TABLE uses the default SqlFormatter which includes it).
This change updates the custom explain() method to include IF NOT EXISTS when present, making the behavior consistent with DROP TABLE while still keeping the simplified output format.
With this, I'm open to suggestions on what the most helpful output for EXPLAIN CREATE TABLE would be. Some options:
- Keep the original abbreviated behavior (just CREATE TABLE <name>) - current behavior before this fix
- Abbreviated with IF NOT EXISTS included (this PR)
- Output the full DDL using SqlFormatter
ex)
```
EXPLAIN CREATE TABLE IF NOT EXISTS myschema.users (
id bigint NOT NULL,
PRIMARY KEY (id)
) WITH (format = 'ORC')
```
will output:
```
CREATE TABLE IF NOT EXISTS myschema.users (
id bigint NOT NULL,
PRIMARY KEY (id)
)
WITH (
format = 'ORC'
)
```
Reviewed By: kewang1024
Differential Revision: D93266866
a3b2a18 to
3b2e34e
Compare
skyelves
approved these changes
Feb 19, 2026
feilong-liu
approved these changes
Feb 19, 2026
This was referenced Mar 31, 2026
15 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
The existing special handling for EXPLAIN CREATE TABLE deliberately simplifies the output to just show CREATE TABLE rather than the full DDL with columns, constraints, and properties. This is reasonable since the full column definitions can be quite verbose and aren't as useful for understanding what the statement will do.
However, the current implementation omits the IF NOT EXISTS clause, which is semantically important - it changes whether the statement will fail or succeed if the table already exists. This is inconsistent with EXPLAIN DROP TABLE IF EXISTS, which does show the IF EXISTS clause (since DROP TABLE uses the default SqlFormatter which includes it).
This change updates the custom explain() method to include IF NOT EXISTS when present, making the behavior consistent with DROP TABLE while still keeping the simplified output format.
With this, I'm open to suggestions on what the most helpful output for EXPLAIN CREATE TABLE would be. Some options:
ex)
will output:
Differential Revision: D93266866
Summary by Sourcery
Include IF NOT EXISTS in EXPLAIN output for CREATE TABLE statements and expand DDL EXPLAIN coverage tests.
Bug Fixes:
Tests: