@@ -1125,6 +1125,8 @@ pub enum TableConstraint {
11251125 index_type : Option < IndexType > ,
11261126 /// Referred column identifier list.
11271127 columns : Vec < IndexColumn > ,
1128+ /// Optional index options such as `USING`; see [`IndexOption`].
1129+ index_options : Vec < IndexOption > ,
11281130 } ,
11291131 /// MySQLs [fulltext][1] definition. Since the [`SPATIAL`][2] definition is exactly the same,
11301132 /// and MySQL displays both the same way, it is part of this definition as well.
@@ -1253,6 +1255,7 @@ impl fmt::Display for TableConstraint {
12531255 name,
12541256 index_type,
12551257 columns,
1258+ index_options,
12561259 } => {
12571260 write ! ( f, "{}" , if * display_as_key { "KEY" } else { "INDEX" } ) ?;
12581261 if let Some ( name) = name {
@@ -1262,7 +1265,9 @@ impl fmt::Display for TableConstraint {
12621265 write ! ( f, " USING {index_type}" ) ?;
12631266 }
12641267 write ! ( f, " ({})" , display_comma_separated( columns) ) ?;
1265-
1268+ if !index_options. is_empty ( ) {
1269+ write ! ( f, " {}" , display_comma_separated( index_options) ) ?;
1270+ }
12661271 Ok ( ( ) )
12671272 }
12681273 Self :: FulltextOrSpatial {
@@ -1377,17 +1382,20 @@ impl fmt::Display for IndexType {
13771382 }
13781383}
13791384
1380- /// MySQLs index option.
1381- ///
1382- /// This structure used here [`MySQL` CREATE TABLE][1], [`MySQL` CREATE INDEX][2].
1385+ /// MySQL index option, used in [`CREATE TABLE`], [`CREATE INDEX`], and [`ALTER TABLE`].
13831386///
1384- /// [1]: https://dev.mysql.com/doc/refman/8.3/en/create-table.html
1385- /// [2]: https://dev.mysql.com/doc/refman/8.3/en/create-index.html
1387+ /// [`CREATE TABLE`]: https://dev.mysql.com/doc/refman/8.4/en/create-table.html
1388+ /// [`CREATE INDEX`]: https://dev.mysql.com/doc/refman/8.4/en/create-index.html
1389+ /// [`ALTER TABLE`]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
13861390#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
13871391#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
13881392#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
13891393pub enum IndexOption {
1394+ /// `USING { BTREE | HASH }`: Index type to use for the index.
1395+ ///
1396+ /// Note that we permissively parse non-MySQL index types, like `GIN`.
13901397 Using ( IndexType ) ,
1398+ /// `COMMENT 'string'`: Specifies a comment for the index.
13911399 Comment ( String ) ,
13921400}
13931401
0 commit comments