提交 47559bd1 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVTableEngine improvements

上级 d893c6bd
......@@ -856,6 +856,9 @@ public class Session extends SessionWithState {
* @return true if yes
*/
public boolean containsUncommitted() {
if (database.getMvStore() != null) {
return transaction != null;
}
return firstUncommittedLog != Session.LOG_WRITTEN;
}
......
......@@ -19,7 +19,7 @@ import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.RegularTable;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueGeometry;
......@@ -41,7 +41,6 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
private final MVRTreeMap<Long> treeMap;
private final MVStore store;
private final RegularTable tableData;
private boolean closed;
private boolean needRebuild;
private boolean persistent;
......@@ -58,7 +57,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
* @param create whether to create a new index
* @param session the session.
*/
public SpatialTreeIndex(RegularTable table, int id, String indexName,
public SpatialTreeIndex(Table table, int id, String indexName,
IndexColumn[] columns, IndexType indexType, boolean persistent,
boolean create, Session session) {
if (indexType.isUnique()) {
......@@ -82,7 +81,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
initBaseIndex(table, id, indexName, columns, indexType);
this.needRebuild = create;
this.persistent = persistent;
tableData = table;
this.table = table;
if (!database.isStarting()) {
if (columns[0].column.getType() != Value.GEOMETRY) {
throw DbException.getUnsupportedException("spatial index on non-geometry column, "
......@@ -158,7 +157,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
}
private Cursor find(Session session) {
return new SpatialCursor(treeMap.keySet().iterator(), tableData, session);
return new SpatialCursor(treeMap.keySet().iterator(), table, session);
}
@Override
......@@ -166,7 +165,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
if (intersection == null) {
return find(filter.getSession());
}
return new SpatialCursor(treeMap.findIntersectingKeys(getEnvelope(intersection)), tableData, filter.getSession());
return new SpatialCursor(treeMap.findIntersectingKeys(getEnvelope(intersection)), table, filter.getSession());
}
@Override
......@@ -189,7 +188,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
@Override
public double getCost(Session session, int[] masks, TableFilter filter, SortOrder sortOrder) {
return getCostRangeIndex(masks, tableData.getRowCountApproximation(), filter, sortOrder);
return getCostRangeIndex(masks, table.getRowCountApproximation(), filter, sortOrder);
}
@Override
......@@ -253,18 +252,18 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
private final Iterator<SpatialKey> it;
private SpatialKey current;
private final RegularTable tableData;
private final Table table;
private Session session;
public SpatialCursor(Iterator<SpatialKey> it, RegularTable tableData, Session session) {
public SpatialCursor(Iterator<SpatialKey> it, Table table, Session session) {
this.it = it;
this.tableData = tableData;
this.table = table;
this.session = session;
}
@Override
public Row get() {
return tableData.getRow(session, current.getId());
return table.getRow(session, current.getId());
}
@Override
......
......@@ -26,6 +26,7 @@ import org.h2.index.Cursor;
import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.index.MultiVersionIndex;
import org.h2.index.SpatialTreeIndex;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.mvstore.db.TransactionStore.Transaction;
......@@ -354,13 +355,7 @@ public class MVTable extends TableBase {
// ignore
}
/**
* Get the given row.
*
* @param session the session
* @param key the primary key
* @return the row
*/
@Override
public Row getRow(Session session, long key) {
return primaryIndex.getRow(session, key);
}
......@@ -401,6 +396,9 @@ public class MVTable extends TableBase {
primaryIndex.setMainIndexColumn(mainIndexColumn);
index = new MVDelegateIndex(this, indexId,
indexName, primaryIndex, indexType);
} else if (indexType.isSpatial()) {
index = new SpatialTreeIndex(this, indexId, indexName, cols,
indexType, true, create, session);
} else {
index = new MVSecondaryIndex(session.getDatabase(),
this, indexId,
......
......@@ -269,7 +269,7 @@ public class MVTableEngine implements TableEngine {
* @param maxCompactTime the maximum time in milliseconds to compact
*/
public void close(long maxCompactTime) {
if (!store.isClosed()) {
if (!store.isClosed() && store.getFileStore() != null) {
if (!store.getFileStore().isReadOnly()) {
store.store();
long start = System.currentTimeMillis();
......
......@@ -101,13 +101,7 @@ public class RegularTable extends TableBase {
}
}
/**
* Read the given row.
*
* @param session the session
* @param key unique key
* @return the row
*/
@Override
public Row getRow(Session session, long key) {
return scanIndex.getRow(session, key);
}
......
......@@ -165,6 +165,17 @@ public abstract class Table extends SchemaObjectBase {
*/
public abstract Index addIndex(Session session, String indexName, int indexId, IndexColumn[] cols, IndexType indexType,
boolean create, String indexComment);
/**
* Get the given row.
*
* @param session the session
* @param key the primary key
* @return the row
*/
public Row getRow(Session session, long key) {
return null;
}
/**
* Remove a row from the table and all indexes.
......
......@@ -1247,10 +1247,12 @@ public abstract class TestBase {
ArrayList<String> list2 = new ArrayList<String>();
while (rs1.next()) {
String s1 = rs1.getString(1);
s1 = removeRowCount(s1);
if (!rs2.next()) {
fail("expected: " + s1);
}
String s2 = rs2.getString(1);
s2 = removeRowCount(s2);
if (!s1.equals(s2)) {
list1.add(s1);
list2.add(s2);
......@@ -1258,12 +1260,20 @@ public abstract class TestBase {
}
for (String s : list1) {
if (!list2.remove(s)) {
fail("only found in first: " + s);
fail("only found in first: " + s + " remaining: " + list2);
}
}
assertEquals(0, list2.size());
assertEquals("remaining: " + list2, 0, list2.size());
assertFalse(rs2.next());
}
private static String removeRowCount(String scriptLine) {
int index = scriptLine.indexOf("+/-");
if (index >= 0) {
scriptLine = scriptLine.substring(index);
}
return scriptLine;
}
/**
* Create a new object of the calling class.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论