提交 931d3924 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remove MVCC code from ScanIndex

上级 e9400e3b
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
*/ */
package org.h2.index; package org.h2.index;
import java.util.Iterator;
import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
...@@ -17,17 +15,9 @@ import org.h2.result.SearchRow; ...@@ -17,17 +15,9 @@ import org.h2.result.SearchRow;
public class ScanCursor implements Cursor { public class ScanCursor implements Cursor {
private final ScanIndex scan; private final ScanIndex scan;
private Row row; private Row row;
private final Session session;
private final boolean multiVersion;
private Iterator<Row> delta;
ScanCursor(Session session, ScanIndex scan, boolean multiVersion) { ScanCursor(ScanIndex scan) {
this.session = session;
this.scan = scan; this.scan = scan;
this.multiVersion = multiVersion;
if (multiVersion) {
delta = scan.getDelta();
}
row = null; row = null;
} }
...@@ -43,29 +33,6 @@ public class ScanCursor implements Cursor { ...@@ -43,29 +33,6 @@ public class ScanCursor implements Cursor {
@Override @Override
public boolean next() { public boolean next() {
if (multiVersion) {
while (true) {
if (delta != null) {
if (!delta.hasNext()) {
delta = null;
row = null;
continue;
}
row = delta.next();
if (!row.isDeleted() || row.getSessionId() == session.getId()) {
continue;
}
} else {
row = scan.getNextRow(row);
if (row != null && row.getSessionId() != 0 &&
row.getSessionId() != session.getId()) {
continue;
}
}
break;
}
return row != null;
}
row = scan.getNextRow(row); row = scan.getNextRow(row);
return row != null; return row != null;
} }
......
...@@ -6,16 +6,11 @@ ...@@ -6,16 +6,11 @@
package org.h2.index; package org.h2.index;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.dml.AllColumnsForPlan; import org.h2.command.dml.AllColumnsForPlan;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
...@@ -36,19 +31,11 @@ public class ScanIndex extends BaseIndex { ...@@ -36,19 +31,11 @@ public class ScanIndex extends BaseIndex {
private long firstFree = -1; private long firstFree = -1;
private ArrayList<Row> rows = Utils.newSmallArrayList(); private ArrayList<Row> rows = Utils.newSmallArrayList();
private final RegularTable tableData; private final RegularTable tableData;
private int rowCountDiff;
private final HashMap<Integer, Integer> sessionRowCount;
private HashSet<Row> delta;
private long rowCount; private long rowCount;
public ScanIndex(RegularTable table, int id, IndexColumn[] columns, public ScanIndex(RegularTable table, int id, IndexColumn[] columns,
IndexType indexType) { IndexType indexType) {
initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType); initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
if (database.isMVStore()) {
sessionRowCount = new HashMap<>();
} else {
sessionRowCount = null;
}
tableData = table; tableData = table;
} }
...@@ -66,10 +53,6 @@ public class ScanIndex extends BaseIndex { ...@@ -66,10 +53,6 @@ public class ScanIndex extends BaseIndex {
} }
tableData.setRowCount(0); tableData.setRowCount(0);
rowCount = 0; rowCount = 0;
rowCountDiff = 0;
if (database.isMVStore()) {
sessionRowCount.clear();
}
} }
@Override @Override
...@@ -102,44 +85,13 @@ public class ScanIndex extends BaseIndex { ...@@ -102,44 +85,13 @@ public class ScanIndex extends BaseIndex {
rows.set((int) key, row); rows.set((int) key, row);
} }
row.setDeleted(false); row.setDeleted(false);
if (database.isMVStore()) {
if (delta == null) {
delta = new HashSet<>();
}
boolean wasDeleted = delta.remove(row);
if (!wasDeleted) {
delta.add(row);
}
incrementRowCount(session.getId(), 1);
}
rowCount++; rowCount++;
} }
@Override
public void commit(int operation, Row row) {
if (database.isMVStore()) {
if (delta != null) {
delta.remove(row);
}
incrementRowCount(row.getSessionId(),
operation == UndoLogRecord.DELETE ? 1 : -1);
}
}
private void incrementRowCount(int sessionId, int count) {
if (database.isMVStore()) {
Integer id = sessionId;
Integer c = sessionRowCount.get(id);
int current = c == null ? 0 : c.intValue();
sessionRowCount.put(id, current + count);
rowCountDiff += count;
}
}
@Override @Override
public void remove(Session session, Row row) { public void remove(Session session, Row row) {
// in-memory // in-memory
if (!database.isMVStore() && rowCount == 1) { if (rowCount == 1) {
rows = Utils.newSmallArrayList(); rows = Utils.newSmallArrayList();
firstFree = -1; firstFree = -1;
} else { } else {
...@@ -153,24 +105,12 @@ public class ScanIndex extends BaseIndex { ...@@ -153,24 +105,12 @@ public class ScanIndex extends BaseIndex {
rows.set((int) key, free); rows.set((int) key, free);
firstFree = key; firstFree = key;
} }
if (database.isMVStore()) {
// if storage is null, the delete flag is not yet set
row.setDeleted(true);
if (delta == null) {
delta = new HashSet<>();
}
boolean wasAdded = delta.remove(row);
if (!wasAdded) {
delta.add(row);
}
incrementRowCount(session.getId(), -1);
}
rowCount--; rowCount--;
} }
@Override @Override
public Cursor find(Session session, SearchRow first, SearchRow last) { public Cursor find(Session session, SearchRow first, SearchRow last) {
return new ScanCursor(session, this, database.isMVStore()); return new ScanCursor(this);
} }
@Override @Override
...@@ -182,13 +122,6 @@ public class ScanIndex extends BaseIndex { ...@@ -182,13 +122,6 @@ public class ScanIndex extends BaseIndex {
@Override @Override
public long getRowCount(Session session) { public long getRowCount(Session session) {
if (database.isMVStore()) {
Integer i = sessionRowCount.get(session.getId());
long count = i == null ? 0 : i.intValue();
count += rowCount;
count -= rowCountDiff;
return count;
}
return rowCount; return rowCount;
} }
...@@ -248,13 +181,6 @@ public class ScanIndex extends BaseIndex { ...@@ -248,13 +181,6 @@ public class ScanIndex extends BaseIndex {
throw DbException.getUnsupportedException("SCAN"); throw DbException.getUnsupportedException("SCAN");
} }
Iterator<Row> getDelta() {
if (delta == null) {
return Collections.emptyIterator();
}
return delta.iterator();
}
@Override @Override
public long getRowCountApproximation() { public long getRowCountApproximation() {
return rowCount; return rowCount;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论