-
Notifications
You must be signed in to change notification settings - Fork 616
feat: support explain options #1426
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
10 commits
Select commit
Hold shift + click to select a range
d714961
feat: support explain options
kysshsy 67e903b
feat: use nameed struct which is more representative and add Doc
kysshsy cde72ea
fix: handle keyword JSON and XML but not non-reserved Postgres, and a…
kysshsy 1c34d7b
test: add explain with option list test
kysshsy 900bc28
feat: parse arg as expr
kysshsy 381f129
test: add dialect flag
kysshsy 5c75a9e
feat: remove UtilityOptionList
kysshsy 406ce84
update base on comment
kysshsy b5bb4f2
fix BigDecimal feature in test
kysshsy f537053
fix doc links
kysshsy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3032,6 +3032,8 @@ pub enum Statement { | |
statement: Box<Statement>, | ||
/// Optional output format of explain | ||
format: Option<AnalyzeFormat>, | ||
/// Postgres style utility options, `(analyze, verbose true)` | ||
options: Option<Vec<UtilityOption>>, | ||
}, | ||
/// ```sql | ||
/// SAVEPOINT | ||
|
@@ -3219,6 +3221,7 @@ impl fmt::Display for Statement { | |
analyze, | ||
statement, | ||
format, | ||
options, | ||
} => { | ||
write!(f, "{describe_alias} ")?; | ||
|
||
|
@@ -3234,6 +3237,10 @@ impl fmt::Display for Statement { | |
write!(f, "FORMAT {format} ")?; | ||
} | ||
|
||
if let Some(options) = options { | ||
write!(f, "({}) ", display_comma_separated(options))?; | ||
} | ||
|
||
write!(f, "{statement}") | ||
} | ||
Statement::Query(s) => write!(f, "{s}"), | ||
|
@@ -7125,6 +7132,47 @@ where | |
} | ||
} | ||
|
||
/// Represents a single PostgreSQL utility option. | ||
/// | ||
/// A utility option is a key-value pair where the key is an identifier (IDENT) and the value | ||
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. ❤️ |
||
/// can be one of the following: | ||
/// - A number with an optional sign (`+` or `-`). Example: `+10`, `-10.2`, `3` | ||
/// - A non-keyword string. Example: `option1`, `'option2'`, `"option3"` | ||
/// - keyword: `TRUE`, `FALSE`, `ON` (`off` is also accept). | ||
/// - Empty. Example: `ANALYZE` (identifier only) | ||
/// | ||
/// Utility options are used in various PostgreSQL DDL statements, including statements such as | ||
/// `CLUSTER`, `EXPLAIN`, `VACUUM`, and `REINDEX`. These statements format options as `( option [, ...] )`. | ||
/// | ||
/// [CLUSTER](https://www.postgresql.org/docs/current/sql-cluster.html) | ||
/// [EXPLAIN](https://www.postgresql.org/docs/current/sql-explain.html) | ||
/// [VACUUM](https://www.postgresql.org/docs/current/sql-vacuum.html) | ||
/// [REINDEX](https://www.postgresql.org/docs/current/sql-reindex.html) | ||
/// | ||
/// For example, the `EXPLAIN` AND `VACUUM` statements with options might look like this: | ||
/// ```sql | ||
/// EXPLAIN (ANALYZE, VERBOSE TRUE, FORMAT TEXT) SELECT * FROM my_table; | ||
/// | ||
/// VACCUM (VERBOSE, ANALYZE ON, PARALLEL 10) my_table; | ||
/// ``` | ||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
pub struct UtilityOption { | ||
kysshsy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub name: Ident, | ||
pub arg: Option<Expr>, | ||
} | ||
|
||
impl Display for UtilityOption { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
if let Some(ref arg) = self.arg { | ||
write!(f, "{} {}", self.name, arg) | ||
} else { | ||
write!(f, "{}", self.name) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
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
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.