Skip to content

Commit

Permalink
IGNITE-22767 Fix index scan
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Jul 31, 2024
1 parent f87e1a9 commit 6d93176
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,12 @@ private synchronized void release() {

InlineIndexRowHandler rowHnd = idx.segment(0).rowHandler();

InlineIndexRowFactory rowFactory = isInlineScan() ?
new InlineIndexRowFactory(rowHnd.inlineIndexKeyTypes().toArray(new InlineIndexKeyType[0]), rowHnd) : null;
InlineIndexRowFactory rowFactory = isInlineScan()
? new InlineIndexRowFactory(
rowHnd.inlineIndexKeyTypes().toArray(new InlineIndexKeyType[0]),
rowHnd,
!F.isEmpty(ectx.getTxWriteEntries())) // Need access to CacheDataRow to corecctly handle transcaction context.
: null;

BPlusTree.TreeRowClosure<IndexRow, IndexRow> rowFilter = isInlineScan() ? null : createNotExpiredRowFilter();

Expand All @@ -444,10 +448,12 @@ private static class InlineIndexRowFactory implements BPlusTree.TreeRowFactory<I
/** */
private InlineIndexRowFactory(
InlineIndexKeyType[] keyTypes,
InlineIndexRowHandler idxRowHnd
InlineIndexRowHandler idxRowHnd,
boolean useCacheRow
) {
this.keyTypes = keyTypes;
this.idxRowHnd = idxRowHnd;
this.useCacheRow = useCacheRow;
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public RuntimeSortedIndex(
Row lowerRow = (lowerBound == null) ? null : lower;
Row upperRow = (upperBound == null) ? null : upper;

return new Cursor(comp, rows, lowerRow, upperRow, lowerInclude, upperInclude);
return new Cursor<>(comp, rows, lowerRow, upperRow, lowerInclude, upperInclude);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,12 @@ private void advance() throws IgniteCheckedException {
}
}

CacheDataRow row = cur.next()
? cur.get()
: txIter.hasNext() ? txIter.next() : null;
CacheDataRow row;

if (cur.next())
row = cur.get();
else
row = txIter.hasNext() ? txIter.next() : null;

if (row != null) {
if (row.expireTime() > 0 && row.expireTime() <= U.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ private void invokeInsideTx(GridNearTxLocal userTx, List<ModifyTuple> tuples) th
if (cache.get(entry.getKey()) != null)
throw conflictKeysException(Collections.singletonList(entry.getKey()));

cache.put(entry.getKey(), entry.getValue());

break;
case UPDATE:
cache.put(entry.getKey(), entry.getValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.internal.processors.tx;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -148,9 +149,14 @@ public static Collection<?> parameters() {
.setValueType(User.class.getName())
.setKeyFieldName("id")
.setFields(flds)
.setIndexes(Collections.singleton(new QueryIndex()
.setName("IDX_FIO_USERS")
.setFieldNames(Collections.singleton("fio"), true).setInlineSize(Character.BYTES * 20))))));
.setIndexes(Arrays.asList(
new QueryIndex()
.setName("IDX_FIO_USERS")
.setFieldNames(Collections.singleton("fio"), true).setInlineSize(Character.BYTES * 20),
new QueryIndex()
.setName("IDX_USER_ID")
.setFieldNames(Collections.singleton("userId"), true)
)))));

cli.createCache(new CacheConfiguration<Integer, Integer>()
.setName("TBL")
Expand Down Expand Up @@ -195,8 +201,6 @@ public void testIndexScan() {
for (int j = 0; j < 5; j++) {
int id = start + j + 1;

log.info("id = " + id);

insert(F.t(id, new User(id, "User" + j))); // Intentionally repeat FIO to make same indexed keys.
}
}
Expand All @@ -207,11 +211,11 @@ public void testIndexScan() {
for (int i = 0; i < 5; i++) {
int start = i * 10 + 5;

assertEquals(i * 10 + 1, executeSql(cli, "SELECT MIN(userid) FROM USERS.USERS WHERE userid > ?", i * 10).get(0).get(0));

for (int j = 0; j < 5; j++) {
int id = start + j + 1;

log.info("id = " + id);

insert(F.t(id, new User(id, "User" + j))); // Intentionally repeat FIO to make same indexed keys.

long expTblSz = 25L + i * 5 + j + 1;
Expand All @@ -223,6 +227,12 @@ public void testIndexScan() {
assertEquals(expTblSz, rows.size());

ensureSorted(rows, true);

assertEquals(
id,
executeSql(cli, "SELECT MIN(userid) FROM USERS.USERS WHERE userid BETWEEN ? AND ?", id, 500).get(0).get(0)
);

}
}

Expand All @@ -232,8 +242,6 @@ public void testIndexScan() {
for (int j = 0; j < 5; j++) {
int id = start + j + 1;

log.info("id = " + id);

delete(id);

long expTblSz = 50L - (i * 5 + j + 1);
Expand Down

0 comments on commit 6d93176

Please sign in to comment.