@@ -975,6 +975,81 @@ pub struct TableFunctionArgs {
975
975
pub settings : Option < Vec < Setting > > ,
976
976
}
977
977
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
+
978
1053
/// A table name or a parenthesized subquery with an optional alias
979
1054
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
980
1055
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -1009,6 +1084,9 @@ pub enum TableFactor {
1009
1084
/// Optional table sample modifier
1010
1085
/// See: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#sample-clause>
1011
1086
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 > ,
1012
1090
} ,
1013
1091
Derived {
1014
1092
lateral : bool ,
@@ -1590,6 +1668,7 @@ impl fmt::Display for TableFactor {
1590
1668
with_ordinality,
1591
1669
json_path,
1592
1670
sample,
1671
+ index_hints,
1593
1672
} => {
1594
1673
write ! ( f, "{name}" ) ?;
1595
1674
if let Some ( json_path) = json_path {
@@ -1618,6 +1697,9 @@ impl fmt::Display for TableFactor {
1618
1697
if let Some ( alias) = alias {
1619
1698
write ! ( f, " AS {alias}" ) ?;
1620
1699
}
1700
+ if !index_hints. is_empty ( ) {
1701
+ write ! ( f, " {}" , display_separated( index_hints, " " ) ) ?;
1702
+ }
1621
1703
if !with_hints. is_empty ( ) {
1622
1704
write ! ( f, " WITH ({})" , display_comma_separated( with_hints) ) ?;
1623
1705
}
0 commit comments