private void logQuery(Operation op, ServiceDocumentQueryResult rsp, QuerySpecification qs,
String sql, long queryTime) {
if (isDebugQuery()) {
appendDebugInfo(op,
"ExecuteQuery time ms: " + queryTime, null,
"ExecuteQuery count: " + rsp.documentCount, null,
"Total query time ms: " + TimeUnit.MICROSECONDS.toMillis(rsp.queryTimeMicros),
null,
"QuerySpecification", Utils.toJsonHtml(qs),
"SQL", prettySqlStatement(sql));
}
if (this.logSlowQueryThresholdMicros > 0
&& rsp.queryTimeMicros > this.logSlowQueryThresholdMicros) {
long totalQueryTimeMillis = TimeUnit.MICROSECONDS.toMillis(rsp.queryTimeMicros);
Map<String, Object> map = new HashMap<>();
map.put("totalQueryTimeMillis", totalQueryTimeMillis);
map.put("executeQueryTimeMillis", queryTime);
map.put("documentCount", rsp.documentCount);
map.put("sql", sql);
map.put("querySpecification", qs);
logger.warning(String.format("Slow SQL Query, %d ms: %s", totalQueryTimeMillis,
Utils.toJson(map)));
}
}