use of org.h2.index.Index in project h2database by h2database.
the class BaseIndex method initBaseIndex.
/**
* Initialize the base index.
*
* @param newTable the table
* @param id the object id
* @param name the index name
* @param newIndexColumns the columns that are indexed or null if this is
* not yet known
* @param newIndexType the index type
*/
protected void initBaseIndex(Table newTable, int id, String name, IndexColumn[] newIndexColumns, IndexType newIndexType) {
initSchemaObjectBase(newTable.getSchema(), id, name, Trace.INDEX);
this.indexType = newIndexType;
this.table = newTable;
if (newIndexColumns != null) {
this.indexColumns = newIndexColumns;
columns = new Column[newIndexColumns.length];
int len = columns.length;
columnIds = new int[len];
for (int i = 0; i < len; i++) {
Column col = newIndexColumns[i].column;
columns[i] = col;
columnIds[i] = col.getColumnId();
}
}
}
use of org.h2.index.Index in project h2database by h2database.
the class BaseIndex method compareRows.
@Override
public int compareRows(SearchRow rowData, SearchRow compare) {
if (rowData == compare) {
return 0;
}
for (int i = 0, len = indexColumns.length; i < len; i++) {
int index = columnIds[i];
Value v1 = rowData.getValue(index);
Value v2 = compare.getValue(index);
if (v1 == null || v2 == null) {
// can't compare further
return 0;
}
int c = compareValues(v1, v2, indexColumns[i].sortType);
if (c != 0) {
return c;
}
}
return 0;
}
use of org.h2.index.Index in project h2database by h2database.
the class HashIndex method add.
@Override
public void add(Session session, Row row) {
Value key = row.getValue(indexColumn);
Object old = rows.get(key);
if (old != null) {
// TODO index duplicate key for hash indexes: is this allowed?
throw getDuplicateKeyException(key.toString());
}
rows.put(key, row.getKey());
}
use of org.h2.index.Index in project h2database by h2database.
the class HashIndex method getCost.
@Override
public double getCost(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) {
for (Column column : columns) {
int index = column.getColumnId();
int mask = masks[index];
if ((mask & IndexCondition.EQUALITY) != IndexCondition.EQUALITY) {
return Long.MAX_VALUE;
}
}
return 2;
}
use of org.h2.index.Index in project h2database by h2database.
the class HashIndex method find.
@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
if (first == null || last == null) {
// TODO hash index: should additionally check if values are the same
throw DbException.throwInternalError(first + " " + last);
}
Value v = first.getValue(indexColumn);
/*
* Sometimes the incoming search is a similar, but not the same type
* e.g. the search value is INT, but the index column is LONG. In which
* case we need to convert, otherwise the ValueHashMap will not find the
* result.
*/
v = v.convertTo(tableData.getColumn(indexColumn).getType());
Row result;
Long pos = rows.get(v);
if (pos == null) {
result = null;
} else {
result = tableData.getRow(session, pos.intValue());
}
return new SingleRowCursor(result);
}
Aggregations