Search in sources :

Example 56 with Index

use of org.h2.index.Index in project h2database by h2database.

the class Aggregate method initOrder.

private SortOrder initOrder(Session session) {
    int size = orderByList.size();
    int[] index = new int[size];
    int[] sortType = new int[size];
    for (int i = 0; i < size; i++) {
        SelectOrderBy o = orderByList.get(i);
        index[i] = i + 1;
        int order = o.descending ? SortOrder.DESCENDING : SortOrder.ASCENDING;
        sortType[i] = order;
    }
    return new SortOrder(session.getDatabase(), index, sortType, null);
}
Also used : SelectOrderBy(org.h2.command.dml.SelectOrderBy) SortOrder(org.h2.result.SortOrder)

Example 57 with Index

use of org.h2.index.Index in project h2database by h2database.

the class NonUniqueHashIndex method find.

@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
    if (first == null || last == null) {
        throw DbException.throwInternalError(first + " " + last);
    }
    if (first != last) {
        if (compareKeys(first, last) != 0) {
            throw DbException.throwInternalError();
        }
    }
    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());
    ArrayList<Long> positions = rows.get(v);
    return new NonUniqueHashCursor(session, tableData, positions);
}
Also used : Value(org.h2.value.Value)

Example 58 with Index

use of org.h2.index.Index in project h2database by h2database.

the class LobStorageBackend method init.

@Override
public void init() {
    if (init) {
        return;
    }
    synchronized (database) {
        // thread
        if (init) {
            return;
        }
        init = true;
        conn = database.getLobConnectionForRegularUse();
        JdbcConnection initConn = database.getLobConnectionForInit();
        try {
            Statement stat = initConn.createStatement();
            // stat.execute("SET UNDO_LOG 0");
            // stat.execute("SET REDO_LOG_BINARY 0");
            boolean create = true;
            PreparedStatement prep = initConn.prepareStatement("SELECT ZERO() FROM INFORMATION_SCHEMA.COLUMNS WHERE " + "TABLE_SCHEMA=? AND TABLE_NAME=? AND COLUMN_NAME=?");
            prep.setString(1, "INFORMATION_SCHEMA");
            prep.setString(2, "LOB_MAP");
            prep.setString(3, "POS");
            ResultSet rs;
            rs = prep.executeQuery();
            if (rs.next()) {
                prep = initConn.prepareStatement("SELECT ZERO() FROM INFORMATION_SCHEMA.TABLES WHERE " + "TABLE_SCHEMA=? AND TABLE_NAME=?");
                prep.setString(1, "INFORMATION_SCHEMA");
                prep.setString(2, "LOB_DATA");
                rs = prep.executeQuery();
                if (rs.next()) {
                    create = false;
                }
            }
            if (create) {
                stat.execute("CREATE CACHED TABLE IF NOT EXISTS " + LOBS + "(ID BIGINT PRIMARY KEY, BYTE_COUNT BIGINT, TABLE INT) HIDDEN");
                stat.execute("CREATE INDEX IF NOT EXISTS " + "INFORMATION_SCHEMA.INDEX_LOB_TABLE ON " + LOBS + "(TABLE)");
                stat.execute("CREATE CACHED TABLE IF NOT EXISTS " + LOB_MAP + "(LOB BIGINT, SEQ INT, POS BIGINT, HASH INT, " + "BLOCK BIGINT, PRIMARY KEY(LOB, SEQ)) HIDDEN");
                stat.execute("ALTER TABLE " + LOB_MAP + " RENAME TO " + LOB_MAP + " HIDDEN");
                stat.execute("ALTER TABLE " + LOB_MAP + " ADD IF NOT EXISTS POS BIGINT BEFORE HASH");
                // TODO the column name OFFSET was used in version 1.3.156,
                // so this can be remove in a later version
                stat.execute("ALTER TABLE " + LOB_MAP + " DROP COLUMN IF EXISTS \"OFFSET\"");
                stat.execute("CREATE INDEX IF NOT EXISTS " + "INFORMATION_SCHEMA.INDEX_LOB_MAP_DATA_LOB ON " + LOB_MAP + "(BLOCK, LOB)");
                stat.execute("CREATE CACHED TABLE IF NOT EXISTS " + LOB_DATA + "(BLOCK BIGINT PRIMARY KEY, COMPRESSED INT, DATA BINARY) HIDDEN");
            }
            rs = stat.executeQuery("SELECT MAX(BLOCK) FROM " + LOB_DATA);
            rs.next();
            nextBlock = rs.getLong(1) + 1;
            stat.close();
        } catch (SQLException e) {
            throw DbException.convert(e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) JdbcConnection(org.h2.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement)

Example 59 with Index

use of org.h2.index.Index in project h2database by h2database.

the class PageStore method redoDelete.

/**
 * Redo a delete in a table.
 *
 * @param tableId the object id of the table
 * @param key the key of the row to delete
 */
void redoDelete(int tableId, long key) {
    Index index = metaObjects.get(tableId);
    PageDataIndex scan = (PageDataIndex) index;
    Row row = scan.getRowWithKey(key);
    if (row == null || row.getKey() != key) {
        trace.error(null, "Entry not found: " + key + " found instead: " + row + " - ignoring");
        return;
    }
    redo(tableId, row, false);
}
Also used : PageDataIndex(org.h2.index.PageDataIndex) Index(org.h2.index.Index) PageIndex(org.h2.index.PageIndex) PageDelegateIndex(org.h2.index.PageDelegateIndex) MultiVersionIndex(org.h2.index.MultiVersionIndex) PageBtreeIndex(org.h2.index.PageBtreeIndex) PageDataIndex(org.h2.index.PageDataIndex) Row(org.h2.result.Row)

Example 60 with Index

use of org.h2.index.Index in project h2database by h2database.

the class PageStore method redoTruncate.

/**
 * Redo a truncate.
 *
 * @param tableId the object id of the table
 */
void redoTruncate(int tableId) {
    Index index = metaObjects.get(tableId);
    Table table = index.getTable();
    table.truncate(pageStoreSession);
}
Also used : RegularTable(org.h2.table.RegularTable) Table(org.h2.table.Table) Index(org.h2.index.Index) PageIndex(org.h2.index.PageIndex) PageDelegateIndex(org.h2.index.PageDelegateIndex) MultiVersionIndex(org.h2.index.MultiVersionIndex) PageBtreeIndex(org.h2.index.PageBtreeIndex) PageDataIndex(org.h2.index.PageDataIndex)

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