Skip to content

Commit fe9c214

Browse files
committed
fix: corrected execution of order by when the index do not cover nested properties, issue #10732
1 parent 0023e66 commit fe9c214

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

core/src/main/java/com/orientechnologies/orient/core/sql/executor/OSelectExecutionPlanner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,9 @@ private boolean fullySorted(OOrderBy orderBy, OAndBlock conditions, OIndex idx)
25662566
String order = null;
25672567

25682568
for (OOrderByItem item : orderBy.getItems()) {
2569+
if (item.getModifier() != null) {
2570+
return false;
2571+
}
25692572
if (order == null) {
25702573
order = item.getType();
25712574
} else if (!order.equals(item.getType())) {

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.orientechnologies.orient.core.id.ORID;
1515
import com.orientechnologies.orient.core.id.ORecordId;
1616
import com.orientechnologies.orient.core.metadata.schema.OClass;
17+
import com.orientechnologies.orient.core.metadata.schema.OClass.INDEX_TYPE;
1718
import com.orientechnologies.orient.core.metadata.schema.OProperty;
1819
import com.orientechnologies.orient.core.metadata.schema.OSchema;
1920
import com.orientechnologies.orient.core.metadata.schema.OType;
@@ -410,6 +411,66 @@ public void testSelectOrderWithProjections2() {
410411
result.close();
411412
}
412413

414+
@Test
415+
public void testSelectOrderLinkSetIndex() {
416+
String className = "testSelectOrderLinkSetIndex";
417+
OClass c1 = db.getMetadata().getSchema().createClass(className);
418+
c1.createProperty("Name", OType.STRING);
419+
String className2 = "testSelectOrderLinkSetIndexLink";
420+
OClass c2 = db.getMetadata().getSchema().createClass(className2);
421+
OProperty p = c2.createProperty("NativeState", OType.LINKSET, c1);
422+
p.createIndex(INDEX_TYPE.NOTUNIQUE);
423+
424+
db.command("INSERT INTO " + className + " SET Name = 'M'").close();
425+
;
426+
db.command("INSERT INTO " + className + " SET Name = 'P'").close();
427+
;
428+
db.command("INSERT INTO " + className + " SET Name = 'G'").close();
429+
;
430+
431+
db.command(
432+
"INSERT INTO "
433+
+ className2
434+
+ " SET NativeState = (SELECT FROM "
435+
+ className
436+
+ " WHERE Name = 'M')")
437+
.close();
438+
;
439+
db.command(
440+
"INSERT INTO "
441+
+ className2
442+
+ " SET NativeState = (SELECT FROM "
443+
+ className
444+
+ " WHERE Name = 'P')")
445+
.close();
446+
;
447+
db.command(
448+
"INSERT INTO "
449+
+ className2
450+
+ " SET NativeState = (SELECT FROM "
451+
+ className
452+
+ " WHERE Name = 'G')")
453+
.close();
454+
;
455+
456+
OResultSet result =
457+
db.query(
458+
"SELECT NativeState, NativeState[0].Name AS _NativeState_Name \n"
459+
+ "FROM "
460+
+ className2
461+
+ " WHERE NativeState IN (SELECT FROM "
462+
+ className
463+
+ " WHERE Name IN ['M','P','G']) \n"
464+
+ "ORDER BY NativeState[0].Name DESC");
465+
printExecutionPlan(result);
466+
List<String> names =
467+
result.stream()
468+
.map((x) -> (String) x.getProperty("_NativeState_Name"))
469+
.collect(Collectors.toList());
470+
assertEquals(Arrays.asList("P", "M", "G"), names);
471+
result.close();
472+
}
473+
413474
@Test
414475
public void testSelectFullScanWithFilter1() {
415476
String className = "testSelectFullScanWithFilter1";

0 commit comments

Comments
 (0)