docs: protected QueryResults executeOptimizedQuery( final ScanQueryContext context,
                                                    QueryCommand command,
                                                    Statistics statistics,
                                                    PlanNode plan ) {
          long nanos = System.nanoTime();
          Columns columns = null;
          NodeSequence rows = null;
          final String workspaceName = context.getWorkspaceNames().iterator().next();
          try {
  
              // Find the topmost PROJECT node and build the Columns ...
              PlanNode project = plan.findAtOrBelow(Type.PROJECT);
              assert project != null;
              columns = context.columnsFor(plan);
              assert columns != null;
  
              boolean trace = LOGGER.isTraceEnabled();
              if (context.getHints().planOnly) {
                  if (trace) {
                      LOGGER.trace("Request for only query plan when executing query {0}", context.id());
                  }
                  rows = NodeSequence.emptySequence(columns.getColumns().size());
              } else {
                  boolean includeSystemContent = context.getHints().includeSystemContent;
                  final QuerySources sources = new QuerySources(context.getRepositoryCache(), context.getNodeTypes(),
                                                                workspaceName, includeSystemContent);
                  rows = createNodeSequence(command, context, plan, columns, sources);
                  long nanos2 = System.nanoTime();
                  statistics = statistics.withResultsFormulationTime(Math.abs(nanos2 - nanos));
                  nanos = nanos2;
                  if (rows == null) {
                      // There must have been an error or was cancelled ...
                      assert context.getProblems().hasErrors() || context.isCancelled();
                      rows = NodeSequence.emptySequence(columns.getColumns().size());
                  }
                  if (trace) {
                      LOGGER.trace("The execution function for {0}: {1}", context.id(), rows);
                  }
              }
          } finally {
              statistics = statistics.withExecutionTime(Math.abs(System.nanoTime() - nanos));
          }
          final String planDesc = context.getHints().showPlan ? plan.getString() : null;
          CachedNodeSupplier cachedNodes = context.getNodeCache(workspaceName);
          return new Results(columns, statistics, rows, cachedNodes, context.getProblems(), planDesc);
      }