Skip to content

Commit 5676b91

Browse files
authored
Revert "Add support for mysql table hints (apache#1675)"
This reverts commit e49bc18.
1 parent ddaf134 commit 5676b91

File tree

12 files changed

+5
-266
lines changed

12 files changed

+5
-266
lines changed

src/ast/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ pub use self::query::{
6969
OrderBy, OrderByExpr, PivotValueSource, ProjectionSelect, Query, RenameSelectItem,
7070
RepetitionQuantifier, ReplaceSelectElement, ReplaceSelectItem, RowsPerMatch, Select,
7171
SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, Setting, SymbolDefinition, Table,
72-
TableAlias, TableAliasColumnDef, TableFactor, TableFunctionArgs, TableIndexHintForClause,
73-
TableIndexHintType, TableIndexHints, TableIndexType, TableSample, TableSampleBucket,
74-
TableSampleKind, TableSampleMethod, TableSampleModifier, TableSampleQuantity, TableSampleSeed,
75-
TableSampleSeedModifier, TableSampleUnit, TableVersion, TableWithJoins, Top, TopQuantity,
76-
UpdateTableFromKind, ValueTableMode, Values, WildcardAdditionalOptions, With, WithFill,
72+
TableAlias, TableAliasColumnDef, TableFactor, TableFunctionArgs, TableSample,
73+
TableSampleBucket, TableSampleKind, TableSampleMethod, TableSampleModifier,
74+
TableSampleQuantity, TableSampleSeed, TableSampleSeedModifier, TableSampleUnit, TableVersion,
75+
TableWithJoins, Top, TopQuantity, UpdateTableFromKind, ValueTableMode, Values,
76+
WildcardAdditionalOptions, With, WithFill,
7777
};
7878

