Skip to content

Commit 23058e2

Browse files
committed
test: add tests for check of combination of indexes usage with null and empty values
1 parent 7a9ec43 commit 23058e2

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,16 +3653,92 @@ public void testEmptyListNoIndex() {
36533653
String className = "testEmptyListNoIndex";
36543654
OClass clazz = db.createClassIfNotExist(className);
36553655
OProperty prop = clazz.createProperty("noIndex", OType.EMBEDDEDLIST, OType.STRING);
3656-
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
3656+
final ODocument metadata = new ODocument();
3657+
metadata.field("ignoreNullValues", false);
3658+
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE, metadata);
36573659

36583660
db.command("insert into " + className + " set noIndex = ['foo', 'bar']");
36593661
db.command("insert into " + className + " set noIndex = ['bbb', 'FFF']");
3662+
db.command("insert into " + className + " set noIndex = []");
36603663

36613664
try (OResultSet result = db.query("select from " + className + " where noIndex = []")) {
3662-
Assert.assertFalse(result.hasNext());
36633665
Assert.assertFalse(
36643666
result.getExecutionPlan().get().getSteps().stream()
36653667
.anyMatch(x -> x instanceof FetchFromIndexStep));
3668+
Assert.assertEquals(1, result.stream().count());
3669+
}
3670+
}
3671+
3672+
@Test
3673+
public void testEmptyListOrNullOrEmptyMultipleCondition() {
3674+
String className = "testEmptyListNoIndex";
3675+
OClass clazz = db.createClassIfNotExist(className);
3676+
OProperty prop = clazz.createProperty("noIndex", OType.EMBEDDEDLIST, OType.STRING);
3677+
final ODocument metadata = new ODocument();
3678+
metadata.field("ignoreNullValues", false);
3679+
3680+
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE, metadata);
3681+
3682+
db.command("insert into " + className + " set noIndex = ['foo', 'bar'], name='aa' ");
3683+
db.command("insert into " + className + " set noIndex = ['bbb', 'FFF'], name='aa' ");
3684+
db.command("insert into " + className + " set noIndex = [] , name='aa' ");
3685+
db.command("insert into " + className + " set noIndex = null , name='aa'");
3686+
3687+
try (OResultSet result =
3688+
db.query(
3689+
"select from "
3690+
+ className
3691+
+ " where name='aa' and(noIndex = [] or noIndex is null or noIndex = '') ")) {
3692+
Assert.assertFalse(
3693+
result.getExecutionPlan().get().getSteps().stream()
3694+
.anyMatch(x -> x instanceof FetchFromIndexStep));
3695+
Assert.assertEquals(2, result.stream().count());
3696+
}
3697+
}
3698+
3699+
@Test
3700+
public void testEmptyListOrNull() {
3701+
String className = "testEmptyListNoIndex";
3702+
OClass clazz = db.createClassIfNotExist(className);
3703+
OProperty prop = clazz.createProperty("noIndex", OType.EMBEDDEDLIST, OType.STRING);
3704+
final ODocument metadata = new ODocument();
3705+
metadata.field("ignoreNullValues", false);
3706+
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE, metadata);
3707+
3708+
db.command("insert into " + className + " set noIndex = ['foo', 'bar']");
3709+
db.command("insert into " + className + " set noIndex = ['bbb', 'FFF']");
3710+
db.command("insert into " + className + " set noIndex = []");
3711+
db.command("insert into " + className + " set noIndex = null");
3712+
3713+
try (OResultSet result =
3714+
db.query("select from " + className + " where noIndex = [] or noIndex is null ")) {
3715+
Assert.assertFalse(
3716+
result.getExecutionPlan().get().getSteps().stream()
3717+
.anyMatch(x -> x instanceof FetchFromIndexStep));
3718+
Assert.assertEquals(2, result.stream().count());
3719+
}
3720+
}
3721+
3722+
@Test
3723+
public void testEmptyListOrNullHashIndex() {
3724+
String className = "testEmptyListNoIndex";
3725+
OClass clazz = db.createClassIfNotExist(className);
3726+
OProperty prop = clazz.createProperty("noIndex", OType.EMBEDDEDLIST, OType.STRING);
3727+
final ODocument metadata = new ODocument();
3728+
metadata.field("ignoreNullValues", false);
3729+
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX, metadata);
3730+
3731+
db.command("insert into " + className + " set noIndex = ['foo', 'bar']");
3732+
db.command("insert into " + className + " set noIndex = ['bbb', 'FFF']");
3733+
db.command("insert into " + className + " set noIndex = []");
3734+
db.command("insert into " + className + " set noIndex = null");
3735+
3736+
try (OResultSet result =
3737+
db.query("select from " + className + " where noIndex = [] or noIndex is null ")) {
3738+
Assert.assertFalse(
3739+
result.getExecutionPlan().get().getSteps().stream()
3740+
.anyMatch(x -> x instanceof FetchFromIndexStep));
3741+
Assert.assertEquals(2, result.stream().count());
36663742
}
36673743
}
36683744

0 commit comments

Comments
 (0)