Skip to content

Commit 3cdea6b

Browse files
tomershaywumpz
authored andcommitted
Adding support for STRAIGHT_JOIN in the select clause (#861)
* Adding support for straight_join in the select clause * Renaming the field name to reflect that this is a MySQL hint
1 parent a0077a1 commit 3cdea6b

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class PlainSelect extends ASTNodeAccessImpl implements SelectBody {
3535
private Fetch fetch;
3636
private OptimizeFor optimizeFor;
3737
private Skip skip;
38+
private boolean mySqlHintStraightJoin;
3839
private First first;
3940
private Top top;
4041
private OracleHierarchicalExpression oracleHierarchical = null;
@@ -170,6 +171,14 @@ public void setSkip(Skip skip) {
170171
this.skip = skip;
171172
}
172173

174+
public boolean getMySqlHintStraightJoin() {
175+
return this.mySqlHintStraightJoin;
176+
}
177+
178+
public void setMySqlHintStraightJoin(boolean mySqlHintStraightJoin) {
179+
this.mySqlHintStraightJoin = mySqlHintStraightJoin;
180+
}
181+
173182
public First getFirst() {
174183
return first;
175184
}
@@ -297,6 +306,10 @@ public String toString() {
297306
}
298307
sql.append("SELECT ");
299308

309+
if (this.mySqlHintStraightJoin) {
310+
sql.append("STRAIGHT_JOIN ");
311+
}
312+
300313
if (oracleHint != null) {
301314
sql.append(oracleHint).append(" ");
302315
}

src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public void visit(PlainSelect plainSelect) {
3636
}
3737
buffer.append("SELECT ");
3838

39+
if (plainSelect.getMySqlHintStraightJoin()) {
40+
buffer.append("STRAIGHT_JOIN ");
41+
}
42+
3943
OracleHint hint = plainSelect.getOracleHint();
4044
if (hint != null) {
4145
buffer.append(hint).append(" ");

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ PlainSelect PlainSelect() #PlainSelect:
12811281
{
12821282
<K_SELECT>
12831283

1284+
[ <K_STRAIGHT> { plainSelect.setMySqlHintStraightJoin(true); } ]
1285+
12841286
{ plainSelect.setOracleHint(getOracleHint()); }
12851287

12861288
[skip = Skip() { plainSelect.setSkip(skip); } ]

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,11 +1637,17 @@ public void testCastTypeProblem2() throws JSQLParserException {
16371637
}
16381638

16391639
@Test
1640-
public void testStraightJoin() throws JSQLParserException {
1640+
public void testMySQLHintStraightJoin() throws JSQLParserException {
16411641
String stmt = "SELECT col FROM tbl STRAIGHT_JOIN tbl2 ON tbl.id = tbl2.id";
16421642
assertSqlCanBeParsedAndDeparsed(stmt);
16431643
}
16441644

1645+
@Test
1646+
public void testStraightJoinInSelect() throws JSQLParserException {
1647+
String stmt = "SELECT STRAIGHT_JOIN col, col2 FROM tbl INNER JOIN tbl2 ON tbl.id = tbl2.id";
1648+
assertSqlCanBeParsedAndDeparsed(stmt);
1649+
}
1650+
16451651
@Test
16461652
public void testCastTypeProblem3() throws JSQLParserException {
16471653
String stmt = "SELECT col1::varchar (256) FROM tabelle1";

0 commit comments

Comments
 (0)