Search in sources :

Example 46 with Index

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();
        }
    }
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn)

Example 47 with Index

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;
}
Also used : Value(org.h2.value.Value)

Example 48 with Index

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());
}
Also used : Value(org.h2.value.Value)

Example 49 with Index

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;
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn)

Example 50 with Index

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);
}
Also used : Value(org.h2.value.Value) Row(org.h2.result.Row) SearchRow(org.h2.result.SearchRow)

Aggregations

ResultSet (java.sql.ResultSet)77 Index (org.h2.index.Index)75 Statement (java.sql.Statement)64 SimpleResultSet (org.h2.tools.SimpleResultSet)61 SQLException (java.sql.SQLException)60 Value (org.h2.value.Value)58 DbException (org.h2.message.DbException)57 Connection (java.sql.Connection)56 PreparedStatement (java.sql.PreparedStatement)56 Column (org.h2.table.Column)53 IndexColumn (org.h2.table.IndexColumn)45 ArrayList (java.util.ArrayList)31 ValueString (org.h2.value.ValueString)29 Constraint (org.h2.constraint.Constraint)25 Row (org.h2.result.Row)22 MultiVersionIndex (org.h2.index.MultiVersionIndex)19 JdbcConnection (org.h2.jdbc.JdbcConnection)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 Table (org.h2.table.Table)18 HashSet (java.util.HashSet)17