提交 129a021d authored 作者: Thomas Mueller's avatar Thomas Mueller

new experimental page store

上级 f1c816b8
...@@ -229,7 +229,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -229,7 +229,7 @@ public class ScriptCommand extends ScriptBase {
add(sql, false); add(sql, false);
if (Table.TABLE.equals(tableType)) { if (Table.TABLE.equals(tableType)) {
if (table.canGetRowCount()) { if (table.canGetRowCount()) {
String rowcount = "-- " + table.getRowCount(session) + " = SELECT COUNT(*) FROM " String rowcount = "-- " + table.getRowCountApproximation() + " +/- SELECT COUNT(*) FROM "
+ table.getSQL(); + table.getSQL();
add(rowcount, false); add(rowcount, false);
} }
......
...@@ -36,7 +36,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -36,7 +36,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
protected int[] columnIds; protected int[] columnIds;
protected Table table; protected Table table;
protected IndexType indexType; protected IndexType indexType;
protected long rowCount;
protected boolean isMultiVersion; protected boolean isMultiVersion;
/** /**
...@@ -179,10 +178,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -179,10 +178,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
throw Message.getInternalError(); throw Message.getInternalError();
} }
public long getRowCount(Session session) {
return rowCount;
}
public int getLookupCost(long rowCount) { public int getLookupCost(long rowCount) {
return 2; return 2;
} }
......
...@@ -54,6 +54,7 @@ public class BtreeIndex extends BaseIndex implements RecordReader { ...@@ -54,6 +54,7 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
private boolean needRebuild; private boolean needRebuild;
private int headPos; private int headPos;
private long lastChange; private long lastChange;
private long rowCount;
/** /**
* Create a new b tree index with the given properties. If the index does * Create a new b tree index with the given properties. If the index does
...@@ -424,4 +425,12 @@ public class BtreeIndex extends BaseIndex implements RecordReader { ...@@ -424,4 +425,12 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
return cursor; return cursor;
} }
public long getRowCount(Session session) {
return rowCount;
}
public long getRowCountApproximation() {
return rowCount;
}
} }
...@@ -56,7 +56,7 @@ public class FunctionIndex extends BaseIndex { ...@@ -56,7 +56,7 @@ public class FunctionIndex extends BaseIndex {
} }
long expectedRows; long expectedRows;
if (functionTable.canGetRowCount()) { if (functionTable.canGetRowCount()) {
expectedRows = functionTable.getRowCount(session); expectedRows = functionTable.getRowCountApproximation();
} else { } else {
expectedRows = SysProperties.ESTIMATED_FUNCTION_TABLE_ROWS; expectedRows = SysProperties.ESTIMATED_FUNCTION_TABLE_ROWS;
} }
...@@ -87,4 +87,12 @@ public class FunctionIndex extends BaseIndex { ...@@ -87,4 +87,12 @@ public class FunctionIndex extends BaseIndex {
throw Message.getUnsupportedException(); throw Message.getUnsupportedException();
} }
public long getRowCount(Session session) {
return functionTable.getRowCount(session);
}
public long getRowCountApproximation() {
return functionTable.getRowCountApproximation();
}
} }
...@@ -29,6 +29,7 @@ public class HashIndex extends BaseIndex { ...@@ -29,6 +29,7 @@ public class HashIndex extends BaseIndex {
private ValueHashMap rows; private ValueHashMap rows;
private IntIntHashMap intMap; private IntIntHashMap intMap;
private TableData tableData; private TableData tableData;
private long rowCount;
public HashIndex(TableData table, int id, String indexName, IndexColumn[] columns, IndexType indexType) { public HashIndex(TableData table, int id, String indexName, IndexColumn[] columns, IndexType indexType) {
initBaseIndex(table, id, indexName, columns, indexType); initBaseIndex(table, id, indexName, columns, indexType);
...@@ -152,4 +153,12 @@ public class HashIndex extends BaseIndex { ...@@ -152,4 +153,12 @@ public class HashIndex extends BaseIndex {
throw Message.getUnsupportedException(); throw Message.getUnsupportedException();
} }
public long getRowCount(Session session) {
return rowCount;
}
public long getRowCountApproximation() {
return rowCount;
}
} }
...@@ -150,6 +150,13 @@ public interface Index extends SchemaObject { ...@@ -150,6 +150,13 @@ public interface Index extends SchemaObject {
* @return the row count * @return the row count
*/ */
long getRowCount(Session session); long getRowCount(Session session);
/**
* Get the approximated row count for this table.
*
* @return the approximated row count
*/
long getRowCountApproximation();
/** /**
* Estimate the cost required to search a number of rows. * Estimate the cost required to search a number of rows.
......
...@@ -30,6 +30,7 @@ public class LinkedIndex extends BaseIndex { ...@@ -30,6 +30,7 @@ public class LinkedIndex extends BaseIndex {
private TableLink link; private TableLink link;
private String targetTableName; private String targetTableName;
private long rowCount;
public LinkedIndex(TableLink table, int id, IndexColumn[] columns, IndexType indexType) { public LinkedIndex(TableLink table, int id, IndexColumn[] columns, IndexType indexType) {
initBaseIndex(table, id, null, columns, indexType); initBaseIndex(table, id, null, columns, indexType);
...@@ -285,4 +286,12 @@ public class LinkedIndex extends BaseIndex { ...@@ -285,4 +286,12 @@ public class LinkedIndex extends BaseIndex {
return Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_2, new String[] { sql, e.toString() }, e); return Message.getSQLException(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_2, new String[] { sql, e.toString() }, e);
} }
public long getRowCount(Session session) {
return rowCount;
}
public long getRowCountApproximation() {
return rowCount;
}
} }
...@@ -49,9 +49,9 @@ public class MetaIndex extends BaseIndex { ...@@ -49,9 +49,9 @@ public class MetaIndex extends BaseIndex {
public double getCost(Session session, int[] masks) { public double getCost(Session session, int[] masks) {
if (scan) { if (scan) {
return 10000; return 10 * MetaTable.ROW_COUNT_APPROXIMATION;
} }
return getCostRangeIndex(masks, 1000); return getCostRangeIndex(masks, MetaTable.ROW_COUNT_APPROXIMATION);
} }
public void truncate(Session session) throws SQLException { public void truncate(Session session) throws SQLException {
...@@ -90,4 +90,12 @@ public class MetaIndex extends BaseIndex { ...@@ -90,4 +90,12 @@ public class MetaIndex extends BaseIndex {
throw Message.getUnsupportedException(); throw Message.getUnsupportedException();
} }
public long getRowCount(Session session) {
return MetaTable.ROW_COUNT_APPROXIMATION;
}
public long getRowCountApproximation() {
return MetaTable.ROW_COUNT_APPROXIMATION;
}
} }
...@@ -308,4 +308,8 @@ public class MultiVersionIndex implements Index { ...@@ -308,4 +308,8 @@ public class MultiVersionIndex implements Index {
base.setTemporary(temporary); base.setTemporary(temporary);
} }
public long getRowCountApproximation() {
return base.getRowCountApproximation();
}
} }
...@@ -240,10 +240,6 @@ class PageDataLeaf extends PageData { ...@@ -240,10 +240,6 @@ class PageDataLeaf extends PageData {
* @return the row * @return the row
*/ */
Row getRowAt(int at) throws SQLException { Row getRowAt(int at) throws SQLException {
if (at >= rows.length) {
int test;
System.out.println("test");
}
Row r = rows[at]; Row r = rows[at];
if (r == null) { if (r == null) {
if (firstOverflowPageId != 0) { if (firstOverflowPageId != 0) {
......
...@@ -38,6 +38,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -38,6 +38,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
// TODO use an undo log and maybe redo log (for performance) // TODO use an undo log and maybe redo log (for performance)
// TODO file position, content checksums // TODO file position, content checksums
private int nextKey; private int nextKey;
private long rowCount;
private long rowCountApproximation;
public PageScanIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType, int headPos) throws SQLException { public PageScanIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType, int headPos) throws SQLException {
initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType); initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType);
...@@ -137,7 +139,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -137,7 +139,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
} }
public double getCost(Session session, int[] masks) throws SQLException { public double getCost(Session session, int[] masks) throws SQLException {
long cost = 10 * tableData.getRowCount(session) + Constants.COST_ROW_OFFSET; long cost = 10 * tableData.getRowCountApproximation() + Constants.COST_ROW_OFFSET;
return cost; return cost;
} }
...@@ -192,4 +194,13 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -192,4 +194,13 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
return tableData.readRow(data); return tableData.readRow(data);
} }
public long getRowCountApproximation() {
return rowCountApproximation;
}
public long getRowCount(Session session) {
int todo;
return rowCount;
}
} }
...@@ -81,4 +81,12 @@ public class RangeIndex extends BaseIndex { ...@@ -81,4 +81,12 @@ public class RangeIndex extends BaseIndex {
return new RangeCursor(pos, pos); return new RangeCursor(pos, pos);
} }
public long getRowCount(Session session) {
return rangeTable.getRowCountApproximation();
}
public long getRowCountApproximation() {
return rangeTable.getRowCountApproximation();
}
} }
...@@ -41,6 +41,7 @@ public class ScanIndex extends BaseIndex implements RowIndex { ...@@ -41,6 +41,7 @@ public class ScanIndex extends BaseIndex implements RowIndex {
private int rowCountDiff; private int rowCountDiff;
private HashMap sessionRowCount; private HashMap sessionRowCount;
private HashSet delta; private HashSet delta;
private long rowCount;
public ScanIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType) { public ScanIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType) {
initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType); initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType);
...@@ -201,7 +202,7 @@ public class ScanIndex extends BaseIndex implements RowIndex { ...@@ -201,7 +202,7 @@ public class ScanIndex extends BaseIndex implements RowIndex {
} }
public double getCost(Session session, int[] masks) { public double getCost(Session session, int[] masks) {
long cost = tableData.getRowCount(session) + Constants.COST_ROW_OFFSET; long cost = tableData.getRowCountApproximation() + Constants.COST_ROW_OFFSET;
if (storage != null) { if (storage != null) {
cost *= 10; cost *= 10;
} }
...@@ -212,11 +213,11 @@ public class ScanIndex extends BaseIndex implements RowIndex { ...@@ -212,11 +213,11 @@ public class ScanIndex extends BaseIndex implements RowIndex {
if (database.isMultiVersion()) { if (database.isMultiVersion()) {
Integer i = (Integer) sessionRowCount.get(ObjectUtils.getInteger(session.getId())); Integer i = (Integer) sessionRowCount.get(ObjectUtils.getInteger(session.getId()));
long count = i == null ? 0 : i.intValue(); long count = i == null ? 0 : i.intValue();
count += super.getRowCount(session); count += rowCount;
count -= rowCountDiff; count -= rowCountDiff;
return count; return count;
} }
return super.getRowCount(session); return rowCount;
} }
/** /**
...@@ -277,4 +278,8 @@ public class ScanIndex extends BaseIndex implements RowIndex { ...@@ -277,4 +278,8 @@ public class ScanIndex extends BaseIndex implements RowIndex {
return delta == null ? Collections.EMPTY_LIST.iterator() : delta.iterator(); return delta == null ? Collections.EMPTY_LIST.iterator() : delta.iterator();
} }
public long getRowCountApproximation() {
return rowCount;
}
} }
...@@ -25,6 +25,7 @@ public class TreeIndex extends BaseIndex { ...@@ -25,6 +25,7 @@ public class TreeIndex extends BaseIndex {
private TreeNode root; private TreeNode root;
private TableData tableData; private TableData tableData;
private long rowCount;
public TreeIndex(TableData table, int id, String indexName, IndexColumn[] columns, IndexType indexType) { public TreeIndex(TableData table, int id, String indexName, IndexColumn[] columns, IndexType indexType) {
initBaseIndex(table, id, indexName, columns, indexType); initBaseIndex(table, id, indexName, columns, indexType);
...@@ -293,7 +294,7 @@ public class TreeIndex extends BaseIndex { ...@@ -293,7 +294,7 @@ public class TreeIndex extends BaseIndex {
} }
public double getCost(Session session, int[] masks) { public double getCost(Session session, int[] masks) {
return getCostRangeIndex(masks, tableData.getRowCount(session)); return getCostRangeIndex(masks, tableData.getRowCountApproximation());
} }
public void remove(Session session) { public void remove(Session session) {
...@@ -414,4 +415,12 @@ public class TreeIndex extends BaseIndex { ...@@ -414,4 +415,12 @@ public class TreeIndex extends BaseIndex {
return cursor; return cursor;
} }
public long getRowCount(Session session) {
return rowCount;
}
public long getRowCountApproximation() {
return rowCount;
}
} }
...@@ -265,4 +265,12 @@ public class ViewIndex extends BaseIndex { ...@@ -265,4 +265,12 @@ public class ViewIndex extends BaseIndex {
this.recursive = value; this.recursive = value;
} }
public long getRowCount(Session session) {
return 0;
}
public long getRowCountApproximation() {
return 0;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论