core/src/main/java/com/orientechnologies/orient/core/sql/executor/OSelectExecutionPlanner.java
private void calculateShardingStrategy(QueryPlanningInfo info, OCommandContext ctx) {
    ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) ctx.getDatabase();
    info.distributedFetchExecutionPlans = new LinkedHashMap<>();

    Map<String, Set<String>> clusterMap = db.getActiveClusterMap();
    Set<String> queryClusters = calculateTargetClusters(info, ctx);
    if (queryClusters == null || queryClusters.size() == 0) {//no target
      String localNode = db.getLocalNodeName();
      info.serverToClusters = new LinkedHashMap<>();
      info.serverToClusters.put(localNode, clusterMap.get(localNode));
      info.distributedFetchExecutionPlans.put(localNode, new OSelectExecutionPlan(ctx));
      return;
    }

//    Set<String> serversWithAllTheClusers = getServersThatHasAllClusters(clusterMap, queryClusters);
//    if (serversWithAllTheClusers.isEmpty()) {
    // sharded query
    Map<String, Set<String>> minimalSetOfNodes = getMinimalSetOfNodesForShardedQuery(db.getLocalNodeName(), clusterMap,
        queryClusters);
    if (minimalSetOfNodes == null) {
      throw new OCommandExecutionException("Cannot execute sharded query");
    }
    info.serverToClusters = minimalSetOfNodes;
    for (String node : info.serverToClusters.keySet()) {
      info.distributedFetchExecutionPlans.put(node, new OSelectExecutionPlan(ctx));
    }
//    } else {
//      // all on a node
//      String targetNode = serversWithAllTheClusers.contains(db.getLocalNodeName()) ?
//          db.getLocalNodeName() :
//          serversWithAllTheClusers.iterator().next();
//      info.serverToClusters = new HashMap<>();
//      info.serverToClusters.put(targetNode, queryClusters);
//    }
  }
private void calculateShardingStrategy(QueryPlanningInfo info, OCommandContext ctx) {
    ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) ctx.getDatabase();
    info.distributedFetchExecutionPlans = new LinkedHashMap<>();

    Map<String, Set<String>> clusterMap = db.getActiveClusterMap();
    Set<String> queryClusters = calculateTargetClusters(info, ctx);
    if (queryClusters == null || queryClusters.size() == 0) {//no target
      String localNode = db.getLocalNodeName();
      info.serverToClusters = new LinkedHashMap<>();
      info.serverToClusters.put(localNode, clusterMap.get(localNode));
      info.distributedFetchExecutionPlans.put(localNode, new OSelectExecutionPlan(ctx));
      return;
    }

//    Set<String> serversWithAllTheClusers = getServersThatHasAllClusters(clusterMap, queryClusters);
//    if (serversWithAllTheClusers.isEmpty()) {
    // sharded query
    Map<String, Set<String>> minimalSetOfNodes = getMinimalSetOfNodesForShardedQuery(db.getLocalNodeName(), clusterMap,
        queryClusters);
    if (minimalSetOfNodes == null) {
      throw new OCommandExecutionException("Cannot execute sharded query");
    }
    info.serverToClusters = minimalSetOfNodes;
    for (String node : info.serverToClusters.keySet()) {
      info.distributedFetchExecutionPlans.put(node, new OSelectExecutionPlan(ctx));
    }
//    } else {
//      // all on a node
//      String targetNode = serversWithAllTheClusers.contains(db.getLocalNodeName()) ?
//          db.getLocalNodeName() :
//          serversWithAllTheClusers.iterator().next();
//      info.serverToClusters = new HashMap<>();
//      info.serverToClusters.put(targetNode, queryClusters);
//    }
  }
private void calculateShardingStrategy ( QueryPlanningInfo info , OCommandContext ctx ) { ODatabaseDocumentInternal db = ( ODatabaseDocumentInternal ) ctx . getDatabase ( ) ; info . distributedFetchExecutionPlans = new LinkedHashMap <> ( ) ; Map < String , Set < String > > clusterMap = db . getActiveClusterMap ( ) ; Set < String > queryClusters = calculateTargetClusters ( info , ctx ) ; if ( queryClusters == null || queryClusters . size ( ) == 0 ) { //no target String localNode = db . getLocalNodeName ( ) ; info . serverToClusters = new LinkedHashMap <> ( ) ; info . serverToClusters . put ( localNode , clusterMap . get ( localNode ) ) ; info . distributedFetchExecutionPlans . put ( localNode , new OSelectExecutionPlan ( ctx ) ) ; return ; } //    Set<String> serversWithAllTheClusers = getServersThatHasAllClusters(clusterMap, queryClusters); //    if (serversWithAllTheClusers.isEmpty()) { // sharded query Map < String , Set < String > > minimalSetOfNodes = getMinimalSetOfNodesForShardedQuery ( db . getLocalNodeName ( ) , clusterMap , queryClusters ) ; if ( minimalSetOfNodes == null ) { throw new OCommandExecutionException ( "Cannot execute sharded query" ) ; } info . serverToClusters = minimalSetOfNodes ; for ( String node : info . serverToClusters . keySet ( ) ) { info . distributedFetchExecutionPlans . put ( node , new OSelectExecutionPlan ( ctx ) ) ; } //    } else { //      // all on a node //      String targetNode = serversWithAllTheClusers.contains(db.getLocalNodeName()) ? //          db.getLocalNodeName() : //          serversWithAllTheClusers.iterator().next(); //      info.serverToClusters = new HashMap<>(); //      info.serverToClusters.put(targetNode, queryClusters); //    } }
based on the cluster/server map and the query target, this method tries to find an optimal strategy to execute the query on the
cluster.

@param info
@param ctx
based on the cluster / server map and the query target this method tries to find an optimal strategy to execute the query on the cluster .