Skip to content

Commit c1a28a8

Browse files
committed
Merge branch 'upstream-main'
2 parents 71c3d4a + 89e0d16 commit c1a28a8

28 files changed

Lines changed: 136 additions & 28 deletions

File tree

bolt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>com.arcadedb</groupId>
2727
<artifactId>arcadedb-parent</artifactId>
28-
<version>26.5.1</version>
28+
<version>26.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

console/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>com.arcadedb</groupId>
2727
<artifactId>arcadedb-parent</artifactId>
28-
<version>26.5.1</version>
28+
<version>26.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

coverage/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<parent>
2727
<groupId>com.arcadedb</groupId>
2828
<artifactId>arcadedb-parent</artifactId>
29-
<version>26.5.1</version>
29+
<version>26.6.1-SNAPSHOT</version>
3030
<relativePath>../pom.xml</relativePath>
3131
</parent>
3232

e2e-ha/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>com.arcadedb</groupId>
2727
<artifactId>arcadedb-parent</artifactId>
28-
<version>26.5.1</version>
28+
<version>26.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

e2e/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>com.arcadedb</groupId>
2727
<artifactId>arcadedb-parent</artifactId>
28-
<version>26.5.1</version>
28+
<version>26.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

engine/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>com.arcadedb</groupId>
2727
<artifactId>arcadedb-parent</artifactId>
28-
<version>26.5.1</version>
28+
<version>26.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

engine/src/main/java/com/arcadedb/query/sql/parser/Expression.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ public boolean isBaseIdentifier() {
111111
}
112112

113113
public boolean isEarlyCalculated(final CommandContext context) {
114-
if (this.mathExpression != null)
114+
if (isNull)
115+
return true;
116+
else if (rid != null)
117+
return rid.legacy || (rid.expression != null && rid.expression.isEarlyCalculated(context));
118+
else if (this.mathExpression != null)
115119
return this.mathExpression.isEarlyCalculated(context);
116120
else if (this.whereCondition != null)
117121
return false;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright © 2021-present Arcade Data Ltd (info@arcadedata.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-FileCopyrightText: 2021-present Arcade Data Ltd (info@arcadedata.com)
17+
* SPDX-License-Identifier: Apache-2.0
18+
*/
19+
package com.arcadedb.index;
20+
21+
import com.arcadedb.TestHelper;
22+
import com.arcadedb.database.RID;
23+
import com.arcadedb.query.sql.executor.ResultSet;
24+
import com.arcadedb.schema.Schema;
25+
import com.arcadedb.schema.Type;
26+
import com.arcadedb.schema.VertexType;
27+
import org.junit.jupiter.api.Test;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/**
32+
* Regression test: a single-property index on a LINK property must be used by SQL
33+
* regardless of whether the RID is written as a quoted string ("#150:5") or as an
34+
* unquoted RID literal (#150:5).
35+
*
36+
* Before the fix, Expression.isEarlyCalculated() returned false for RID-literal
37+
* expressions (the rid field was not checked), so the planner classified the
38+
* equality as non-index-aware and ran a full scan.
39+
*/
40+
class LinkIndexRidLiteralTest extends TestHelper {
41+
42+
@Override
43+
protected void beginTest() {
44+
database.transaction(() -> {
45+
final VertexType library = database.getSchema().createVertexType("Library");
46+
library.createProperty("name", Type.STRING);
47+
48+
final VertexType bo = database.getSchema().createVertexType("BusinessObject");
49+
bo.createProperty("_library", Type.LINK);
50+
database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, false, "BusinessObject", "_library");
51+
});
52+
}
53+
54+
@Test
55+
void equalityOnLinkUsesIndexForQuotedStringRid() {
56+
final RID libRid = createFixture();
57+
58+
database.transaction(() -> {
59+
final String explain = database.query("sql",
60+
"EXPLAIN SELECT FROM BusinessObject WHERE _library = \"" + libRid + "\"")
61+
.next().getProperty("executionPlan").toString();
62+
63+
assertThat(explain).contains("FETCH FROM INDEX");
64+
65+
try (final ResultSet rs = database.query("sql",
66+
"SELECT FROM BusinessObject WHERE _library = \"" + libRid + "\"")) {
67+
assertThat(rs.stream().count()).isEqualTo(3);
68+
}
69+
});
70+
}
71+
72+
@Test
73+
void equalityOnLinkUsesIndexForUnquotedRidLiteral() {
74+
final RID libRid = createFixture();
75+
76+
database.transaction(() -> {
77+
final String explain = database.query("sql",
78+
"EXPLAIN SELECT FROM BusinessObject WHERE _library = " + libRid)
79+
.next().getProperty("executionPlan").toString();
80+
81+
assertThat(explain).contains("FETCH FROM INDEX");
82+
83+
try (final ResultSet rs = database.query("sql",
84+
"SELECT FROM BusinessObject WHERE _library = " + libRid)) {
85+
assertThat(rs.stream().count()).isEqualTo(3);
86+
}
87+
});
88+
}
89+
90+
private RID createFixture() {
91+
final RID[] holder = new RID[1];
92+
database.transaction(() -> {
93+
final var lib = database.newVertex("Library").set("name", "main").save();
94+
holder[0] = lib.getIdentity();
95+
for (int i = 0; i < 3; i++)
96+
database.newVertex("BusinessObject").set("_library", holder[0]).save();
97+
for (int i = 0; i < 5; i++) {
98+
final var otherLib = database.newVertex("Library").set("name", "other-" + i).save();
99+
database.newVertex("BusinessObject").set("_library", otherLib.getIdentity()).save();
100+
}
101+
});
102+
return holder[0];
103+
}
104+
}

graphql/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>com.arcadedb</groupId>
2626
<artifactId>arcadedb-parent</artifactId>
27-
<version>26.5.1</version>
27+
<version>26.6.1-SNAPSHOT</version>
2828
<relativePath>../pom.xml</relativePath>
2929
</parent>
3030

gremlin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>com.arcadedb</groupId>
2727
<artifactId>arcadedb-parent</artifactId>
28-
<version>26.5.1</version>
28+
<version>26.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

0 commit comments

Comments
 (0)