Skip to content

Commit 5e3345d

Browse files
romanbRoman Borschel
authored andcommitted
Add support for MySQL's STRAIGHT_JOIN join operator. (apache#1802)
Co-authored-by: Roman Borschel <[email protected]>
1 parent d6f9cb1 commit 5e3345d

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

src/ast/query.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,9 @@ impl fmt::Display for Join {
21572157
self.relation,
21582158
suffix(constraint)
21592159
),
2160+
JoinOperator::StraightJoin(constraint) => {
2161+
write!(f, " STRAIGHT_JOIN {}{}", self.relation, suffix(constraint))
2162+
}
21602163
}
21612164
}
21622165
}
@@ -2197,6 +2200,10 @@ pub enum JoinOperator {
21972200
match_condition: Expr,
21982201
constraint: JoinConstraint,
21992202
},
2203+
/// STRAIGHT_JOIN (non-standard)
2204+
///
2205+
/// See <https://dev.mysql.com/doc/refman/8.4/en/join.html>.
2206+
StraightJoin(JoinConstraint),
22002207
}
22012208

22022209
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,7 @@ impl Spanned for JoinOperator {
21332133
} => match_condition.span().union(&constraint.span()),
21342134
JoinOperator::Anti(join_constraint) => join_constraint.span(),
21352135
JoinOperator::Semi(join_constraint) => join_constraint.span(),
2136+
JoinOperator::StraightJoin(join_constraint) => join_constraint.span(),
21362137
}
21372138
}
21382139
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ define_keywords!(
840840
STORAGE_INTEGRATION,
841841
STORAGE_SERIALIZATION_POLICY,
842842
STORED,
843+
STRAIGHT_JOIN,
843844
STRICT,
844845
STRING,
845846
STRUCT,

src/parser/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11836,6 +11836,10 @@ impl<'a> Parser<'a> {
1183611836
Keyword::OUTER => {
1183711837
return self.expected("LEFT, RIGHT, or FULL", self.peek_token());
1183811838
}
11839+
Keyword::STRAIGHT_JOIN => {
11840+
let _ = self.next_token(); // consume STRAIGHT_JOIN
11841+
JoinOperator::StraightJoin
11842+
}
1183911843
_ if natural => {
1184011844
return self.expected("a join type after NATURAL", self.peek_token());
1184111845
}

tests/sqlparser_mysql.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,3 +3587,10 @@ fn test_variable_assignment_using_colon_equal() {
35873587
_ => panic!("Unexpected statement {stmt}"),
35883588
}
35893589
}
3590+
3591+
#[test]
3592+
fn parse_straight_join() {
3593+
mysql().verified_stmt(
3594+
"SELECT a.*, b.* FROM table_a AS a STRAIGHT_JOIN table_b AS b ON a.b_id = b.id",
3595+
);
3596+
}

0 commit comments

Comments
 (0)