ArcadeData / arcadedb

ArcadeDB Multi-Model Database, one DBMS that supports SQL, Cypher, Gremlin, HTTP/JSON, MongoDB and Redis. ArcadeDB is a conceptual fork of OrientDB, the first Multi-Model DBMS. ArcadeDB supports Vector Embeddings.
https://arcadedb.com
Apache License 2.0
503 stars 62 forks source link

SQL: Out-of-memory when `CREATE EDGE ... IF NOT EXISTS` for existing edges with array of destination vertices #1763

Open gramian opened 1 month ago

gramian commented 1 month ago

ArcadeDB Version:

ArcadeDB Server v24.11.1-SNAPSHOT (build 4207821d055e37cbd74b76683e45073da759c2de/1729083296142/console)

OS and JDK Version:

Running on Mac OS X 12.7.6 - OpenJDK 64-Bit Server VM 17.0.12 (Homebrew)

When creating edges that already exists with the suffix IF NOT EXISTS and the destinition (TO part) is an array, then an out-of-memory error happens after some time.

Expected behavior

No out-of-memory (OOM) error.

Actual behavior

Error on command execution (PostCommandHandler)
java.lang.OutOfMemoryError: Java heap space

or:

Error on command execution (PostCommandHandler)
java.lang.OutOfMemoryError: Java heap space
    at java.base/java.util.Arrays.copyOf(Arrays.java:3481)
    at java.base/java.util.ArrayList.grow(ArrayList.java:237)
    at java.base/java.util.ArrayList.grow(ArrayList.java:244)
    at java.base/java.util.ArrayList.add(ArrayList.java:454)
    at java.base/java.util.ArrayList.add(ArrayList.java:467)
    at com.arcadedb.query.sql.executor.InsertExecutionPlan.executeInternal(InsertExecutionPlan.java:67)
    at com.arcadedb.query.sql.executor.ScriptLineStep.syncPull(ScriptLineStep.java:48)
    at com.arcadedb.query.sql.executor.ScriptExecutionPlan.doExecute(ScriptExecutionPlan.java:101)
    at com.arcadedb.query.sql.executor.ScriptExecutionPlan.fetchNext(ScriptExecutionPlan.java:62)
    at com.arcadedb.query.sql.parser.LocalResultSet.fetchNext(LocalResultSet.java:44)
    at com.arcadedb.query.sql.parser.LocalResultSet.<init>(LocalResultSet.java:40)
    at com.arcadedb.query.sql.SQLScriptQueryEngine.executeInternal(SQLScriptQueryEngine.java:218)
    at com.arcadedb.query.sql.SQLScriptQueryEngine.command(SQLScriptQueryEngine.java:108)
    at com.arcadedb.database.LocalDatabase.command(LocalDatabase.java:1348)
    at com.arcadedb.server.ServerDatabase.command(ServerDatabase.java:472)
    at com.arcadedb.server.http.handler.PostCommandHandler.executeCommand(PostCommandHandler.java:134)
    at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:113)
    at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:100)
    at com.arcadedb.server.http.handler.AbstractServerHttpHandler.handleRequest(AbstractServerHttpHandler.java:127)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:395)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
    at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
    at java.base/java.lang.Thread.run(Thread.java:840)

Steps to reproduce

  1. Create vertex and edge types

    CREATE VERTEX TYPE vex;
    CREATE EDGE TYPE edg;
  2. Add some vertices

    CREATE VERTEX vex;
    CREATE VERTEX vex;
    CREATE VERTEX vex;
  3. Add new edges

    CREATE EDGE edg FROM #1:0 TO [#4:0,#7:0]
  4. Try add same edges again with IF NOT EXISTS

    CREATE EDGE edg FROM #1:0 TO [#4:0,#7:0] IF NOT EXISTS

    This last statement causes the OOM error.

lvca commented 1 month ago

That's pretty awful, I'll look it up asap.