mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
1476 - Query plan capture, initial wip capturing bind params (#1477)
* 1476 - Query plan capture, initial wip capturing bind params * No effective change - Reset test default db to H2 * #1476 - Query plan capture, initial wip capturing bind params #1477 Update with consumer * #1476 - Query plan capture, initial wip capturing bind params #1477 Update with query plan request * #1476 - Query plan capture, initial wip capturing bind params #1477 Extract interface * #1476 - Query plan capture, initial wip capturing bind params #1477 Extract interface
This commit is contained in:
@@ -4,6 +4,7 @@ import io.ebean.ProfileLocation;
|
||||
import io.ebean.bean.ObjectGraphNode;
|
||||
import io.ebean.config.dbplatform.SqlLimitResponse;
|
||||
import io.ebean.meta.MetricType;
|
||||
import io.ebean.meta.QueryPlanRequest;
|
||||
import io.ebean.metric.MetricFactory;
|
||||
import io.ebean.metric.TimedMetric;
|
||||
import io.ebeaninternal.api.CQueryPlanKey;
|
||||
@@ -13,6 +14,7 @@ import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import io.ebeaninternal.server.core.timezone.DataTimeZone;
|
||||
import io.ebeaninternal.server.query.CQueryPlanStats.Snapshot;
|
||||
import io.ebeaninternal.server.type.DataBind;
|
||||
import io.ebeaninternal.server.type.DataBindCapture;
|
||||
import io.ebeaninternal.server.type.DataReader;
|
||||
import io.ebeaninternal.server.type.RsetDataReader;
|
||||
import io.ebeaninternal.server.type.ScalarDataReader;
|
||||
@@ -50,6 +52,8 @@ public class CQueryPlan {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CQueryPlan.class);
|
||||
|
||||
public static final String RESULT_SET_BASED_RAW_SQL = "--ResultSetBasedRawSql";
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
private final boolean autoTuned;
|
||||
@@ -92,6 +96,8 @@ public class CQueryPlan {
|
||||
|
||||
private final Set<String> dependentTables;
|
||||
|
||||
private final CQueryBindCapture bindCapture;
|
||||
|
||||
/**
|
||||
* Create a query plan based on a OrmQueryRequest.
|
||||
*/
|
||||
@@ -115,6 +121,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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,6 +147,7 @@ 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());
|
||||
}
|
||||
|
||||
private String location() {
|
||||
@@ -193,6 +201,16 @@ public class CQueryPlan {
|
||||
return dataBind;
|
||||
}
|
||||
|
||||
private DataBindCapture bindCapture() throws SQLException {
|
||||
DataBindCapture dataBind = DataBindCapture.of(dataTimeZone);
|
||||
if (encryptedProps != null) {
|
||||
for (STreeProperty encryptedProp : encryptedProps) {
|
||||
dataBind.setString(encryptedProp.getEncryptKeyAsString());
|
||||
}
|
||||
}
|
||||
return dataBind;
|
||||
}
|
||||
|
||||
int getAsOfTableCount() {
|
||||
return asOfTableCount;
|
||||
}
|
||||
@@ -263,13 +281,15 @@ public class CQueryPlan {
|
||||
/**
|
||||
* Register an execution time against this query plan;
|
||||
*/
|
||||
void executionTime(long loadedBeanCount, long timeMicros, ObjectGraphNode objectGraphNode) {
|
||||
boolean executionTime(long loadedBeanCount, long timeMicros, ObjectGraphNode objectGraphNode) {
|
||||
|
||||
stats.add(loadedBeanCount, timeMicros, objectGraphNode);
|
||||
if (objectGraphNode != null) {
|
||||
// collect stats based on objectGraphNode for lazy loading reporting
|
||||
server.collectQueryStats(objectGraphNode, loadedBeanCount, timeMicros);
|
||||
}
|
||||
|
||||
return bindCapture.collectFor(timeMicros);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,4 +320,22 @@ public class CQueryPlan {
|
||||
public TimedMetric createTimedMetric() {
|
||||
return MetricFactory.get().createTimedMetric(MetricType.ORM, label);
|
||||
}
|
||||
|
||||
void captureBindForQueryPlan(CQueryPredicates predicates, long executionTimeMicros) {
|
||||
try {
|
||||
DataBindCapture capture = bindCapture();
|
||||
predicates.bind(capture);
|
||||
bindCapture.setBind(capture.bindCapture(), executionTimeMicros);
|
||||
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error capturing bind values", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void collectQueryPlan(QueryPlanRequest request) {
|
||||
|
||||
if (!getSql().equals(RESULT_SET_BASED_RAW_SQL)) {
|
||||
bindCapture.collectQueryPlan(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user