Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7dbd95d
First version with basic functionalities working
lvca Sep 24, 2023
36a56ec
Merge branch 'main' into native-select
lvca Oct 5, 2023
84d4525
fix: fixed native select expression tree, added from buckets
lvca Oct 5, 2023
e4a670b
test: fixed test cases
lvca Oct 5, 2023
4067018
feat: native select, implemented to and from JSON
lvca Oct 5, 2023
d07d06e
fix: fixed native select json
lvca Oct 5, 2023
c4e48c5
perf: speeded up logic for comparison in SQL engine
lvca Oct 5, 2023
2c860b6
feat: native query now supports the timeout
lvca Oct 5, 2023
11784d7
perf: implemented lazy evaluation (speedup only when the operator nee…
lvca Oct 5, 2023
1da0a0e
test: added some benchmark to activate on demand
lvca Oct 5, 2023
4406da4
test: native select, added test case for timeout
lvca Oct 5, 2023
edaf4ac
feat: native select, supported timeout with cutting of results (no ex…
lvca Oct 5, 2023
6b13f8c
test: added test case with update
lvca Oct 5, 2023
a689deb
feat: first version of native select optimizer
lvca Oct 6, 2023
a68f7b3
fix: usage of indexes only when possible
lvca Oct 6, 2023
86ce969
feat: native select, supported like() and new()
lvca Oct 6, 2023
791ed5b
chore: refactoring to statically limit choices while building the nat…
lvca Oct 6, 2023
91ac132
Merge branch 'main' into native-select
lvca Oct 6, 2023
34e76c2
feat: supported orderBy() with multiple properties asc/desc.
lvca Oct 6, 2023
ab43a31
fix: fixed NPE introduced by recent optimization with SQL operators
lvca Oct 7, 2023
2eacc83
Merge branch 'main' into native-select
lvca Oct 16, 2023
550c4df
Merge branch 'main' into native-select
lvca Oct 16, 2023
ab0f800
feat: supported SKIP in native select
lvca Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions engine/src/main/java/com/arcadedb/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.arcadedb.graph.Vertex;
import com.arcadedb.index.IndexCursor;
import com.arcadedb.query.QueryEngine;
import com.arcadedb.query.select.Select;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.schema.Schema;

Expand Down Expand Up @@ -55,6 +56,8 @@ enum TRANSACTION_ISOLATION_LEVEL {
*/
String getCurrentUserName();

Select select();

/**
* Executes a command by specifying the language and arguments in a map.
*
Expand Down Expand Up @@ -218,9 +221,9 @@ enum TRANSACTION_ISOLATION_LEVEL {
* @see DatabaseAsyncExecutor#newEdgeByKeys(String, String, Object, String, String, Object, boolean, String, boolean, boolean, NewEdgeCallback, Object...)
* @see #newEdgeByKeys(Vertex, String, String[], Object[], boolean, String, boolean, Object...)
*/
Edge newEdgeByKeys(String sourceVertexType, String[] sourceVertexKeyNames, Object[] sourceVertexKeyValues, String destinationVertexType,
String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues, boolean createVertexIfNotExist, String edgeType, boolean bidirectional,
Object... properties);
Edge newEdgeByKeys(String sourceVertexType, String[] sourceVertexKeyNames, Object[] sourceVertexKeyValues,
String destinationVertexType, String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues,
boolean createVertexIfNotExist, String edgeType, boolean bidirectional, Object... properties);

/**
* Creates a new edge between two vertices specifying the source vertex instance and the key/value pairs to lookup for the destination vertices. The direction
Expand All @@ -242,8 +245,9 @@ Edge newEdgeByKeys(String sourceVertexType, String[] sourceVertexKeyNames, Objec
* @see DatabaseAsyncExecutor#newEdgeByKeys(String, String, Object, String, String, Object, boolean, String, boolean, boolean, NewEdgeCallback, Object...)
* @see #newEdgeByKeys(String, String[], Object[], String, String[], Object[], boolean, String, boolean, Object...)
*/
Edge newEdgeByKeys(Vertex sourceVertex, String destinationVertexType, String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues,
boolean createVertexIfNotExist, String edgeType, boolean bidirectional, Object... properties);
Edge newEdgeByKeys(Vertex sourceVertex, String destinationVertexType, String[] destinationVertexKeyNames,
Object[] destinationVertexKeyValues, boolean createVertexIfNotExist, String edgeType, boolean bidirectional,
Object... properties);

/**
* Returns the query engine by language name.
Expand Down
109 changes: 71 additions & 38 deletions engine/src/main/java/com/arcadedb/database/EmbeddedDatabase.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public Identifiable getRecord() {
return last;
}

@Override
public int getScore() {
return 0;
}

@Override
public BinaryComparator getComparator() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public Identifiable next() {
throw new NoSuchElementException();
}

@Override
public int getScore() {
return 0;
}

@Override
public BinaryComparator getComparator() {
return null;
Expand All @@ -62,7 +57,7 @@ public byte[] getBinaryKeyTypes() {

@Override
public long estimateSize() {
return 0l;
return 0L;
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions engine/src/main/java/com/arcadedb/index/IndexCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public interface IndexCursor extends Cursor {

Identifiable getRecord();

int getScore();

default void close() {
// NO ACTIONS
}
Expand Down
18 changes: 10 additions & 8 deletions engine/src/main/java/com/arcadedb/index/MultiIndexCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public MultiIndexCursor(final List<IndexInternal> indexes, final boolean ascendi
initCursors();
}

public MultiIndexCursor(final List<IndexInternal> indexes, final Object[] fromKeys, final boolean ascendingOrder, final boolean includeFrom,
final int limit) {
public MultiIndexCursor(final List<IndexInternal> indexes, final Object[] fromKeys, final boolean ascendingOrder,
final boolean includeFrom, final int limit) {
this.cursors = new ArrayList<>(indexes.size());
this.limit = limit;
for (final Index i : indexes) {
Expand Down Expand Up @@ -148,11 +148,6 @@ public Identifiable next() {
return nextValue;
}

@Override
public int getScore() {
return -1;
}

@Override
public void close() {
for (final IndexCursor cursor : cursors)
Expand All @@ -162,11 +157,18 @@ public void close() {
@Override
public long estimateSize() {
long tot = 0L;
for (final IndexCursor cursor : cursors)
for (final IndexCursor cursor : cursors) {
if (cursor.estimateSize() == -1)
return -1;
tot += cursor.estimateSize();
}
return tot;
}

public int getCursors() {
return cursors.size();
}

@Override
public Iterator<Identifiable> iterator() {
return this;
Expand Down
5 changes: 0 additions & 5 deletions engine/src/main/java/com/arcadedb/index/TempIndexCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public Identifiable next() {
return current.record;
}

@Override
public int getScore() {
return current.score;
}

@Override
public BinaryComparator getComparator() {
return null;
Expand Down
39 changes: 20 additions & 19 deletions engine/src/main/java/com/arcadedb/index/lsm/LSMTreeIndexCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public LSMTreeIndexCursor(final LSMTreeIndexMutable index, final boolean ascendi
this(index, ascendingOrder, null, true, null, true);
}

public LSMTreeIndexCursor(final LSMTreeIndexMutable index, final boolean ascendingOrder, final Object[] fromKeys, final boolean beginKeysInclusive,
final Object[] toKeys, final boolean endKeysInclusive) throws IOException {
public LSMTreeIndexCursor(final LSMTreeIndexMutable index, final boolean ascendingOrder, final Object[] fromKeys,
final boolean beginKeysInclusive, final Object[] toKeys, final boolean endKeysInclusive) throws IOException {
this.index = index;
this.ascendingOrder = ascendingOrder;
this.binaryKeyTypes = index.getBinaryKeyTypes();
Expand Down Expand Up @@ -118,13 +118,14 @@ public LSMTreeIndexCursor(final LSMTreeIndexMutable index, final boolean ascendi

if (serializedFromKeys != null) {
// SEEK FOR THE FROM RANGE
final BasePage currentPage = index.getDatabase().getTransaction().getPage(new PageId(index.getFileId(), pageId), index.getPageSize());
final BasePage currentPage = index.getDatabase().getTransaction()
.getPage(new PageId(index.getFileId(), pageId), index.getPageSize());
final Binary currentPageBuffer = new Binary(currentPage.slice());
final int count = index.getCount(currentPage);

if (count > 0) {
final LSMTreeIndexMutable.LookupResult lookupResult = index.lookupInPage(currentPage.getPageId().getPageNumber(), count, currentPageBuffer,
serializedFromKeys, ascendingOrder ? 2 : 3);
final LSMTreeIndexMutable.LookupResult lookupResult = index.lookupInPage(currentPage.getPageId().getPageNumber(), count,
currentPageBuffer, serializedFromKeys, ascendingOrder ? 2 : 3);

if (!lookupResult.outside) {
pageCursors[cursorIdx] = index.newPageIterator(pageId, lookupResult.keyIndex, ascendingOrder);
Expand All @@ -148,7 +149,8 @@ public LSMTreeIndexCursor(final LSMTreeIndexMutable index, final boolean ascendi
if (ascendingOrder) {
pageCursors[cursorIdx] = index.newPageIterator(pageId, -1, true);
} else {
final BasePage currentPage = index.getDatabase().getTransaction().getPage(new PageId(index.getFileId(), pageId), index.getPageSize());
final BasePage currentPage = index.getDatabase().getTransaction()
.getPage(new PageId(index.getFileId(), pageId), index.getPageSize());
pageCursors[cursorIdx] = index.newPageIterator(pageId, index.getCount(currentPage), false);
}

Expand Down Expand Up @@ -249,9 +251,11 @@ public String dumpStats() {
if (cursor == null)
buffer.append(String.format("%n- Cursor[%d] = null", i));
else {
buffer.append(String.format("%n- Cursor[%d] %s=%s index=%s compacted=%s totalKeys=%d ascending=%s keyTypes=%s currentPageId=%s currentPosInPage=%d", i,
Arrays.toString(cursorKeys[i]), Arrays.toString(cursor.getValue()), cursor.index, cursor instanceof LSMTreeIndexUnderlyingCompactedSeriesCursor,
cursor.totalKeys, cursor.ascendingOrder, Arrays.toString(cursor.keyTypes), cursor.getCurrentPageId(), cursor.getCurrentPositionInPage()));
buffer.append(String.format(
"%n- Cursor[%d] %s=%s index=%s compacted=%s totalKeys=%d ascending=%s keyTypes=%s currentPageId=%s currentPosInPage=%d",
i, Arrays.toString(cursorKeys[i]), Arrays.toString(cursor.getValue()), cursor.index,
cursor instanceof LSMTreeIndexUnderlyingCompactedSeriesCursor, cursor.totalKeys, cursor.ascendingOrder,
Arrays.toString(cursor.keyTypes), cursor.getCurrentPageId(), cursor.getCurrentPositionInPage()));
}
}

Expand Down Expand Up @@ -391,8 +395,8 @@ else if (tempCurrentValues.length > 0) {
if (serializedToKeys != null) {
final int compare = LSMTreeIndexMutable.compareKeys(comparator, binaryKeyTypes, cursorKeys[minorKeyIndex], toKeys);

if ((ascendingOrder && ((toKeysInclusive && compare > 0) || (!toKeysInclusive && compare >= 0))) || (!ascendingOrder && (
(toKeysInclusive && compare < 0) || (!toKeysInclusive && compare <= 0)))) {
if ((ascendingOrder && ((toKeysInclusive && compare > 0) || (!toKeysInclusive && compare >= 0))) || (!ascendingOrder
&& ((toKeysInclusive && compare < 0) || (!toKeysInclusive && compare <= 0)))) {
currentCursor.close();
pageCursors[minorKeyIndex] = null;
cursorKeys[minorKeyIndex] = null;
Expand Down Expand Up @@ -420,8 +424,9 @@ else if (tempCurrentValues.length > 0) {
if (txCursor == null || !txCursor.hasNext())
getClosestEntryInTx(currentKeys != null ? currentKeys : fromKeys, false);

} while ((currentValues == null || currentValues.length == 0 || (currentValueIndex < currentValues.length && index.isDeletedEntry(
currentValues[currentValueIndex]))) && hasNext());
} while (
(currentValues == null || currentValues.length == 0 || (currentValueIndex < currentValues.length && index.isDeletedEntry(
currentValues[currentValueIndex]))) && hasNext());

return currentValues == null || currentValueIndex >= currentValues.length ? null : currentValues[currentValueIndex++];
}
Expand Down Expand Up @@ -451,7 +456,8 @@ else if (inclusive)
entry = indexChanges.lowerEntry(new TransactionIndexContext.ComparableKey(keys));
}

final Map<TransactionIndexContext.IndexKey, TransactionIndexContext.IndexKey> values = entry != null ? entry.getValue() : null;
final Map<TransactionIndexContext.IndexKey, TransactionIndexContext.IndexKey> values =
entry != null ? entry.getValue() : null;
if (values != null) {
for (final TransactionIndexContext.IndexKey value : values.values()) {
if (value != null) {
Expand Down Expand Up @@ -502,11 +508,6 @@ public Identifiable getRecord() {
return null;
}

@Override
public int getScore() {
return 1;
}

@Override
public void close() {
for (final LSMTreeIndexUnderlyingAbstractCursor it : pageCursors)
Expand Down
Loading