@@ -975,6 +975,81 @@ pub struct TableFunctionArgs {
975975 pub settings : Option < Vec < Setting > > ,
976976}
977977
978+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
979+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
980+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
981+ pub enum TableIndexHintType {
982+ Use ,
983+ Ignore ,
984+ Force ,
985+ }
986+
987+ impl fmt:: Display for TableIndexHintType {
988+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
989+ f. write_str ( match self {
990+ TableIndexHintType :: Use => "USE" ,
991+ TableIndexHintType :: Ignore => "IGNORE" ,
992+ TableIndexHintType :: Force => "FORCE" ,
993+ } )
994+ }
995+ }
996+
997+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
998+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
999+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1000+ pub enum TableIndexType {
1001+ Index ,
1002+ Key ,
1003+ }
1004+
1005+ impl fmt:: Display for TableIndexType {
1006+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1007+ f. write_str ( match self {
1008+ TableIndexType :: Index => "INDEX" ,
1009+ TableIndexType :: Key => "KEY" ,
1010+ } )
1011+ }
1012+ }
1013+
1014+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1015+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1016+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1017+ pub enum TableIndexHintForClause {
1018+ Join ,
1019+ OrderBy ,
1020+ GroupBy ,
1021+ }
1022+
1023+ impl fmt:: Display for TableIndexHintForClause {
1024+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1025+ f. write_str ( match self {
1026+ TableIndexHintForClause :: Join => "JOIN" ,
1027+ TableIndexHintForClause :: OrderBy => "ORDER BY" ,
1028+ TableIndexHintForClause :: GroupBy => "GROUP BY" ,
1029+ } )
1030+ }
1031+ }
1032+
1033+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1034+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1035+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1036+ pub struct TableIndexHints {
1037+ pub hint_type : TableIndexHintType ,
1038+ pub index_type : TableIndexType ,
1039+ pub for_clause : Option < TableIndexHintForClause > ,
1040+ pub index_names : Vec < Ident > ,
1041+ }
1042+
1043+ impl fmt:: Display for TableIndexHints {
1044+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1045+ write ! ( f, "{} {} " , self . hint_type, self . index_type) ?;
1046+ if let Some ( for_clause) = & self . for_clause {
1047+ write ! ( f, "FOR {} " , for_clause) ?;
1048+ }
1049+ write ! ( f, "({})" , display_comma_separated( & self . index_names) )
1050+ }
1051+ }
1052+
9781053/// A table name or a parenthesized subquery with an optional alias
9791054#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9801055#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -1009,6 +1084,9 @@ pub enum TableFactor {
10091084 /// Optional table sample modifier
10101085 /// See: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#sample-clause>
10111086 sample : Option < TableSampleKind > ,
1087+ /// Optional index hints(mysql)
1088+ /// See: <https://dev.mysql.com/doc/refman/8.4/en/index-hints.html>
1089+ index_hints : Vec < TableIndexHints > ,
10121090 } ,
10131091 Derived {
10141092 lateral : bool ,
@@ -1590,6 +1668,7 @@ impl fmt::Display for TableFactor {
15901668 with_ordinality,
15911669 json_path,
15921670 sample,
1671+ index_hints,
15931672 } => {
15941673 write ! ( f, "{name}" ) ?;
15951674 if let Some ( json_path) = json_path {
@@ -1618,6 +1697,9 @@ impl fmt::Display for TableFactor {
16181697 if let Some ( alias) = alias {
16191698 write ! ( f, " AS {alias}" ) ?;
16201699 }
1700+ if !index_hints. is_empty ( ) {
1701+ write ! ( f, " {}" , display_separated( index_hints, " " ) ) ?;
1702+ }
16211703 if !with_hints. is_empty ( ) {
16221704 write ! ( f, " WITH ({})" , display_comma_separated( with_hints) ) ?;
16231705 }
0 commit comments