提交 1db3a8a0 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Inline parseSelectUnionExtension() into parseSelectUnion() and optimize it

上级 f3e8e86d
...@@ -2308,39 +2308,25 @@ public class Parser { ...@@ -2308,39 +2308,25 @@ public class Parser {
private Query parseSelectUnion() { private Query parseSelectUnion() {
int start = lastParseIndex; int start = lastParseIndex;
Query command = parseSelectSub(); Query command = parseSelectSub();
return parseSelectUnionExtension(command, start, false); for (;;) {
} SelectUnion.UnionType type;
private Query parseSelectUnionExtension(Query command, int start,
boolean unionOnly) {
while (true) {
if (readIf(UNION)) { if (readIf(UNION)) {
SelectUnion union = new SelectUnion(session, command);
if (readIf(ALL)) { if (readIf(ALL)) {
union.setUnionType(SelectUnion.UnionType.UNION_ALL); type = SelectUnion.UnionType.UNION_ALL;
} else { } else {
readIf(DISTINCT); readIf(DISTINCT);
union.setUnionType(SelectUnion.UnionType.UNION); type = SelectUnion.UnionType.UNION;
} }
union.setRight(parseSelectSub()); } else if (readIf(EXCEPT) || readIf(MINUS)) {
command = union; type = SelectUnion.UnionType.EXCEPT;
} else if (readIf(MINUS) || readIf(EXCEPT)) {
SelectUnion union = new SelectUnion(session, command);
union.setUnionType(SelectUnion.UnionType.EXCEPT);
union.setRight(parseSelectSub());
command = union;
} else if (readIf(INTERSECT)) { } else if (readIf(INTERSECT)) {
SelectUnion union = new SelectUnion(session, command); type = SelectUnion.UnionType.INTERSECT;
union.setUnionType(SelectUnion.UnionType.INTERSECT);
union.setRight(parseSelectSub());
command = union;
} else { } else {
break; break;
} }
command = new SelectUnion(session, type, command, parseSelectSub());
} }
if (!unionOnly) { parseEndOfQuery(command);
parseEndOfQuery(command);
}
setSQL(command, null, start); setSQL(command, null, start);
return command; return command;
} }
......
...@@ -61,7 +61,7 @@ public class SelectUnion extends Query { ...@@ -61,7 +61,7 @@ public class SelectUnion extends Query {
INTERSECT INTERSECT
} }
private UnionType unionType; private final UnionType unionType;
/** /**
* The left hand side of the union (the first subquery). * The left hand side of the union (the first subquery).
...@@ -71,7 +71,7 @@ public class SelectUnion extends Query { ...@@ -71,7 +71,7 @@ public class SelectUnion extends Query {
/** /**
* The right hand side of the union (the second subquery). * The right hand side of the union (the second subquery).
*/ */
Query right; final Query right;
private ArrayList<Expression> expressions; private ArrayList<Expression> expressions;
private Expression[] expressionArray; private Expression[] expressionArray;
...@@ -80,9 +80,11 @@ public class SelectUnion extends Query { ...@@ -80,9 +80,11 @@ public class SelectUnion extends Query {
private boolean isPrepared, checkInit; private boolean isPrepared, checkInit;
private boolean isForUpdate; private boolean isForUpdate;
public SelectUnion(Session session, Query query) { public SelectUnion(Session session, UnionType unionType, Query query, Query right) {
super(session); super(session);
this.unionType = unionType;
this.left = query; this.left = query;
this.right = right;
} }
@Override @Override
...@@ -96,18 +98,10 @@ public class SelectUnion extends Query { ...@@ -96,18 +98,10 @@ public class SelectUnion extends Query {
right.prepareJoinBatch(); right.prepareJoinBatch();
} }
public void setUnionType(UnionType type) {
this.unionType = type;
}
public UnionType getUnionType() { public UnionType getUnionType() {
return unionType; return unionType;
} }
public void setRight(Query select) {
right = select;
}
public Query getLeft() { public Query getLeft() {
return left; return left;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论