From 9959167b20feed493775300e5d297ed01e07d70f Mon Sep 17 00:00:00 2001 From: Tglman Date: Sat, 7 Dec 2024 21:03:20 +0000 Subject: [PATCH] refactor: make sure to create the script line fetch plan only onece --- .../core/sql/executor/OScriptExecutionPlan.java | 9 ++++----- .../core/sql/executor/ScriptLineStep.java | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionPlan.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionPlan.java index 73626f79469..d19e27228a0 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionPlan.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionPlan.java @@ -82,7 +82,6 @@ public void chain(OStatement nextStm, boolean profilingEnabled, OCommandContext } public void chain(ORetryExecutionPlan retryStep, boolean profilingEnabled, OCommandContext ctx) { - OExecutionStepInternal lastStep = steps.size() == 0 ? null : steps.get(steps.size() - 1); OExecutionStepInternal nextStep = new OExecutionStepInternal() { @@ -140,13 +139,13 @@ public boolean canBeCached() { return false; } - public boolean containsReturn() { + public boolean containsReturn(OCommandContext ctx) { for (OExecutionStepInternal step : steps) { if (step instanceof ReturnStep) { return true; } if (step instanceof ScriptLineStep) { - return ((ScriptLineStep) step).containsReturn(); + return ((ScriptLineStep) step).containsReturn(ctx); } } @@ -167,7 +166,7 @@ public OExecutionStepInternal executeUntilReturn(OCommandContext ctx) { for (int i = 0; i < steps.size() - 1; i++) { OExecutionStepInternal step = steps.get(i); if (step instanceof ScriptLineStep) - if (((ScriptLineStep) step).containsReturn()) { + if (((ScriptLineStep) step).containsReturn(ctx)) { OExecutionStepInternal returnStep = ((ScriptLineStep) step).executeUntilReturn(ctx); if (returnStep != null) { lastStep = returnStep; @@ -196,7 +195,7 @@ public OExecutionStepInternal executeFull(OCommandContext ctx) { for (int i = 0; i < steps.size(); i++) { OExecutionStepInternal step = steps.get(i); if (step instanceof ScriptLineStep) { - if (((ScriptLineStep) step).containsReturn()) { + if (((ScriptLineStep) step).containsReturn(ctx)) { OExecutionStepInternal returnStep = ((ScriptLineStep) step).executeUntilReturn(ctx); if (returnStep != null) { return returnStep; diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/ScriptLineStep.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/ScriptLineStep.java index 7534a867e22..0599abd7c0f 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/ScriptLineStep.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/ScriptLineStep.java @@ -13,15 +13,22 @@ */ public class ScriptLineStep extends AbstractExecutionStep { protected final OStatement statement; + private OInternalExecutionPlan plan; public ScriptLineStep(OStatement statement, OCommandContext ctx, boolean profilingEnabled) { super(ctx, profilingEnabled); this.statement = statement; } + private void initPlan(OCommandContext ctx) { + if (plan == null) { + plan = statement.createExecutionPlan(ctx); + } + } + @Override public OExecutionStream internalStart(OCommandContext ctx) throws OTimeoutException { - OInternalExecutionPlan plan = statement.createExecutionPlan(ctx); + initPlan(ctx); if (plan instanceof OInsertExecutionPlan) { ((OInsertExecutionPlan) plan).executeInternal(ctx); } else if (plan instanceof ODeleteExecutionPlan) { @@ -36,10 +43,10 @@ public OExecutionStream internalStart(OCommandContext ctx) throws OTimeoutExcept return plan.start(ctx); } - public boolean containsReturn() { - OInternalExecutionPlan plan = statement.createExecutionPlan(ctx); + public boolean containsReturn(OCommandContext ctx) { + initPlan(ctx); if (plan instanceof OScriptExecutionPlan) { - return ((OScriptExecutionPlan) plan).containsReturn(); + return ((OScriptExecutionPlan) plan).containsReturn(ctx); } if (plan instanceof OSingleOpExecutionPlan) { if (((OSingleOpExecutionPlan) plan).statement instanceof OReturnStatement) { @@ -61,7 +68,7 @@ public boolean containsReturn() { } public OExecutionStepInternal executeUntilReturn(OCommandContext ctx) { - OInternalExecutionPlan plan = statement.createExecutionPlan(ctx); + initPlan(ctx); if (plan instanceof OScriptExecutionPlan) { return ((OScriptExecutionPlan) plan).executeUntilReturn(ctx); }