#1660 - Modify MetaOrmQueryMetric getQueryPlanHash to return hash of sql

This commit is contained in:
rob bygrave
2019-03-27 16:12:09 +13:00
parent f8b97ff397
commit f06f21cf5e
3 changed files with 14 additions and 8 deletions
@@ -72,6 +72,7 @@ public class CQueryPlan {
private final boolean rowNumberIncluded;
private final String sql;
private final String sqlHash;
private final String logWhereSql;
@@ -115,6 +116,7 @@ public class CQueryPlan {
this.autoTuned = query.isAutoTuned();
this.asOfTableCount = query.getAsOfTableCount();
this.sql = sqlRes.getSql();
this.sqlHash = md5Hash(sql);
this.rowNumberIncluded = sqlRes.isIncludesRowNumberColumn();
this.sqlTree = sqlTree;
this.rawSql = rawSql;
@@ -141,6 +143,7 @@ public class CQueryPlan {
this.autoTuned = false;
this.asOfTableCount = 0;
this.sql = sql;
this.sqlHash = md5Hash(sql);
this.sqlTree = sqlTree;
this.rawSql = rawSql;
this.rowNumberIncluded = rowNumberIncluded;
@@ -245,21 +248,25 @@ public class CQueryPlan {
private String calcAuditQueryKey() {
// rawSql needs to include the MD5 hash of the sql
return rawSql ? planKey.getPartialKey() + "_" + getSqlMd5Hash() : planKey.getPartialKey();
return rawSql ? planKey.getPartialKey() + "_" + sqlHash : planKey.getPartialKey();
}
/**
* Return the MD5 hash of the underlying sql.
* Return the MD5 hash of the sql.
*/
private String getSqlMd5Hash() {
private String md5Hash(String sql) {
try {
return Md5.hash(sql);
} catch (Exception e) {
logger.error("Failed to MD5 hash the rawSql query", e);
logger.error("Failed to MD5 hash the query", e);
return "error";
}
}
public String getSqlHash() {
return sqlHash;
}
public String getSql() {
return sql;
}
@@ -239,7 +239,7 @@ public final class CQueryPlanStats {
@Override
public String getQueryPlanHash() {
return queryPlan.getPlanKey().toString();
return queryPlan.getSqlHash();
}
@Override
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.util;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
public class Md5 {
public final class Md5 {
/**
* Return the MD5 hash of the underlying sql.
@@ -12,8 +12,7 @@ public class Md5 {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(content.getBytes(StandardCharsets.UTF_8));
return digestToHex(digest);
return digestToHex(md.digest(content.getBytes(StandardCharsets.UTF_8)));
} catch (Exception e) {
throw new RuntimeException("MD5 hashing failed", e);
}