Skip to content

Commit

Permalink
Print the join graph using the keyword '--@joingraph'
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkimxxx committed Jul 31, 2024
1 parent 4e3d639 commit 5b0756f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CTP/sql/src/com/navercorp/cubridqa/cqt/common/SQLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static List<Sql> parseSqlFile(String sqlFile, String codeset, boolean isN
boolean isCall = false;
boolean isNewStatement = true;
boolean isQueryplan = false;
boolean isJoingraph = false;

LineScanner lineScanner = new LineScanner();

Expand All @@ -73,7 +74,9 @@ public static List<Sql> parseSqlFile(String sqlFile, String codeset, boolean isN

if ("--@queryplan".equals(line.trim())) {
isQueryplan = true;
} else {
} else if ("--@joingraph".equals(line.trim())) {
isJoingraph = true;
} else {
String controlCmd = getControlCommand(line);
if (controlCmd != null) {
// control command : either hodcas or server-message
Expand Down Expand Up @@ -115,11 +118,13 @@ public static List<Sql> parseSqlFile(String sqlFile, String codeset, boolean isN
// new sql
Sql sql = new Sql(connId, ret.toString(), paramList, isCall);
sql.setQueryplan(isQueryplan);
sql.setJoingraph(isJoingraph);
list.add(sql);

// initialize state variables
isNewStatement = true;
isQueryplan = false;
isJoingraph = false;
ret.setLength(0);
paramList = null;
isCall = false;
Expand Down
11 changes: 11 additions & 0 deletions CTP/sql/src/com/navercorp/cubridqa/cqt/console/bean/Sql.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class Sql {
// add query plan for single sql statement
private boolean isQueryplan = false;

// Only join graph xxx
private boolean isJoingraph = false;

private int type;

private String result = "";
Expand Down Expand Up @@ -160,4 +163,12 @@ public boolean isQueryplan() {
public void setQueryplan(boolean isQueryplan) {
this.isQueryplan = isQueryplan;
}

public boolean isJoingraph() {
return isJoingraph;
}

public void setJoingraph(boolean isJoingraph) {
this.isJoingraph = isJoingraph;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,16 @@ private void executeStatement(Connection conn, Sql sql, boolean isPrintQueryPlan
boolean isRs = st.execute(sql.getScript());
getAllResult(st, isRs, sql);
String script = sql.getScript().trim().toUpperCase();
if ((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) {
boolean isOnlyJoinGraph = sql.isJoingraph();
if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph) {
Method method = st.getClass().getMethod("getQueryplan", stringType);
String queryPlan = (String) method.invoke(st, new Object[] {sql.getScript()});
queryPlan = queryPlan + System.getProperty("line.separator");
queryPlan = StringUtil.replaceQureyPlan(queryPlan);
if (isOnlyJoinGraph) {
queryPlan = StringUtil.replaceJoingraph(queryPlan);
} else {
queryPlan = StringUtil.replaceQureyPlan(queryPlan);
}
sql.setResult(sql.getResult() + queryPlan);
method = null;
queryPlan = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,66 @@ public static String replaceQureyPlan(String queryPlan) {
return ret.toString();
}

/**
* * Show only the join graph.
* *
* * @param queryPlan
* * @return
* */
public static String replaceJoingraph(String queryPlan) {
if (queryPlan == null) {
return null;
}

StringBuilder ret = new StringBuilder();

String flag = "default";
String separator = System.getProperty("line.separator");
BufferedReader reader = null;
try {
reader = new BufferedReader(new StringReader(queryPlan));

String message = reader.readLine();
while (message != null) {
if (message.trim().equals("")) {
message = reader.readLine();
continue;
}

if (message.startsWith("Join graph edges:")) {
flag = "edges";
ret.append(message + separator);
message = reader.readLine();
continue;
} else if (message.startsWith("Join graph")) {
flag = "default";
ret.append(message + separator);
message = reader.readLine();
continue;
} else if (message.startsWith("Query plan:")) {
break;
}

// make chageable values hidden.
if ("edges".equals(flag)) {
message = message.replaceAll("sel [0-9]+\\.[0-9]+", "sel ?");
}

ret.append(message + separator);
message = reader.readLine();
}
} catch (Exception e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
return ret.toString();
}

/**
* translate byte array to Hex String .
*
Expand Down

0 comments on commit 5b0756f

Please sign in to comment.