@@ -3326,19 +3326,24 @@ impl Display for ExceptionWhen {
33263326 }
33273327}
33283328
3329- /// ANALYZE TABLE statement (Hive-specific)
3329+ /// ANALYZE statement
3330+ ///
3331+ /// Supported syntax varies by dialect:
3332+ /// - Hive: `ANALYZE TABLE t [PARTITION (...)] COMPUTE STATISTICS [NOSCAN] [FOR COLUMNS [col1, ...]] [CACHE METADATA]`
3333+ /// - PostgreSQL: `ANALYZE [VERBOSE] [t [(col1, ...)]]` See <https://www.postgresql.org/docs/current/sql-analyze.html>
3334+ /// - General: `ANALYZE [TABLE] t`
33303335#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
33313336#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
33323337#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
33333338pub struct Analyze {
33343339 #[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
3335- /// Name of the table to analyze.
3336- pub table_name : ObjectName ,
3340+ /// Name of the table to analyze. `None` for bare `ANALYZE`.
3341+ pub table_name : Option < ObjectName > ,
33373342 /// Optional partition expressions to restrict the analysis.
33383343 pub partitions : Option < Vec < Expr > > ,
3339- /// `true` when analyzing specific columns.
3344+ /// `true` when analyzing specific columns (Hive `FOR COLUMNS` syntax) .
33403345 pub for_columns : bool ,
3341- /// Columns to analyze when `for_columns` is `true` .
3346+ /// Columns to analyze.
33423347 pub columns : Vec < Ident > ,
33433348 /// Whether to cache metadata before analyzing.
33443349 pub cache_metadata : bool ,
@@ -3352,22 +3357,21 @@ pub struct Analyze {
33523357
33533358impl fmt:: Display for Analyze {
33543359 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3355- write ! (
3356- f,
3357- "ANALYZE{}{table_name}" ,
3360+ write ! ( f, "ANALYZE" ) ?;
3361+ if let Some ( ref table_name) = self . table_name {
33583362 if self . has_table_keyword {
3359- " TABLE "
3360- } else {
3361- " "
3362- } ,
3363- table_name = self . table_name
3364- ) ?;
3363+ write ! ( f, " TABLE" ) ?;
3364+ }
3365+ write ! ( f, " {table_name}" ) ?;
3366+ }
3367+ if !self . for_columns && !self . columns . is_empty ( ) {
3368+ write ! ( f, " ({})" , display_comma_separated( & self . columns) ) ?;
3369+ }
33653370 if let Some ( ref parts) = self . partitions {
33663371 if !parts. is_empty ( ) {
33673372 write ! ( f, " PARTITION ({})" , display_comma_separated( parts) ) ?;
33683373 }
33693374 }
3370-
33713375 if self . compute_statistics {
33723376 write ! ( f, " COMPUTE STATISTICS" ) ?;
33733377 }
0 commit comments