Add support for MySQL's STRAIGHT_JOIN join operator. (#1802)

Co-authored-by: Roman Borschel <roman@cluvio.com>
This commit is contained in:
Roman Borschel 2025-04-10 12:26:13 +02:00 committed by GitHub
parent cfd8951452
commit 67c3be075e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 0 deletions

View file

@ -2157,6 +2157,9 @@ impl fmt::Display for Join {
self.relation,
suffix(constraint)
),
JoinOperator::StraightJoin(constraint) => {
write!(f, " STRAIGHT_JOIN {}{}", self.relation, suffix(constraint))
}
}
}
}
@ -2197,6 +2200,10 @@ pub enum JoinOperator {
match_condition: Expr,
constraint: JoinConstraint,
},
/// STRAIGHT_JOIN (non-standard)
///
/// See <https://dev.mysql.com/doc/refman/8.4/en/join.html>.
StraightJoin(JoinConstraint),
}
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]

View file

@ -2128,6 +2128,7 @@ impl Spanned for JoinOperator {
} => match_condition.span().union(&constraint.span()),
JoinOperator::Anti(join_constraint) => join_constraint.span(),
JoinOperator::Semi(join_constraint) => join_constraint.span(),
JoinOperator::StraightJoin(join_constraint) => join_constraint.span(),
}
}
}

View file

@ -840,6 +840,7 @@ define_keywords!(
STORAGE_INTEGRATION,
STORAGE_SERIALIZATION_POLICY,
STORED,
STRAIGHT_JOIN,
STRICT,
STRING,
STRUCT,

View file

@ -11826,6 +11826,10 @@ impl<'a> Parser<'a> {
Keyword::OUTER => {
return self.expected("LEFT, RIGHT, or FULL", self.peek_token());
}
Keyword::STRAIGHT_JOIN => {
let _ = self.next_token(); // consume STRAIGHT_JOIN
JoinOperator::StraightJoin
}
_ if natural => {
return self.expected("a join type after NATURAL", self.peek_token());
}

View file

@ -3587,3 +3587,10 @@ fn test_variable_assignment_using_colon_equal() {
_ => panic!("Unexpected statement {stmt}"),
}
}
#[test]
fn parse_straight_join() {
mysql().verified_stmt(
"SELECT a.*, b.* FROM table_a AS a STRAIGHT_JOIN table_b AS b ON a.b_id = b.id",
);
}