7979
pub use self::trigger::{

src/ast/query.rs

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -975,81 +975,6 @@ 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-
1053978
/// A table name or a parenthesized subquery with an optional alias
1054979
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1055980
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -1084,9 +1009,6 @@ pub enum TableFactor {
10841009
/// Optional table sample modifier
10851010
/// See: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#sample-clause>
10861011
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>,
10901012
},
10911013
Derived {
10921014
lateral: bool,
@@ -1668,7 +1590,6 @@ impl fmt::Display for TableFactor {
16681590
with_ordinality,
16691591
json_path,
16701592
sample,
1671-
index_hints,
16721593
} => {
16731594
write!(f, "{name}")?;
16741595
if let Some(json_path) = json_path {
@@ -1697,9 +1618,6 @@ impl fmt::Display for TableFactor {
16971618
if let Some(alias) = alias {
16981619
write!(f, " AS {alias}")?;
16991620
}
1700-
if !index_hints.is_empty() {
1701-
write!(f, " {}", display_separated(index_hints, " "))?;
1702-
}
17031621
if !with_hints.is_empty() {
17041622
write!(f, " WITH ({})", display_comma_separated(with_hints))?;
17051623
}

src/ast/spans.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,6 @@ impl Spanned for TableFactor {
17661766
partitions: _,
17671767
json_path: _,
17681768
sample: _,
1769-
index_hints: _,
17701769
} => union_spans(
17711770
name.0
17721771
.iter()

src/dialect/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,6 @@ pub trait Dialect: Debug + Any {
854854
fn supports_string_escape_constant(&self) -> bool {
855855
false
856856
}
857-
/// Returns true if the dialect supports the table hints in the `FROM` clause.
858-
fn supports_table_hints(&self) -> bool {
859-
false
860-
}
861857
}
862858

863859
/// This represents the operators for which precedence must be defined

src/dialect/mysql.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ use crate::{
2525
parser::{Parser, ParserError},
2626
};
2727

28-
use super::keywords;
29-
30-
const RESERVED_FOR_TABLE_ALIAS_MYSQL: &[Keyword] = &[Keyword::USE, Keyword::IGNORE, Keyword::FORCE];
31-
3228
/// A [`Dialect`] for [MySQL](https://www.mysql.com/)
3329
#[derive(Debug)]
3430
pub struct MySqlDialect {}
@@ -115,16 +111,6 @@ impl Dialect for MySqlDialect {
115111
fn supports_user_host_grantee(&self) -> bool {
116112
true
117113
}
118-
119-
fn is_table_factor_alias(&self, explicit: bool, kw: &Keyword, _parser: &mut Parser) -> bool {
120-
explicit
121-
|| (!keywords::RESERVED_FOR_TABLE_ALIAS.contains(kw)
122-
&& !RESERVED_FOR_TABLE_ALIAS_MYSQL.contains(kw))
123-
}
124-
125-
fn supports_table_hints(&self) -> bool {
126-
true
127-
}
128114
}
129115

130116
/// `LOCK TABLES`

src/parser/mod.rs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8910,64 +8910,6 @@ impl<'a> Parser<'a> {
89108910
}
89118911
}
89128912

8913-
fn parse_table_index_hints(&mut self) -> Result<Vec<TableIndexHints>, ParserError> {
8914-
let mut hints = vec![];
8915-
while let Some(hint_type) =
8916-
self.parse_one_of_keywords(&[Keyword::USE, Keyword::IGNORE, Keyword::FORCE])
8917-
{
8918-
let hint_type = match hint_type {
8919-
Keyword::USE => TableIndexHintType::Use,
8920-
Keyword::IGNORE => TableIndexHintType::Ignore,
8921-
Keyword::FORCE => TableIndexHintType::Force,
8922-
_ => {
8923-
return self.expected(
8924-
"expected to match USE/IGNORE/FORCE keyword",
8925-
self.peek_token(),
8926-
)
8927-
}
8928-
};
8929-
let index_type = match self.parse_one_of_keywords(&[Keyword::INDEX, Keyword::KEY]) {
8930-
Some(Keyword::INDEX) => TableIndexType::Index,
8931-
Some(Keyword::KEY) => TableIndexType::Key,
8932-
_ => {
8933-
return self.expected("expected to match INDEX/KEY keyword", self.peek_token())
8934-
}
8935-
};
8936-
let for_clause = if self.parse_keyword(Keyword::FOR) {
8937-
let clause = if self.parse_keyword(Keyword::JOIN) {
8938-
TableIndexHintForClause::Join
8939-
} else if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) {
8940-
TableIndexHintForClause::OrderBy
8941-
} else if self.parse_keywords(&[Keyword::GROUP, Keyword::BY]) {
8942-
TableIndexHintForClause::GroupBy
8943-
} else {
8944-
return self.expected(
8945-
"expected to match FOR/ORDER BY/GROUP BY table hint in for clause",
8946-
self.peek_token(),
8947-
);
8948-
};
8949-
Some(clause)
8950-
} else {
8951-
None
8952-
};
8953-
8954-
self.expect_token(&Token::LParen)?;
8955-
let index_names = if self.peek_token().token != Token::RParen {
8956-
self.parse_comma_separated(Parser::parse_identifier)?
8957-
} else {
8958-
vec![]
8959-
};
8960-
self.expect_token(&Token::RParen)?;
8961-
hints.push(TableIndexHints {
8962-
hint_type,
8963-
index_type,
8964-
for_clause,
8965-
index_names,
8966-
});
8967-
}
8968-
Ok(hints)
8969-
}
8970-
89718913
/// Wrapper for parse_optional_alias_inner, left for backwards-compatibility
89728914
/// but new flows should use the context-specific methods such as `maybe_parse_select_item_alias`
89738915
/// and `maybe_parse_table_alias`.
@@ -11315,14 +11257,6 @@ impl<'a> Parser<'a> {
1131511257

1131611258
let alias = self.maybe_parse_table_alias()?;
1131711259

11318-
// MYSQL-specific table hints:
11319-
let index_hints = if self.dialect.supports_table_hints() {
11320-
self.maybe_parse(|p| p.parse_table_index_hints())?
11321-
.unwrap_or(vec![])
11322-
} else {
11323-
vec![]
11324-
};
11325-
1132611260
// MSSQL-specific table hints:
1132711261
let mut with_hints = vec![];
1132811262
if self.parse_keyword(Keyword::WITH) {
@@ -11351,7 +11285,6 @@ impl<'a> Parser<'a> {
1135111285
with_ordinality,
1135211286
json_path,
1135311287
sample,
11354-
index_hints,
1135511288
};
1135611289

1135711290
while let Some(kw) = self.parse_one_of_keywords(&[Keyword::PIVOT, Keyword::UNPIVOT]) {

src/test_utils.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ pub fn table(name: impl Into<String>) -> TableFactor {
362362
with_ordinality: false,
363363
json_path: None,
364364
sample: None,
365-
index_hints: vec![],
366365
}
367366
}
368367

@@ -377,7 +376,6 @@ pub fn table_from_name(name: ObjectName) -> TableFactor {
377376
with_ordinality: false,
378377
json_path: None,
379378
sample: None,
380-
index_hints: vec![],
381379
}
382380
}
383381

@@ -395,7 +393,6 @@ pub fn table_with_alias(name: impl Into<String>, alias: impl Into<String>) -> Ta
395393
with_ordinality: false,
396394
json_path: None,
397395
sample: None,
398-
index_hints: vec![],
399396
}
400397
}
401398

tests/sqlparser_bigquery.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,6 @@ fn parse_table_time_travel() {
15651565
with_ordinality: false,
15661566
json_path: None,
15671567
sample: None,
1568-
index_hints: vec![],
15691568
},
15701569
joins: vec![]
15711570
},]
@@ -1666,7 +1665,6 @@ fn parse_merge() {
16661665
with_ordinality: false,
16671666
json_path: None,
16681667
sample: None,
1669-
index_hints: vec![],
16701668
},
16711669
table
16721670
);
@@ -1684,7 +1682,6 @@ fn parse_merge() {
16841682
with_ordinality: false,
16851683
json_path: None,
16861684
sample: None,
1687-
index_hints: vec![],
16881685
},
16891686
source
16901687
);

0 commit comments

Comments
 (0)