Skip to content

Commit 67c3be0

Browse files
romanbRoman Borschel
and
Roman Borschel
authored
Add support for MySQL's STRAIGHT_JOIN join operator. (#1802)
Co-authored-by: Roman Borschel <[email protected]>
1 parent cfd8951 commit 67c3be0

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

src/ast/query.rs

+7
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

+1
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,7 @@ impl Spanned for JoinOperator {
21282128
} => match_condition.span().union(&constraint.span()),
21292129
JoinOperator::Anti(join_constraint) => join_constraint.span(),
21302130
JoinOperator::Semi(join_constraint) => join_constraint.span(),
2131+
JoinOperator::StraightJoin(join_constraint) => join_constraint.span(),
21312132
}
21322133
}
21332134
}

src/keywords.rs

+1
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

+4
Original file line numberDiff line numberDiff line change
@@ -11826,6 +11826,10 @@ impl<'a> Parser<'a> {
1182611826
Keyword::OUTER => {
1182711827
return self.expected("LEFT, RIGHT, or FULL", self.peek_token());
1182811828
}
11829+
Keyword::STRAIGHT_JOIN => {
11830+
let _ = self.next_token(); // consume STRAIGHT_JOIN
11831+
JoinOperator::StraightJoin
11832+
}
1182911833
_ if natural => {
1183011834
return self.expected("a join type after NATURAL", self.peek_token());
1183111835
}

tests/sqlparser_mysql.rs

+7
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)