improve sql parser performance

This commit is contained in:
wenshao
2013-01-14 20:45:13 +08:00
parent cb45e49a0c
commit 7aa2038498
6 changed files with 71 additions and 21 deletions
@@ -209,13 +209,24 @@ public class MySqlLexer extends Lexer {
{
boolean hasSpecial = false;
int startIndex = pos + 1;
int endIndex = text.indexOf('\'', startIndex);
int endIndex = -1; //text.indexOf('\'', startIndex);
for (int i = startIndex; i < text.length(); ++i) {
final char ch = text.charAt(i);
if (ch == '\\') {
hasSpecial = true;
}
if (ch == '\'') {
endIndex = i;
break;
}
}
if (endIndex == -1) {
throw new ParserException("unclosed str");
}
String stringVal = subString(startIndex, endIndex - startIndex);
hasSpecial = stringVal.indexOf('\\') != -1;
// hasSpecial = stringVal.indexOf('\\') != -1;
if (!hasSpecial) {
this.stringVal = stringVal;
@@ -79,7 +79,7 @@ public class Lexer {
return text.charAt(index);
}
public String addSymbol() {
public final String addSymbol() {
return subString(mark, bufPos);
}
@@ -137,9 +137,30 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
}
private String handleName(String ident) {
ident = ident.replaceAll("\"", "");
ident = ident.replaceAll("`", "");
ident = ident.replaceAll(" ", "");
boolean flag0 = false;
boolean flag1 = false;
boolean flag2 = false;
for (int i = 0; i < ident.length(); ++i) {
final char ch = ident.charAt(i);
if (ch == '\"') {
flag0 = true;
} else if (ch == '`') {
flag1 = true;
} else if (ch == ' ') {
flag2 = true;
}
}
if (flag0) {
ident = ident.replaceAll("\"", "");
}
if (flag1) {
ident = ident.replaceAll("`", "");
}
if (flag2) {
ident = ident.replaceAll(" ", "");
}
ident = aliasWrap(ident);