Skip to content

Commit

Permalink
fixed bug for transaction index changes iteration in case of missing …
Browse files Browse the repository at this point in the history
…value, issue #7322
  • Loading branch information
tglman committed Apr 12, 2017
1 parent 47740ef commit 6255c91
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ public PureTxBetweenIndexForwardCursor(Object fromKey, boolean fromInclusive, Ob
else
lastKey = indexChanges.getLowerKey(toKey);

nextKey = firstKey;
if (firstKey != null && ODefaultComparator.INSTANCE.compare(firstKey, toKey) > 0) {
nextKey = null;
} else {
nextKey = firstKey;
}
}

@Override
Expand Down Expand Up @@ -166,7 +170,11 @@ public PureTxBetweenIndexBackwardCursor(Object fromKey, boolean fromInclusive, O
else
lastKey = indexChanges.getLowerKey(toKey);

nextKey = lastKey;
if (firstKey != null && ODefaultComparator.INSTANCE.compare(firstKey, toKey) > 0) {
nextKey = null;
} else {
nextKey = firstKey;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.orientechnologies.orient.core.tx;

import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Created by tglman on 12/04/17.
*/
public class TransactionQueryIndexTests {

private OrientDB orientDB;
private ODatabaseDocument database;

@Before
public void before() {
orientDB = new OrientDB("embedded:", OrientDBConfig.defaultConfig());
orientDB.create("test", ODatabaseType.MEMORY);
database = orientDB.open("test", "admin", "admin");
}

@Test
public void test() {
OClass clazz = database.createClass("test");
OProperty prop = clazz.createProperty("test", OType.STRING);
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);

database.begin();
ODocument doc = database.newInstance("test");
doc.setProperty("test", "abcdefg");
database.save(doc);
OResultSet res = database.query("select from Test where test='abcdefg' ");

assertEquals(1L, res.stream().count());

res = database.query("select from Test where test='aaaaa' ");

System.out.println(res.getExecutionPlan().get().prettyPrint(0, 0));
assertEquals(0L, res.stream().count());
}

@After
public void after() {
database.close();
orientDB.close();
}

}

0 comments on commit 6255c91

Please sign in to comment.