提交 79ba7f42 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 774b1795
......@@ -9,7 +9,6 @@ import java.math.BigInteger;
import java.sql.SQLException;
import java.text.Collator;
import java.util.HashSet;
import org.h2.command.ddl.AlterIndexRename;
import org.h2.command.ddl.AlterSequence;
import org.h2.command.ddl.AlterTableAddConstraint;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Right;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.command.dml.Insert;
import org.h2.command.dml.Query;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Role;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint;
import org.h2.engine.Database;
......
......@@ -5,7 +5,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Comment;
import org.h2.engine.Database;
......
......@@ -7,7 +7,6 @@ package org.h2.command.dml;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
......@@ -238,7 +237,7 @@ public class Select extends Query {
// can't use the scan index
continue;
}
if(index.indexType.isHash()) {
if(index.getIndexType().isHash()) {
continue;
}
Column[] indexCols = index.getColumns();
......@@ -490,7 +489,7 @@ public class Select extends Query {
if(sort != null && !isQuickQuery && !isGroupQuery && !distinct) {
Index index = getSortIndex();
Index current = topTableFilter.getIndex();
if(index != null && (current.indexType.isScan() || current == index)) {
if(index != null && (current.getIndexType().isScan() || current == index)) {
topTableFilter.setIndex(index);
sort = null;
}
......
......@@ -12,14 +12,14 @@ import org.h2.index.Index;
import org.h2.message.Trace;
import org.h2.result.Row;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.SchemaObjectBase;
import org.h2.table.Column;
import org.h2.table.Table;
/**
* @author Thomas
*/
public abstract class Constraint extends SchemaObject {
public abstract class Constraint extends SchemaObjectBase {
public static final String CHECK = "CHECK", REFERENTIAL = "REFERENTIAL", UNIQUE = "UNIQUE";
protected Table table;
......
......@@ -5,7 +5,6 @@
package org.h2.constraint;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......
......@@ -5,7 +5,6 @@
package org.h2.constraint;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.engine.Session;
import org.h2.index.Index;
......
......@@ -11,7 +11,7 @@ import org.h2.message.Trace;
import org.h2.table.Table;
import org.h2.util.StringUtils;
public class Comment extends DbObject {
public class Comment extends DbObjectBase {
private final int objectType;
private final String objectName;
......
......@@ -11,7 +11,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.h2.api.DatabaseEventListener;
import org.h2.command.dml.SetTypes;
import org.h2.constant.ErrorCode;
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.engine;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.table.Table;
import org.h2.util.ObjectArray;
/**
* @author Thomas
*/
public abstract class DbObjectBase implements DbObject {
private int id;
protected Database database;
protected Trace trace;
private String objectName;
private long modificationId;
private boolean temporary;
protected String comment;
protected DbObjectBase(Database database, int id, String name, String traceModule) {
this.database = database;
this.trace = database.getTrace(traceModule);
this.id = id;
this.objectName = name;
this.modificationId = database.getModificationMetaId();
}
public void setModified() {
this.modificationId = database == null ? -1 : database.getNextModificationMetaId();
}
public long getModificationId() {
return modificationId;
}
protected void setObjectName(String name) {
objectName = name;
}
public String getSQL() {
return Parser.quoteIdentifier(objectName);
}
public ObjectArray getChildren() {
return null;
}
public Database getDatabase() {
return database;
}
public int getId() {
return id;
}
public String getName() {
return objectName;
}
public abstract String getCreateSQLForCopy(Table table, String quotedName);
public abstract String getCreateSQL();
public abstract String getDropSQL();
public abstract int getType();
public abstract void removeChildrenAndResources(Session session) throws SQLException;
public abstract void checkRename() throws SQLException;
protected void invalidate() {
setModified();
id = -1;
database = null;
trace = null;
objectName = null;
}
public int getHeadPos() {
return 0;
}
public void rename(String newName) throws SQLException {
checkRename();
objectName = newName;
setModified();
}
public boolean getTemporary() {
return temporary;
}
public void setTemporary(boolean temporary) {
this.temporary = temporary;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getComment() {
return comment;
}
static int getCreateOrder(int type) {
switch(type) {
case SETTING:
return 0;
case USER:
return 1;
case SCHEMA:
return 2;
case USER_DATATYPE:
return 3;
case SEQUENCE:
return 4;
case CONSTANT:
return 5;
case FUNCTION_ALIAS:
return 6;
case TABLE_OR_VIEW:
return 7;
case INDEX:
return 8;
case CONSTRAINT:
return 9;
case TRIGGER:
return 10;
case ROLE:
return 11;
case RIGHT:
return 12;
case COMMENT:
return 13;
default:
throw Message.getInternalError("type="+type);
}
}
}
......@@ -19,7 +19,7 @@ import org.h2.value.DataType;
import org.h2.value.Value;
import org.h2.value.ValueNull;
public class FunctionAlias extends DbObject {
public class FunctionAlias extends DbObjectBase {
private boolean hasConnectionParam;
private String className;
......
......@@ -35,8 +35,8 @@ public class MetaRecord {
public int compare(Object o1, Object o2) {
MetaRecord m1 = (MetaRecord)o1;
MetaRecord m2 = (MetaRecord)o2;
int c1 = DbObject.getCreateOrder(m1.getObjectType());
int c2 = DbObject.getCreateOrder(m2.getObjectType());
int c1 = DbObjectBase.getCreateOrder(m1.getObjectType());
int c2 = DbObjectBase.getCreateOrder(m2.getObjectType());
if(c1 != c2) {
return c1 - c2;
}
......
......@@ -10,7 +10,7 @@ import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.table.Table;
public class Right extends DbObject {
public class Right extends DbObjectBase {
public static final int SELECT = 1, DELETE = 2, INSERT = 4, UPDATE = 8, ALL = 15;
......
......@@ -12,7 +12,7 @@ import org.h2.constant.ErrorCode;
import org.h2.message.Message;
import org.h2.table.Table;
public abstract class RightOwner extends DbObject {
public abstract class RightOwner extends DbObjectBase {
// key: role; value: right
private HashMap grantedRoles;
......
......@@ -10,7 +10,7 @@ import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.table.Table;
public class Setting extends DbObject {
public class Setting extends DbObjectBase {
private int intValue;
private String stringValue;
......
......@@ -11,7 +11,7 @@ import org.h2.message.Trace;
import org.h2.table.Column;
import org.h2.table.Table;
public class UserDataType extends DbObject {
public class UserDataType extends DbObjectBase {
private Column column;
......
......@@ -16,6 +16,7 @@ import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.index.Index;
import org.h2.message.Message;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
......@@ -160,7 +161,8 @@ public class Aggregate extends Expression {
case MAX:
boolean first = type == MIN;
Index index = getColumnIndex(first);
Value v = index.findFirstOrLast(session, first);
SearchRow row = index.findFirstOrLast(session, first);
Value v = row.getValue(index.getColumns()[0].getColumnId());
return v;
default:
throw Message.getInternalError("type="+type);
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.index;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.schema.SchemaObjectBase;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.util.StringUtils;
import org.h2.value.Value;
import org.h2.value.ValueNull;
/**
* @author Thomas
*/
public abstract class BaseIndex extends SchemaObjectBase implements Index {
protected Column[] columns;
protected int[] columnIndex;
protected Table table;
protected IndexType indexType;
protected long rowCount;
public BaseIndex(Table table, int id, String name, Column[] columns, IndexType indexType) {
super(table.getSchema(), id, name, Trace.INDEX);
this.indexType = indexType;
this.table = table;
if(columns != null) {
this.columns = columns;
columnIndex = new int[columns.length];
for(int i=0; i<columns.length; i++) {
columnIndex[i] = columns[i].getColumnId();
}
}
}
public String getDropSQL() {
return null;
}
public SQLException getDuplicateKeyException() {
StringBuffer buff = new StringBuffer();
buff.append(getName());
buff.append(" ");
buff.append(" ON ");
buff.append(table.getSQL());
buff.append("(");
buff.append(getColumnListSQL());
buff.append(")");
return Message.getSQLException(ErrorCode.DUPLICATE_KEY_1, buff.toString());
}
public String getPlanSQL() {
return getSQL();
}
public void removeChildrenAndResources(Session session) throws SQLException {
table.removeIndex(this);
remove(session);
}
public abstract void close(Session session) throws SQLException;
public abstract void add(Session session, Row row) throws SQLException;
public abstract void remove(Session session, Row row) throws SQLException;
public abstract Cursor find(Session session, SearchRow first, SearchRow last) throws SQLException;
public abstract double getCost(Session session, int[] masks) throws SQLException;
public abstract void remove(Session session) throws SQLException;
public abstract void truncate(Session session) throws SQLException;
public abstract boolean canGetFirstOrLast(boolean first);
public abstract SearchRow findFirstOrLast(Session session, boolean first) throws SQLException;
public abstract boolean needRebuild();
public long getRowCount(Session session) {
return rowCount;
}
public int getLookupCost(long rowCount) {
return 2;
}
public long getCostRangeIndex(int[] masks, long rowCount) throws SQLException {
rowCount += Constants.COST_ROW_OFFSET;
long cost = rowCount;
int totalSelectivity = 0;
for (int i = 0; masks != null && i < columns.length; i++) {
Column column = columns[i];
int index = column.getColumnId();
int mask = masks[index];
if ((mask & IndexCondition.EQUALITY) == IndexCondition.EQUALITY) {
if(i == columns.length-1 && getIndexType().isUnique()) {
cost = getLookupCost(rowCount) + 1;
break;
}
totalSelectivity = 100 - ((100-totalSelectivity) * (100-column.getSelectivity()) / 100);
long distinctRows = rowCount * totalSelectivity / 100;
if(distinctRows <= 0) {
distinctRows = 1;
}
long rowsSelected = rowCount / distinctRows;
if(rowsSelected < 1) {
rowsSelected = 1;
}
cost = getLookupCost(rowCount) + rowsSelected;
} else if ((mask & IndexCondition.RANGE) == IndexCondition.RANGE) {
cost = getLookupCost(rowCount) + rowCount / 4;
break;
} else if ((mask & IndexCondition.START) == IndexCondition.START) {
cost = getLookupCost(rowCount) + rowCount / 3;
break;
} else if ((mask & IndexCondition.END) == IndexCondition.END) {
cost = rowCount / 3;
break;
} else {
break;
}
}
return cost;
}
public int compareRows(SearchRow rowData, SearchRow compare) throws SQLException {
for (int i = 0; i < columns.length; i++) {
int index = columnIndex[i];
Value v = compare.getValue(index);
if(v==null) {
// can't compare further
return 0;
}
int c = compareValues(rowData.getValue(index), v);
if (c != 0) {
return c;
}
}
return 0;
}
public boolean isNull(Row newRow) {
for (int i = 0; i < columns.length; i++) {
int index = columnIndex[i];
Value v = newRow.getValue(index);
if(v == ValueNull.INSTANCE) {
return true;
}
}
return false;
}
public int compareKeys(SearchRow rowData, SearchRow compare) {
int k1 = rowData.getPos();
int k2 = compare.getPos();
if (k1 == k2) {
return 0;
}
return k1 > k2 ? 1 : -1;
}
private int compareValues(Value v1, Value v2) throws SQLException {
if (v1 == null) {
if (v2 == null) {
return 0;
}
return 1;
}
if (v2 == null) {
return -1;
}
return database.compareTypeSave(v1, v2);
}
public int getColumnIndex(Column col) {
for (int i = 0; i < columns.length; i++) {
if (columns[i] == col) {
return i;
}
}
return -1;
}
public String getColumnListSQL() {
StringBuffer buff = new StringBuffer();
for (int i = 0; i < columns.length; i++) {
if (i > 0) {
buff.append(", ");
}
buff.append(columns[i].getSQL());
}
return buff.toString();
}
public String getCreateSQLForCopy(Table table, String quotedName) {
StringBuffer buff = new StringBuffer();
buff.append("CREATE ");
buff.append(indexType.getSQL());
if(!indexType.isPrimaryKey()) {
buff.append(' ');
buff.append(quotedName);
}
buff.append(" ON ");
buff.append(table.getSQL());
if(comment != null) {
buff.append(" COMMENT ");
buff.append(StringUtils.quoteStringSQL(comment));
}
buff.append("(");
buff.append(getColumnListSQL());
buff.append(")");
return buff.toString();
}
public String getCreateSQL() {
return getCreateSQLForCopy(table, getSQL());
}
public Column[] getColumns() {
return columns;
}
public IndexType getIndexType() {
return indexType;
}
public int getType() {
return DbObject.INDEX;
}
public Table getTable() {
return table;
}
public void commit(Row row) throws SQLException {
}
}
......@@ -87,17 +87,6 @@ public class BtreeCursor implements Cursor {
}
}
}
if(SysProperties.MVCC) {
if(currentSearchRow != null) {
while(true) {
Row r = get();
int sessionId = r.getSessionId();
if(sessionId == 0 || sessionId == session.getId()) {
break;
}
}
}
}
return currentSearchRow != null;
}
......
......@@ -26,7 +26,7 @@ import org.h2.value.ValueNull;
/**
* @author Thomas
*/
public class BtreeIndex extends Index implements RecordReader {
public class BtreeIndex extends BaseIndex implements RecordReader {
// TODO index / btree: tune page size
// final static int MAX_PAGE_SIZE = 256;
......@@ -164,17 +164,12 @@ public class BtreeIndex extends Index implements RecordReader {
public void remove(Session session, Row row) throws SQLException {
setChanged(session);
if(SysProperties.MVCC) {
if(rowCount == 1) {
// TODO performance: maybe improve truncate performance in this case
truncate(session);
} else {
root.remove(session, row, 0);
rowCount--;
} else {
if(rowCount == 1) {
// TODO performance: maybe improve truncate performance in this case
truncate(session);
} else {
root.remove(session, row, 0);
rowCount--;
}
}
}
......@@ -188,7 +183,7 @@ public class BtreeIndex extends Index implements RecordReader {
return cursor;
} else {
BtreeCursor cursor = new BtreeCursor(session, this, last);
if (!root.findFirst(cursor, first)) {
if (getRowCount(session)==0 || !root.findFirst(cursor, first)) {
cursor.setCurrentRow(null);
}
return cursor;
......@@ -290,24 +285,20 @@ public class BtreeIndex extends Index implements RecordReader {
return true;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
if(first) {
// TODO optimization: this loops through NULL values
// TODO optimization: this loops through NULL elements
Cursor cursor = find(session, null, null);
while(cursor.next()) {
Value v = cursor.get().getValue(columnIndex[0]);
SearchRow row = cursor.getSearchRow();
Value v = row.getValue(columnIndex[0]);
if(v != ValueNull.INSTANCE) {
return v;
return row;
}
}
return ValueNull.INSTANCE;
return null;
} else {
SearchRow row = root.getLast(session);
if(row != null) {
Value v = row.getValue(columnIndex[0]);
return v;
}
return ValueNull.INSTANCE;
return root.getLast(session);
}
}
......
......@@ -60,18 +60,7 @@ public class BtreeLeaf extends BtreePage {
if (comp == 0) {
if(index.indexType.isUnique()) {
if(!index.isNull(newRow)) {
if(SysProperties.MVCC) {
int todoMVCC;
// currently, throw a duplicate row exception even if another transaction
// updated or deleted the same row and did not yet commit - PostgreSQL waits but in most cases transactions are committed
if(row.getDeleted() && row.getSessionId() == session.getId()) {
// ignore: deleted
} else {
throw index.getDuplicateKeyException();
}
} else {
throw index.getDuplicateKeyException();
}
throw index.getDuplicateKeyException();
}
}
comp = index.compareKeys(row, newRow);
......@@ -262,9 +251,7 @@ public class BtreeLeaf extends BtreePage {
int size = 2 + dummy.getIntLen() * (len+1);
for (int i = 0; i < len; i++) {
SearchRow row = (SearchRow) pageData.get(i);
if(!row.getDeleted()) {
size += getRowSize(dummy, row);
}
size += getRowSize(dummy, row);
}
size += index.getRecordOverhead();
cachedRealByteCount = size;
......
......@@ -60,7 +60,6 @@ public class BtreeNode extends BtreePage {
SearchRow r = (SearchRow) pageData.get(i);
if(r == null) {
int p = pageChildren.get(i+1);
// MVCC: get the committed data
Session session = index.getDatabase().getSystemSession();
BtreePage page = index.getPage(session, p);
r = page.getFirst(session);
......
......@@ -5,7 +5,6 @@
package org.h2.index;
import java.sql.SQLException;
import org.h2.engine.Session;
import org.h2.expression.FunctionCall;
import org.h2.message.Message;
......@@ -14,9 +13,8 @@ import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.Column;
import org.h2.table.FunctionTable;
import org.h2.value.Value;
public class FunctionIndex extends Index {
public class FunctionIndex extends BaseIndex {
private FunctionTable functionTable;
private LocalResult result;
......@@ -73,7 +71,7 @@ public class FunctionIndex extends Index {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
throw Message.getUnsupportedException();
}
......
......@@ -21,7 +21,7 @@ import org.h2.value.ValueArray;
/**
* @author Thomas
*/
public class HashIndex extends Index {
public class HashIndex extends BaseIndex {
private ValueHashMap rows;
private IntIntHashMap intMap;
......@@ -145,7 +145,7 @@ public class HashIndex extends Index {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
throw Message.getUnsupportedException();
}
......
......@@ -27,7 +27,7 @@ import org.h2.value.ValueArray;
/**
* @author Thomas
*/
public class LinearHashIndex extends Index implements RecordReader {
public class LinearHashIndex extends BaseIndex implements RecordReader {
// TODO index / linear hash: tune page size
// private static final int MAX_PAGE_SIZE = 256;
......@@ -535,7 +535,7 @@ public class LinearHashIndex extends Index implements RecordReader {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
throw Message.getUnsupportedException();
}
......
......@@ -23,7 +23,7 @@ import org.h2.value.ValueNull;
* @author Thomas
*/
public class LinkedIndex extends Index {
public class LinkedIndex extends BaseIndex {
private TableLink link;
private String originalTable;
......@@ -161,7 +161,7 @@ public class LinkedIndex extends Index {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
// TODO optimization: could get the first or last value (in any case; maybe not optimized)
throw Message.getUnsupportedException();
}
......
......@@ -5,7 +5,6 @@
package org.h2.index;
import java.sql.SQLException;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.Row;
......@@ -13,14 +12,13 @@ import org.h2.result.SearchRow;
import org.h2.table.Column;
import org.h2.table.MetaTable;
import org.h2.util.ObjectArray;
import org.h2.value.Value;
/**
* @author Thomas
*/
public class MetaIndex extends Index {
public class MetaIndex extends BaseIndex {
private MetaTable meta;
private boolean scan;
......@@ -87,7 +85,7 @@ public class MetaIndex extends Index {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
throw Message.getUnsupportedException();
}
......
package org.h2.index;
import java.sql.SQLException;
import org.h2.engine.Session;
import org.h2.result.Row;
import org.h2.result.SearchRow;
public class MultiVersionCursor implements Cursor {
private final MultiVersionIndex index;
private final Session session;
private final Cursor base, delta;
private boolean onBase;
private SearchRow current;
MultiVersionCursor(Session session, MultiVersionIndex index, Cursor base, Cursor delta) throws SQLException {
this.session = session;
this.index = index;
this.base = base;
this.delta = delta;
boolean b = base.next();
boolean d = delta.next();
}
public Row get() throws SQLException {
return onBase ? base.get() : delta.get();
}
public int getPos() {
return onBase ? base.getPos() : delta.getPos();
}
public SearchRow getSearchRow() throws SQLException {
return onBase ? base.getSearchRow() : delta.getSearchRow();
}
public boolean next() throws SQLException {
return false;
}
}
package org.h2.index;
import java.sql.SQLException;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.schema.Schema;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.table.TableData;
import org.h2.util.ObjectArray;
public class MultiVersionIndex implements Index {
private Index base;
private TreeIndex delta;
public MultiVersionIndex(Index base, TableData table) throws SQLException {
this.base = base;
IndexType deltaIndexType = IndexType.createNonUnique(false);
this.delta = new TreeIndex(table, -1, "DELTA" ,base.getColumns(), deltaIndexType);
}
public void add(Session session, Row row) throws SQLException {
base.add(session, row);
delta.add(session, row);
}
public void close(Session session) throws SQLException {
base.close(session);
}
public Cursor find(Session session, SearchRow first, SearchRow last) throws SQLException {
Cursor baseCursor = base.find(session, first, last);
Cursor deltaCursor = delta.find(session, first, last);
return new MultiVersionCursor(session, this, baseCursor, deltaCursor);
}
public boolean canGetFirstOrLast(boolean first) {
int todoMVCC_Min_Max_Optimization;
return false;
}
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
int todoMVCC_Min_Max_Optimization;
throw Message.getUnsupportedException();
}
public double getCost(Session session, int[] masks) throws SQLException {
return base.getCost(session, masks);
}
public boolean needRebuild() {
return base.needRebuild();
}
public void remove(Session session, Row row) throws SQLException {
base.remove(session, row);
delta.add(session, row);
}
public void remove(Session session) throws SQLException {
base.remove(session);
}
public void truncate(Session session) throws SQLException {
int todoLockingRequired;
base.truncate(session);
}
public void commit(Row row) throws SQLException {
delta.remove(null, row);
}
public int compareKeys(SearchRow rowData, SearchRow compare) {
return base.compareKeys(rowData, compare);
}
public int compareRows(SearchRow rowData, SearchRow compare) throws SQLException {
return base.compareRows(rowData, compare);
}
public int getColumnIndex(Column col) {
return base.getColumnIndex(col);
}
public String getColumnListSQL() {
return base.getColumnListSQL();
}
public Column[] getColumns() {
return base.getColumns();
}
public long getCostRangeIndex(int[] masks, long rowCount) throws SQLException {
return base.getCostRangeIndex(masks, rowCount);
}
public String getCreateSQL() {
return base.getCreateSQL();
}
public String getCreateSQLForCopy(Table table, String quotedName) {
return base.getCreateSQLForCopy(table, quotedName);
}
public String getDropSQL() {
return base.getDropSQL();
}
public SQLException getDuplicateKeyException() {
return base.getDuplicateKeyException();
}
public IndexType getIndexType() {
return base.getIndexType();
}
public int getLookupCost(long rowCount) {
return base.getLookupCost(rowCount);
}
public String getPlanSQL() {
return base.getPlanSQL();
}
public long getRowCount(Session session) {
return base.getRowCount(session);
}
public Table getTable() {
return base.getTable();
}
public int getType() {
return base.getType();
}
public boolean isNull(Row newRow) {
return base.isNull(newRow);
}
public void removeChildrenAndResources(Session session) throws SQLException {
base.removeChildrenAndResources(session);
}
public String getSQL() {
return base.getSQL();
}
public Schema getSchema() {
return base.getSchema();
}
public void checkRename() throws SQLException {
base.checkRename();
}
public ObjectArray getChildren() {
return base.getChildren();
}
public String getComment() {
return base.getComment();
}
public Database getDatabase() {
return base.getDatabase();
}
public int getHeadPos() {
return base.getHeadPos();
}
public int getId() {
return base.getId();
}
public long getModificationId() {
return base.getModificationId();
}
public String getName() {
return base.getName();
}
public boolean getTemporary() {
return base.getTemporary();
}
public void rename(String newName) throws SQLException {
base.rename(newName);
}
public void setComment(String comment) {
base.setComment(comment);
}
public void setModified() {
base.setModified();
}
public void setTemporary(boolean temporary) {
base.setTemporary(temporary);
}
}
......@@ -15,7 +15,7 @@ import org.h2.table.RangeTable;
import org.h2.value.Value;
import org.h2.value.ValueLong;
public class RangeIndex extends Index {
public class RangeIndex extends BaseIndex {
private long min, max;
......@@ -70,8 +70,8 @@ public class RangeIndex extends Index {
return true;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
return ValueLong.get(first ? min : max);
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
return new Row(new Value[]{ValueLong.get(first ? min : max)}, 0);
}
}
......@@ -23,7 +23,7 @@ import org.h2.value.ValueLob;
/**
* @author Thomas
*/
public class ScanIndex extends Index {
public class ScanIndex extends BaseIndex {
private int firstFree = -1;
private ObjectArray rows = new ObjectArray();
private Storage storage;
......@@ -193,7 +193,7 @@ public class ScanIndex extends Index {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
throw Message.getUnsupportedException();
}
......
......@@ -17,7 +17,7 @@ import org.h2.value.Value;
import org.h2.value.ValueNull;
public class TreeIndex extends Index {
public class TreeIndex extends BaseIndex {
private TreeNode root;
private TableData tableData;
......@@ -340,17 +340,18 @@ public class TreeIndex extends Index {
return true;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
if(first) {
// TODO optimization: this loops through NULL values
Cursor cursor = find(session, null, null);
while(cursor.next()) {
Value v = cursor.get().getValue(columnIndex[0]);
SearchRow row = cursor.getSearchRow();
Value v = row.getValue(columnIndex[0]);
if(v != ValueNull.INSTANCE) {
return v;
return row;
}
}
return ValueNull.INSTANCE;
return null;
} else {
TreeNode x = root, n;
while (x != null) {
......@@ -361,10 +362,9 @@ public class TreeIndex extends Index {
x = n;
}
if(x != null) {
Value v = x.row.getValue(columnIndex[0]);
return v;
return x.row;
}
return ValueNull.INSTANCE;
return null;
}
}
......
......@@ -5,7 +5,6 @@
package org.h2.index;
import java.sql.SQLException;
import org.h2.command.dml.Query;
import org.h2.engine.Constants;
import org.h2.engine.Session;
......@@ -18,11 +17,11 @@ import org.h2.result.SearchRow;
import org.h2.table.Column;
import org.h2.table.TableView;
import org.h2.util.IntArray;
import org.h2.util.SmallLRUCache;
import org.h2.util.ObjectArray;
import org.h2.util.SmallLRUCache;
import org.h2.value.Value;
public class ViewIndex extends Index {
public class ViewIndex extends BaseIndex {
private String querySQL;
private ObjectArray originalParameters;
......@@ -232,7 +231,7 @@ public class ViewIndex extends Index {
return false;
}
public Value findFirstOrLast(Session session, boolean first) throws SQLException {
public SearchRow findFirstOrLast(Session session, boolean first) throws SQLException {
throw Message.getUnsupportedException();
}
......
......@@ -315,7 +315,7 @@ The selectivity can be set manually with ALTER TABLE ALTER COLUMN SELECTIVITY.
The manual values are overwritten by this statement.
The selectivity is available in the INFORMATION_SCHEMA.COLUMNS table.
","
ANALYZE TOP 1000
ANALYZE SAMPLE_SIZE 1000
"
"Commands (DDL)","COMMENT","
......
......@@ -4,7 +4,6 @@
*/
package org.h2.result;
import org.h2.engine.Session;
import org.h2.value.Value;
public interface SearchRow {
......@@ -14,8 +13,5 @@ public interface SearchRow {
int getColumnCount();
void setValue(int idx, Value v);
void setPos(int pos);
void setDeleted(Session session, boolean deleted);
int getSessionId();
boolean getDeleted();
}
......@@ -4,15 +4,12 @@
*/
package org.h2.result;
import org.h2.engine.Session;
import org.h2.value.Value;
public class SimpleRow implements SearchRow {
private int pos;
private Value[] data;
private int sessionId;
private boolean deleted;
public SimpleRow(Value[] data) {
this.data = data;
......@@ -38,18 +35,4 @@ public class SimpleRow implements SearchRow {
return data[i];
}
public boolean getDeleted() {
return deleted;
}
public void setDeleted(Session session, boolean deleted) {
this.sessionId = session.getId();
this.deleted = deleted;
}
public int getSessionId() {
int testing;
return sessionId;
}
}
......@@ -4,7 +4,6 @@
*/
package org.h2.result;
import org.h2.engine.Session;
import org.h2.value.Value;
public class SimpleRowValue implements SearchRow {
......@@ -13,8 +12,6 @@ public class SimpleRowValue implements SearchRow {
private int index;
private int virtualColumnCount;
private Value data;
private int sessionId;
private boolean deleted;
public SimpleRowValue(int columnCount) {
this.virtualColumnCount = columnCount;
......@@ -37,19 +34,5 @@ public class SimpleRowValue implements SearchRow {
index = idx;
data = v;
}
public boolean getDeleted() {
return deleted;
}
public void setDeleted(Session session, boolean deleted) {
this.sessionId = session.getId();
this.deleted = deleted;
}
public int getSessionId() {
int testing;
return sessionId;
}
}
......@@ -14,7 +14,7 @@ import org.h2.message.Trace;
import org.h2.table.Table;
import org.h2.value.Value;
public class Constant extends SchemaObject {
public class Constant extends SchemaObjectBase {
private Value value;
private ValueExpression expression;
......
......@@ -13,8 +13,10 @@ import org.h2.constraint.Constraint;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.DbObjectBase;
import org.h2.engine.Session;
import org.h2.engine.User;
import org.h2.index.BaseIndex;
import org.h2.index.Index;
import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message;
......@@ -24,7 +26,7 @@ import org.h2.table.TableData;
import org.h2.table.TableLink;
import org.h2.util.ObjectArray;
public class Schema extends DbObject {
public class Schema extends DbObjectBase {
private User owner;
private boolean system;
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.schema;
import org.h2.engine.DbObjectBase;
public abstract class SchemaObjectBase extends DbObjectBase implements SchemaObject {
private Schema schema;
protected SchemaObjectBase(Schema schema, int id, String name, String traceModule) {
super(schema.getDatabase(), id, name, traceModule);
this.schema = schema;
}
public Schema getSchema() {
return schema;
}
public String getSQL() {
return schema.getSQL() + "." + super.getSQL();
}
}
......@@ -14,7 +14,7 @@ import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.table.Table;
public class Sequence extends SchemaObject {
public class Sequence extends SchemaObjectBase {
private static final int BLOCK_INCREMENT = 32;
private long value = 1;
private long valueWithMargin;
......
......@@ -23,7 +23,7 @@ import org.h2.value.Value;
* @author Thomas
*/
public class TriggerObject extends SchemaObject {
public class TriggerObject extends SchemaObjectBase {
public static final int INSERT=1, UPDATE=2, DELETE=4;
public static final int DEFAULT_QUEUE_SIZE = 1024;
......
......@@ -15,6 +15,7 @@ import org.h2.index.Index;
import org.h2.message.Message;
import org.h2.result.Row;
import org.h2.table.Table;
import org.h2.util.ObjectArray;
import org.h2.value.Value;
/**
......@@ -141,7 +142,12 @@ public class UndoLogRecord {
return table;
}
public void commit() {
public void commit() throws SQLException {
ObjectArray list = table.getIndexes();
for(int i=0; i<list.size(); i++) {
Index index = (Index) list.get(i);
index.commit(row);
}
row.commit();
}
}
......@@ -7,7 +7,6 @@ package org.h2.table;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Session;
import org.h2.expression.Expression;
......
......@@ -14,7 +14,6 @@ import java.sql.SQLException;
import java.text.Collator;
import java.util.Locale;
import java.util.Properties;
import org.h2.constant.SysProperties;
import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck;
......
......@@ -5,7 +5,6 @@
package org.h2.table;
import java.sql.SQLException;
import org.h2.engine.Session;
import org.h2.index.Index;
import org.h2.index.IndexType;
......
......@@ -6,7 +6,6 @@ package org.h2.table;
import java.sql.SQLException;
import java.util.HashMap;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint;
......@@ -23,7 +22,7 @@ import org.h2.result.SearchRow;
import org.h2.result.SimpleRow;
import org.h2.result.SimpleRowValue;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.SchemaObjectBase;
import org.h2.schema.Sequence;
import org.h2.schema.TriggerObject;
import org.h2.store.UndoLogRecord;
......@@ -36,7 +35,7 @@ import org.h2.value.ValueNull;
* @author Thomas
*/
public abstract class Table extends SchemaObject {
public abstract class Table extends SchemaObjectBase {
public static final int TYPE_CACHED = 0, TYPE_MEMORY = 1;
......@@ -317,7 +316,7 @@ public abstract class Table extends SchemaObject {
ObjectArray indexes = getIndexes();
if(indexes != null) {
remove(indexes, index);
if(index.indexType.isPrimaryKey()) {
if(index.getIndexType().isPrimaryKey()) {
Column[] cols = index.getColumns();
for(int i=0; i<cols.length; i++) {
cols[i].setPrimaryKey(false);
......
......@@ -7,7 +7,6 @@ package org.h2.table;
import java.sql.SQLException;
import java.util.Comparator;
import java.util.HashSet;
import org.h2.api.DatabaseEventListener;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
......@@ -22,6 +21,7 @@ import org.h2.index.HashIndex;
import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.index.LinearHashIndex;
import org.h2.index.MultiVersionIndex;
import org.h2.index.ScanIndex;
import org.h2.index.TreeIndex;
import org.h2.message.Message;
......@@ -83,7 +83,7 @@ public class TableData extends Table implements RecordReader {
Index index = (Index) indexes.get(i);
index.add(session, row);
if(SysProperties.CHECK) {
long rc = index.getRowCount();
long rc = index.getRowCount(session);
if(rc != rowCount+1) {
throw Message.getInternalError("rowCount expected "+(rowCount+1)+" got "+rc);
}
......@@ -96,7 +96,7 @@ public class TableData extends Table implements RecordReader {
Index index = (Index) indexes.get(i);
index.remove(session, row);
if(SysProperties.CHECK) {
long rc = index.getRowCount();
long rc = index.getRowCount(session);
if(rc != rowCount) {
throw Message.getInternalError("rowCount expected "+(rowCount)+" got "+rc);
}
......@@ -156,10 +156,13 @@ public class TableData extends Table implements RecordReader {
index = new TreeIndex(this, indexId, indexName, cols, indexType);
}
}
if(SysProperties.MVCC) {
index = new MultiVersionIndex(index, this);
}
if(index.needRebuild() && rowCount > 0) {
try {
Index scan = getScanIndex(session);
long remaining = scan.getRowCount();
long remaining = scan.getRowCount(session);
long total = remaining;
Cursor cursor = scan.find(session, null, null);
long i = 0;
......@@ -253,7 +256,7 @@ public class TableData extends Table implements RecordReader {
Index index = (Index) indexes.get(i);
index.remove(session, row);
if(SysProperties.CHECK) {
long rc = index.getRowCount();
long rc = index.getRowCount(session);
if(rc != rowCount-1) {
throw Message.getInternalError("rowCount expected "+(rowCount-1)+" got "+rc);
}
......@@ -268,7 +271,7 @@ public class TableData extends Table implements RecordReader {
Index index = (Index) indexes.get(i);
index.truncate(session);
if(SysProperties.CHECK) {
long rc = index.getRowCount();
long rc = index.getRowCount(session);
if(rc != 0) {
throw Message.getInternalError("rowCount expected 0 got "+rc);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论