提交 9ad1ffae authored 作者: S.Vladykin's avatar S.Vladykin

Switched to use linked list like approach + allow to get info from upper levels

上级 bd37e682
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
package org.h2.engine; package org.h2.engine;
import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -110,7 +109,7 @@ public class Session extends SessionWithState { ...@@ -110,7 +109,7 @@ public class Session extends SessionWithState {
private final int queryCacheSize; private final int queryCacheSize;
private SmallLRUCache<String, Command> queryCache; private SmallLRUCache<String, Command> queryCache;
private long modificationMetaID = -1; private long modificationMetaID = -1;
private ArrayDeque<SubQueryInfo> subQueryInfoStack = new ArrayDeque<SubQueryInfo>(); private SubQueryInfo subQueryInfo;
private int parsingView; private int parsingView;
/** /**
...@@ -145,18 +144,12 @@ public class Session extends SessionWithState { ...@@ -145,18 +144,12 @@ public class Session extends SessionWithState {
this.currentSchemaName = Constants.SCHEMA_MAIN; this.currentSchemaName = Constants.SCHEMA_MAIN;
} }
public void pushSubQueryInfo(SubQueryInfo subQueryInfo) { public void setSubQueryInfo(SubQueryInfo subQueryInfo) {
assert subQueryInfo != null; this.subQueryInfo = subQueryInfo;
subQueryInfoStack.addLast(subQueryInfo);
}
public void popSubQueryInfo(SubQueryInfo subQueryInfo) {
SubQueryInfo popped = subQueryInfoStack.pollLast();
assert popped == subQueryInfo;
} }
public SubQueryInfo getSubQueryInfo() { public SubQueryInfo getSubQueryInfo() {
return subQueryInfoStack.peekLast(); return subQueryInfo;
} }
public void setParsingView(boolean parsingView) { public void setParsingView(boolean parsingView) {
......
...@@ -198,12 +198,14 @@ public class ViewIndex extends BaseIndex implements SpatialIndex { ...@@ -198,12 +198,14 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
private static Query prepareSubQuery(String sql, Session session, int[] masks, private static Query prepareSubQuery(String sql, Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder, boolean preliminary) { TableFilter[] filters, int filter, SortOrder sortOrder, boolean preliminary) {
Prepared p; Prepared p;
SubQueryInfo info = new SubQueryInfo(masks, filters, filter, sortOrder, preliminary); SubQueryInfo upper = session.getSubQueryInfo();
session.pushSubQueryInfo(info); SubQueryInfo info = new SubQueryInfo(upper,
masks, filters, filter, sortOrder, preliminary);
session.setSubQueryInfo(info);
try { try {
p = session.prepare(sql, true); p = session.prepare(sql, true);
} finally { } finally {
session.popSubQueryInfo(info); session.setSubQueryInfo(upper);
} }
return (Query) p; return (Query) p;
} }
......
...@@ -20,8 +20,10 @@ public class SubQueryInfo { ...@@ -20,8 +20,10 @@ public class SubQueryInfo {
private int filter; private int filter;
private SortOrder sortOrder; private SortOrder sortOrder;
private boolean preliminary; private boolean preliminary;
private SubQueryInfo upper;
/** /**
* @param upper upper level sub-query if any
* @param masks index conditions masks * @param masks index conditions masks
* @param filters table filters * @param filters table filters
* @param filter current filter * @param filter current filter
...@@ -29,8 +31,9 @@ public class SubQueryInfo { ...@@ -29,8 +31,9 @@ public class SubQueryInfo {
* @param preliminary if this is a preliminary query optimization * @param preliminary if this is a preliminary query optimization
* without global conditions * without global conditions
*/ */
public SubQueryInfo(int[] masks, TableFilter[] filters, int filter, public SubQueryInfo(SubQueryInfo upper, int[] masks, TableFilter[] filters, int filter,
SortOrder sortOrder, boolean preliminary) { SortOrder sortOrder, boolean preliminary) {
this.upper = upper;
this.masks = masks; this.masks = masks;
this.filters = filters; this.filters = filters;
this.filter = filter; this.filter = filter;
...@@ -38,6 +41,10 @@ public class SubQueryInfo { ...@@ -38,6 +41,10 @@ public class SubQueryInfo {
this.preliminary = preliminary; this.preliminary = preliminary;
} }
public SubQueryInfo getUpper() {
return upper;
}
public int[] getMasks() { public int[] getMasks() {
return masks; return masks;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论