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

Inline parseSelectUnionExtension() into parseSelectUnion() and optimize it

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