Search in sources :

Example 46 with Cursor

use of org.h2.mvstore.Cursor in project h2database by h2database.

the class MultiVersionIndex method findFirstOrLast.

@Override
public Cursor findFirstOrLast(Session session, boolean first) {
    if (first) {
        // TODO optimization: this loops through NULL elements
        Cursor cursor = find(session, null, null);
        while (cursor.next()) {
            SearchRow row = cursor.getSearchRow();
            Value v = row.getValue(firstColumn.getColumnId());
            if (v != ValueNull.INSTANCE) {
                return cursor;
            }
        }
        return cursor;
    }
    Cursor baseCursor = base.findFirstOrLast(session, false);
    Cursor deltaCursor = delta.findFirstOrLast(session, false);
    MultiVersionCursor cursor = new MultiVersionCursor(session, this, baseCursor, deltaCursor, sync);
    cursor.loadCurrent();
    // TODO optimization: this loops through NULL elements
    while (cursor.previous()) {
        SearchRow row = cursor.getSearchRow();
        if (row == null) {
            break;
        }
        Value v = row.getValue(firstColumn.getColumnId());
        if (v != ValueNull.INSTANCE) {
            return cursor;
        }
    }
    return cursor;
}
Also used : Value(org.h2.value.Value) SearchRow(org.h2.result.SearchRow)

Example 47 with Cursor

use of org.h2.mvstore.Cursor in project h2database by h2database.

the class MVSecondaryIndex method findFirstOrLast.

@Override
public Cursor findFirstOrLast(Session session, boolean first) {
    TransactionMap<Value, Value> map = getMap(session);
    Value key = first ? map.firstKey() : map.lastKey();
    while (true) {
        if (key == null) {
            return new MVStoreCursor(session, Collections.<Value>emptyList().iterator(), null);
        }
        if (((ValueArray) key).getList()[0] != ValueNull.INSTANCE) {
            break;
        }
        key = first ? map.higherKey(key) : map.lowerKey(key);
    }
    ArrayList<Value> list = New.arrayList();
    list.add(key);
    MVStoreCursor cursor = new MVStoreCursor(session, list.iterator(), null);
    cursor.next();
    return cursor;
}
Also used : Value(org.h2.value.Value) ValueArray(org.h2.value.ValueArray)

Example 48 with Cursor

use of org.h2.mvstore.Cursor in project h2database by h2database.

the class MVDelegateIndex method find.

@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
    ValueLong min = mainIndex.getKey(first, ValueLong.MIN, ValueLong.MIN);
    // ifNull is MIN as well, because the column is never NULL
    // so avoid returning all rows (returning one row is OK)
    ValueLong max = mainIndex.getKey(last, ValueLong.MAX, ValueLong.MIN);
    return mainIndex.find(session, min, max);
}
Also used : ValueLong(org.h2.value.ValueLong)

Example 49 with Cursor

use of org.h2.mvstore.Cursor in project h2database by h2database.

the class MVPrimaryIndex method findFirstOrLast.

@Override
public Cursor findFirstOrLast(Session session, boolean first) {
    TransactionMap<Value, Value> map = getMap(session);
    ValueLong v = (ValueLong) (first ? map.firstKey() : map.lastKey());
    if (v == null) {
        return new MVStoreCursor(session, Collections.<Entry<Value, Value>>emptyList().iterator());
    }
    Value value = map.get(v);
    Entry<Value, Value> e = new DataUtils.MapEntry<Value, Value>(v, value);
    List<Entry<Value, Value>> list = Collections.singletonList(e);
    MVStoreCursor c = new MVStoreCursor(session, list.iterator());
    c.next();
    return c;
}
Also used : Entry(java.util.Map.Entry) ValueLong(org.h2.value.ValueLong) Value(org.h2.value.Value)

Example 50 with Cursor

use of org.h2.mvstore.Cursor in project h2database by h2database.

the class MVPrimaryIndex method find.

@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
    ValueLong min, max;
    if (first == null) {
        min = ValueLong.MIN;
    } else if (mainIndexColumn < 0) {
        min = ValueLong.get(first.getKey());
    } else {
        ValueLong v = (ValueLong) first.getValue(mainIndexColumn);
        if (v == null) {
            min = ValueLong.get(first.getKey());
        } else {
            min = v;
        }
    }
    if (last == null) {
        max = ValueLong.MAX;
    } else if (mainIndexColumn < 0) {
        max = ValueLong.get(last.getKey());
    } else {
        ValueLong v = (ValueLong) last.getValue(mainIndexColumn);
        if (v == null) {
            max = ValueLong.get(last.getKey());
        } else {
            max = v;
        }
    }
    TransactionMap<Value, Value> map = getMap(session);
    return new MVStoreCursor(session, map.entryIterator(min, max));
}
Also used : ValueLong(org.h2.value.ValueLong) Value(org.h2.value.Value)

Aggregations

Cursor (org.h2.index.Cursor)24 Value (org.h2.value.Value)20 Index (org.h2.index.Index)11 Row (org.h2.result.Row)11 SearchRow (org.h2.result.SearchRow)11 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Constraint (org.h2.constraint.Constraint)5 SingleRowCursor (org.h2.index.SingleRowCursor)5 Column (org.h2.table.Column)5 Session (org.h2.engine.Session)4 MultiVersionIndex (org.h2.index.MultiVersionIndex)4 IndexColumn (org.h2.table.IndexColumn)4 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)3 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)3 Database (org.h2.engine.Database)3 ValueLong (org.h2.value.ValueLong)3 PreparedStatement (java.sql.PreparedStatement)2 BitSet (java.util.BitSet)2 UUID (java.util.UUID)2