Skip to content

Commit

Permalink
fix: added profiling to the SQL LET steps
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 16, 2023
1 parent c8bbf90 commit c07787f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public String prettyPrint(final int depth, final int indent) {
final StringBuilder result = new StringBuilder();
result.append(spaces);
result.append("+ DELETE");
if (profilingEnabled) {
if (profilingEnabled)
result.append(" (").append(getCostFormatted()).append(")");
}

return result.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public LetExpressionStep(final Identifier varName, final Expression expression,
public ResultSet syncPull(final CommandContext context, final int nRecords) throws TimeoutException {
checkForPrevious("Cannot execute a local LET on a query without a target");

cost = 0L;

return new ResultSet() {
final ResultSet source = getPrev().syncPull(context, nRecords);

Expand All @@ -49,10 +51,12 @@ public boolean hasNext() {

@Override
public Result next() {
final long beginTime = System.nanoTime();
final ResultInternal result = (ResultInternal) source.next();
final Object value = expression.execute(result, context);
result.setMetadata(varName.getStringValue(), value);
context.setVariable(varName.getStringValue(), value);
cost += System.nanoTime() - beginTime;
return result;
}

Expand All @@ -66,6 +70,11 @@ public void close() {
@Override
public String prettyPrint(final int depth, final int indent) {
final String spaces = ExecutionStepInternal.getIndent(depth, indent);
return spaces + "+ LET (for each record)\n" + spaces + " " + varName + " = " + expression;

final StringBuilder result = new StringBuilder();
result.append(spaces).append("+ LET (for each record)\n").append(spaces).append(" ").append(varName).append(" = (").append(expression).append(")");
if (profilingEnabled)
result.append(" (").append(getCostFormatted()).append(")");
return result.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ public Result next() {
}

private void calculate(final ResultInternal result, final CommandContext context) {
final long beginTime = System.nanoTime();

final BasicCommandContext subCtx = new BasicCommandContext();
subCtx.setDatabase(context.getDatabase());
subCtx.setParentWithoutOverridingChild(context);
final InternalExecutionPlan subExecutionPlan = query.createExecutionPlan(subCtx, profilingEnabled);
final List<Result> value = toList(new LocalResultSet(subExecutionPlan));
result.setMetadata(varName.getStringValue(), value);
context.setVariable(varName.getStringValue(), value);

cost = System.nanoTime() - beginTime;
}

private List<Result> toList(final LocalResultSet oLocalResultSet) {
Expand All @@ -82,13 +86,17 @@ private List<Result> toList(final LocalResultSet oLocalResultSet) {
public void close() {
source.close();
}

};
}

@Override
public String prettyPrint(final int depth, final int indent) {
final String spaces = ExecutionStepInternal.getIndent(depth, indent);
return spaces + "+ LET (for each record)\n" + spaces + " " + varName + " = (" + query + ")";

final StringBuilder result = new StringBuilder();
result.append(spaces).append("+ LET (for each record)\n").append(spaces).append(" ").append(varName).append(" = (").append(query).append(")");
if (profilingEnabled)
result.append(" (").append(getCostFormatted()).append(")");
return result.toString();
}
}

0 comments on commit c07787f

Please sign in to comment.