#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;
}