提交 7f81a4a8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Don't use the page store when using the MVStore table engine

上级 97c5cb26
...@@ -10,6 +10,7 @@ import java.io.InputStream; ...@@ -10,6 +10,7 @@ import java.io.InputStream;
import java.lang.Thread.UncaughtExceptionHandler; import java.lang.Thread.UncaughtExceptionHandler;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.h2.api.TableEngine; import org.h2.api.TableEngine;
...@@ -102,7 +103,7 @@ public class MVTableEngine implements TableEngine { ...@@ -102,7 +103,7 @@ public class MVTableEngine implements TableEngine {
@Override @Override
public TableBase createTable(CreateTableData data) { public TableBase createTable(CreateTableData data) {
Database db = data.session.getDatabase(); Database db = data.session.getDatabase();
if (!data.persistData || (data.temporary && !data.persistIndexes)) { if (!data.persistData) {
return new RegularTable(data); return new RegularTable(data);
} }
Store store = init(db); Store store = init(db);
...@@ -125,7 +126,7 @@ public class MVTableEngine implements TableEngine { ...@@ -125,7 +126,7 @@ public class MVTableEngine implements TableEngine {
/** /**
* The list of open tables. * The list of open tables.
*/ */
final ArrayList<MVTable> openTables = New.arrayList(); final List<MVTable> openTables = Collections.synchronizedList(new ArrayList<MVTable>());
/** /**
* The store. * The store.
...@@ -153,7 +154,7 @@ public class MVTableEngine implements TableEngine { ...@@ -153,7 +154,7 @@ public class MVTableEngine implements TableEngine {
} }
public List<MVTable> getTables() { public List<MVTable> getTables() {
return openTables; return new ArrayList<MVTable>(openTables);
} }
/** /**
......
...@@ -19,6 +19,7 @@ import org.h2.schema.Schema; ...@@ -19,6 +19,7 @@ import org.h2.schema.Schema;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.RegularTable; import org.h2.table.RegularTable;
import org.h2.table.Table;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
...@@ -29,10 +30,11 @@ public class ResultTempTable implements ResultExternal { ...@@ -29,10 +30,11 @@ public class ResultTempTable implements ResultExternal {
private static final String COLUMN_NAME = "DATA"; private static final String COLUMN_NAME = "DATA";
private final SortOrder sort; private final SortOrder sort;
private final Session session;
private final Index index; private final Index index;
private RegularTable table; private Session session;
private Table table;
private Cursor resultCursor; private Cursor resultCursor;
private int rowCount;
private final ResultTempTable parent; private final ResultTempTable parent;
private boolean closed; private boolean closed;
...@@ -53,7 +55,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -53,7 +55,7 @@ public class ResultTempTable implements ResultExternal {
data.persistData = true; data.persistData = true;
data.create = true; data.create = true;
data.session = session; data.session = session;
table = (RegularTable) schema.createTable(data); table = schema.createTable(data);
int indexId = session.getDatabase().allocateObjectId(); int indexId = session.getDatabase().allocateObjectId();
IndexColumn indexColumn = new IndexColumn(); IndexColumn indexColumn = new IndexColumn();
indexColumn.column = column; indexColumn.column = column;
...@@ -61,9 +63,14 @@ public class ResultTempTable implements ResultExternal { ...@@ -61,9 +63,14 @@ public class ResultTempTable implements ResultExternal {
IndexType indexType; IndexType indexType;
indexType = IndexType.createPrimaryKey(true, false); indexType = IndexType.createPrimaryKey(true, false);
IndexColumn[] indexCols = { indexColumn }; IndexColumn[] indexCols = { indexColumn };
index = new PageBtreeIndex(table, indexId, data.tableName, indexCols, indexType, true, session); if (session.getDatabase().getMvStore() != null) {
index.setTemporary(true); index = table.addIndex(session, data.tableName, indexId, indexCols, indexType, true, null);
table.getIndexes().add(index); index.setTemporary(true);
} else {
index = new PageBtreeIndex((RegularTable) table, indexId, data.tableName, indexCols, indexType, true, session);
index.setTemporary(true);
table.getIndexes().add(index);
}
parent = null; parent = null;
} }
...@@ -72,6 +79,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -72,6 +79,7 @@ public class ResultTempTable implements ResultExternal {
this.session = parent.session; this.session = parent.session;
this.table = parent.table; this.table = parent.table;
this.index = parent.index; this.index = parent.index;
this.rowCount = parent.rowCount;
// sort is only used when adding rows // sort is only used when adding rows
this.sort = null; this.sort = null;
reset(); reset();
...@@ -96,8 +104,9 @@ public class ResultTempTable implements ResultExternal { ...@@ -96,8 +104,9 @@ public class ResultTempTable implements ResultExternal {
if (cursor != null) { if (cursor != null) {
row = cursor.get(); row = cursor.get();
table.removeRow(session, row); table.removeRow(session, row);
rowCount--;
} }
return (int) table.getRowCount(session); return rowCount;
} }
@Override @Override
...@@ -111,8 +120,9 @@ public class ResultTempTable implements ResultExternal { ...@@ -111,8 +120,9 @@ public class ResultTempTable implements ResultExternal {
Cursor cursor = find(row); Cursor cursor = find(row);
if (cursor == null) { if (cursor == null) {
table.addRow(session, row); table.addRow(session, row);
rowCount++;
} }
return (int) table.getRowCount(session); return rowCount;
} }
@Override @Override
...@@ -123,7 +133,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -123,7 +133,7 @@ public class ResultTempTable implements ResultExternal {
for (Value[] values : rows) { for (Value[] values : rows) {
addRow(values); addRow(values);
} }
return (int) table.getRowCount(session); return rowCount;
} }
private synchronized void closeChild() { private synchronized void closeChild() {
...@@ -186,6 +196,21 @@ public class ResultTempTable implements ResultExternal { ...@@ -186,6 +196,21 @@ public class ResultTempTable implements ResultExternal {
@Override @Override
public Value[] next() { public Value[] next() {
if (resultCursor == null) {
if (session.getDatabase().getMvStore() != null) {
// sometimes the transaction is already committed,
// in which case we can't use the session
if (index.getRowCount(session) == 0 && rowCount > 0) {
// this means querying is not transactional
resultCursor = index.find((Session) null, null, null);
} else {
// the transaction is still open
resultCursor = index.find(session, null, null);
}
} else {
resultCursor = index.find(session, null, null);
}
}
if (!resultCursor.next()) { if (!resultCursor.next()) {
return null; return null;
} }
...@@ -196,7 +221,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -196,7 +221,7 @@ public class ResultTempTable implements ResultExternal {
@Override @Override
public void reset() { public void reset() {
resultCursor = index.find(session, null, null); resultCursor = null;
} }
private static Row convertToRow(Value[] values) { private static Row convertToRow(Value[] values) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论