Source:
<code>public static String getMaxFeature(final Server server, String sqlQuery, final int configuration) throws PerfEnforceException { try { String explainQuery = "EXPLAIN " + sqlQuery; List<String> featuresList = new ArrayList<String>(); String maxFeature = ""; double maxCost = Integer.MIN_VALUE; String[] allWorkerFeatures = server.executeSQLStatement( explainQuery, Schema.ofFields("explain", Type.STRING_TYPE), PerfEnforceUtils.getWorkerRangeSet(configuration)); for (String currentWorkerFeatures : allWorkerFeatures) { if (currentWorkerFeatures.contains("cost")) { currentWorkerFeatures = currentWorkerFeatures.substring(currentWorkerFeatures.indexOf("cost")); currentWorkerFeatures = currentWorkerFeatures.replace("\"", " "); <START> String[] cmd = { <END> "sh", "-c", "echo \"" + currentWorkerFeatures + "\" | sed -e 's/.*cost= }; ProcessBuilder pb = new ProcessBuilder(cmd); Process p = pb.start(); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); currentWorkerFeatures = input.readLine(); if (explainQuery.contains("WHERE")) { String[] tables = explainQuery .substring(explainQuery.indexOf("FROM"), explainQuery.indexOf("WHERE")) .split(","); currentWorkerFeatures = tables.length + "," + currentWorkerFeatures; } else { currentWorkerFeatures = "1," + currentWorkerFeatures; } currentWorkerFeatures += "," + configuration + ",0"; featuresList.add(currentWorkerFeatures); } } for (String f : featuresList) { double cost = Double.parseDouble(f.split(",")[2]); if (cost > maxCost) { maxCost = cost; maxFeature = f; } } return maxFeature; } catch (Exception e) { throw new PerfEnforceException("Error collecting the max feature"); } }</code><technical_language>This replaced String.replace() save launching a process</technical_language>

Target:
public static String getMaxFeature(final Server server, String sqlQuery, final int configuration) throws PerfEnforceException { try { String explainQuery = "EXPLAIN " + sqlQuery; List<String> featuresList = new ArrayList<String>(); String maxFeature = ""; double maxCost = Integer.MIN_VALUE; String[] allWorkerFeatures = server.executeSQLStatement( explainQuery, Schema.ofFields("explain", Type.STRING_TYPE), PerfEnforceUtils.getWorkerRangeSet(configuration)); for (String currentWorkerFeatures : allWorkerFeatures) { if (currentWorkerFeatures.contains("cost")) { currentWorkerFeatures = currentWorkerFeatures.substring(currentWorkerFeatures.indexOf("cost")); currentWorkerFeatures = currentWorkerFeatures .replace("\"", " ") .replaceAll(".*cost=|\\)", "") .replaceAll("\\.\\.| rows=| width=", ","); if (explainQuery.contains("WHERE")) { String[] tables = explainQuery .substring(explainQuery.indexOf("FROM"), explainQuery.indexOf("WHERE")) .split(","); currentWorkerFeatures = tables.length + "," + currentWorkerFeatures; } else { currentWorkerFeatures = "1," + currentWorkerFeatures; } currentWorkerFeatures += "," + configuration + ",0"; featuresList.add(currentWorkerFeatures); } } for (String f : featuresList) { double cost = Double.parseDouble(f.split(",")[2]); if (cost > maxCost) { maxCost = cost; maxFeature = f; } } return maxFeature; } catch (Exception e) { throw new PerfEnforceException("Error collecting the max feature"); } }