Merge pull request #2136 from ditdb/master

parse the index hints clause containning multiple similar parts in mysql
This commit is contained in:
温绍
2017-11-28 22:11:51 +08:00
committed by GitHub
3 changed files with 82 additions and 43 deletions
@@ -277,11 +277,18 @@ public class MySqlSelectIntoParser extends SQLSelectParser {
return tableSource;
}
if (lexer.token() == Token.USE) {
parseIndexHintList(tableSource);
return super.parseTableSourceRest(tableSource);
}
private void parseIndexHintList(SQLTableSource tableSource) {
if (lexer.token() == Token.USE) {
lexer.nextToken();
MySqlUseIndexHint hint = new MySqlUseIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
parseIndexHintList(tableSource);
}
if (lexer.identifierEquals("IGNORE")) {
@@ -289,6 +296,7 @@ public class MySqlSelectIntoParser extends SQLSelectParser {
MySqlIgnoreIndexHint hint = new MySqlIgnoreIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
parseIndexHintList(tableSource);
}
if (lexer.identifierEquals("FORCE")) {
@@ -296,9 +304,8 @@ public class MySqlSelectIntoParser extends SQLSelectParser {
MySqlForceIndexHint hint = new MySqlForceIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
parseIndexHintList(tableSource);
}
return super.parseTableSourceRest(tableSource);
}
private void parseIndexHint(MySqlIndexHintImpl hint) {
@@ -424,26 +424,7 @@ public class MySqlSelectParser extends SQLSelectParser {
}
protected SQLTableSource primaryTableSourceRest(SQLTableSource tableSource) {
if (lexer.token() == Token.USE) {
lexer.nextToken();
MySqlUseIndexHint hint = new MySqlUseIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
}
if (lexer.identifierEquals("IGNORE")) {
lexer.nextToken();
MySqlIgnoreIndexHint hint = new MySqlIgnoreIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
}
if (lexer.identifierEquals("FORCE")) {
lexer.nextToken();
MySqlForceIndexHint hint = new MySqlForceIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
}
parseIndexHintList(tableSource);
if (lexer.token() == Token.PARTITION) {
lexer.nextToken();
@@ -460,26 +441,7 @@ public class MySqlSelectParser extends SQLSelectParser {
return tableSource;
}
if (lexer.token() == Token.USE) {
lexer.nextToken();
MySqlUseIndexHint hint = new MySqlUseIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
}
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
lexer.nextToken();
MySqlIgnoreIndexHint hint = new MySqlIgnoreIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
}
if (lexer.identifierEquals(FnvHash.Constants.FORCE)) {
lexer.nextToken();
MySqlForceIndexHint hint = new MySqlForceIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
}
parseIndexHintList(tableSource);
if (lexer.token() == Token.PARTITION) {
lexer.nextToken();
@@ -491,6 +453,32 @@ public class MySqlSelectParser extends SQLSelectParser {
return super.parseTableSourceRest(tableSource);
}
private void parseIndexHintList(SQLTableSource tableSource) {
if (lexer.token() == Token.USE) {
lexer.nextToken();
MySqlUseIndexHint hint = new MySqlUseIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
parseIndexHintList(tableSource);
}
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
lexer.nextToken();
MySqlIgnoreIndexHint hint = new MySqlIgnoreIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
parseIndexHintList(tableSource);
}
if (lexer.identifierEquals(FnvHash.Constants.FORCE)) {
lexer.nextToken();
MySqlForceIndexHint hint = new MySqlForceIndexHint();
parseIndexHint(hint);
tableSource.getHints().add(hint);
parseIndexHintList(tableSource);
}
}
private void parseIndexHint(MySqlIndexHintImpl hint) {
if (lexer.token() == Token.INDEX) {
lexer.nextToken();