mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1588 -Fix query plan capture excluding update and delete queries from query plan capture
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.query;
|
||||
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.meta.QueryPlanRequest;
|
||||
import io.ebeaninternal.server.type.bindcapture.BindCapture;
|
||||
|
||||
@@ -10,7 +9,6 @@ class CQueryBindCapture {
|
||||
|
||||
private final CQueryPlan cQueryPlan;
|
||||
private final QueryPlanLogger planLogger;
|
||||
private final boolean enabled;
|
||||
|
||||
private BindCapture bindCapture;
|
||||
private long queryTimeMicros;
|
||||
@@ -19,18 +17,16 @@ class CQueryBindCapture {
|
||||
|
||||
private long lastBindCapture;
|
||||
|
||||
|
||||
CQueryBindCapture(CQueryPlan cQueryPlan, ServerConfig serverConfig) {
|
||||
CQueryBindCapture(CQueryPlan cQueryPlan, QueryPlanLogger planLogger) {
|
||||
this.cQueryPlan = cQueryPlan;
|
||||
this.enabled = serverConfig.isCollectQueryPlans();
|
||||
this.planLogger = PlatformQueryPlan.getLogger(serverConfig.getDatabasePlatform().getPlatform());
|
||||
this.planLogger = planLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if we should capture the bind values for this query.
|
||||
*/
|
||||
boolean collectFor(long timeMicros) {
|
||||
return enabled && (bindCapture == null || timeMicros > thresholdMicros);
|
||||
return (bindCapture == null || timeMicros > thresholdMicros);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,15 +51,12 @@ class CQueryBindCapture {
|
||||
*/
|
||||
void collectQueryPlan(QueryPlanRequest request) {
|
||||
|
||||
if (request.getSince() > lastBindCapture) {
|
||||
if (bindCapture == null || request.getSince() > lastBindCapture) {
|
||||
// no bind capture since the last capture
|
||||
return;
|
||||
}
|
||||
|
||||
final BindCapture last = this.bindCapture;
|
||||
if (last == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DQueryPlanOutput queryPlan = planLogger.logQueryPlan(request.getConnection(), cQueryPlan, last);
|
||||
queryPlan.with(queryTimeMicros, captureCount, cQueryPlan.getPlanKey().toString());
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.query;
|
||||
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.bean.ObjectGraphNode;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.SqlLimitResponse;
|
||||
import io.ebean.meta.MetricType;
|
||||
import io.ebean.meta.QueryPlanRequest;
|
||||
@@ -121,7 +122,7 @@ public class CQueryPlan {
|
||||
this.encryptedProps = sqlTree.getEncryptedProps();
|
||||
this.stats = new CQueryPlanStats(this, server.isCollectQueryOrigins());
|
||||
this.dependentTables = sqlTree.dependentTables();
|
||||
this.bindCapture = new CQueryBindCapture(this, server.getServerConfig());
|
||||
this.bindCapture = initBindCapture(server.getServerConfig(), query);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +148,15 @@ public class CQueryPlan {
|
||||
this.encryptedProps = sqlTree.getEncryptedProps();
|
||||
this.stats = new CQueryPlanStats(this, server.isCollectQueryOrigins());
|
||||
this.dependentTables = (rawSql) ? Collections.emptySet() : sqlTree.dependentTables();
|
||||
this.bindCapture = new CQueryBindCapture(this, server.getServerConfig());
|
||||
this.bindCapture = initBindCapture(server.getServerConfig(), query);
|
||||
}
|
||||
|
||||
private CQueryBindCapture initBindCapture(ServerConfig serverConfig, SpiQuery<?> query) {
|
||||
if (serverConfig.isCollectQueryPlans() && !query.getType().isUpdate()) {
|
||||
return new CQueryBindCapture(this, PlatformQueryPlan.getLogger(serverConfig.getDatabasePlatform().getPlatform()));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String location() {
|
||||
@@ -289,7 +298,7 @@ public class CQueryPlan {
|
||||
server.collectQueryStats(objectGraphNode, loadedBeanCount, timeMicros);
|
||||
}
|
||||
|
||||
return bindCapture.collectFor(timeMicros);
|
||||
return bindCapture != null && bindCapture.collectFor(timeMicros);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,7 +343,7 @@ public class CQueryPlan {
|
||||
|
||||
public void collectQueryPlan(QueryPlanRequest request) {
|
||||
|
||||
if (!getSql().equals(RESULT_SET_BASED_RAW_SQL)) {
|
||||
if (!getSql().equals(RESULT_SET_BASED_RAW_SQL) && bindCapture != null) {
|
||||
bindCapture.collectQueryPlan(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user