Skip to content

Commit

Permalink
refactor: make sure to create the script line fetch plan only onece
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 7, 2024
1 parent 435724c commit 9959167
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 9959167

Please sign in to comment.