Refactor for query plan capture with initial threshold micros - part 3

Use QueryPlanInit
This commit is contained in:
rob bygrave
2019-12-24 02:02:11 +13:00
parent b854943a86
commit ec55b2f096
4 changed files with 28 additions and 12 deletions
@@ -146,7 +146,7 @@ public class CQueryPlan implements SpiQueryPlan {
this.encryptedProps = sqlTree.getEncryptedProps();
this.stats = new CQueryPlanStats(this);
this.dependentTables = sqlTree.dependentTables();
this.bindCapture = initBindCaptureRaw(sql);
this.bindCapture = initBindCaptureRaw(sql, query);
this.hash = md5Hash();
}
@@ -164,8 +164,8 @@ public class CQueryPlan implements SpiQueryPlan {
return query.getType().isUpdate() ? SpiQueryBindCapture.NOOP : server.createQueryBindCapture(this);
}
private SpiQueryBindCapture initBindCaptureRaw(String sql) {
return sql.equals(RESULT_SET_BASED_RAW_SQL) ? SpiQueryBindCapture.NOOP : server.createQueryBindCapture(this);
private SpiQueryBindCapture initBindCaptureRaw(String sql, SpiQuery<?> query) {
return sql.equals(RESULT_SET_BASED_RAW_SQL) || query.getType().isUpdate() ? SpiQueryBindCapture.NOOP : server.createQueryBindCapture(this);
}
private String location() {
@@ -61,12 +61,7 @@ public class CQueryPlanManager implements QueryPlanManager {
if (plans.isEmpty()) {
return emptyList();
}
long startNanos = System.nanoTime();
try {
return collectPlans(request);
} finally {
timeCollection.addSinceNanos(startNanos);
}
return collectPlans(request);
}
private List<MetaQueryPlan> collectPlans(QueryPlanRequest request) {
@@ -76,7 +71,6 @@ public class CQueryPlanManager implements QueryPlanManager {
req.nextCapture();
}
return req.getPlans();
} catch (SQLException e) {
log.error("Error during query plan collection", e);
return emptyList();
@@ -84,6 +78,11 @@ public class CQueryPlanManager implements QueryPlanManager {
}
public SpiDbQueryPlan collectPlan(Connection connection, SpiQueryPlan queryPlan, BindCapture last) {
return planLogger.collectPlan(connection, queryPlan, last);
long startNanos = System.nanoTime();
try {
return planLogger.collectPlan(connection, queryPlan, last);
} finally {
timeCollection.addSinceNanos(startNanos);
}
}
}
@@ -6,6 +6,7 @@ import io.ebean.Transaction;
import io.ebean.meta.MetaQueryMetric;
import io.ebean.meta.MetaQueryPlan;
import io.ebean.meta.MetaTimedMetric;
import io.ebean.meta.QueryPlanInit;
import io.ebean.meta.QueryPlanRequest;
import io.ebean.meta.ServerMetrics;
import io.ebean.meta.SortMetric;
@@ -174,6 +175,17 @@ public class TestCustomerFinder extends BaseTestCase {
ResetBasicData.reset();
// the server has some plans
runQueries();
// enable query plan bind capture on all plans threshold 100 micros
QueryPlanInit init = new QueryPlanInit();
init.setAll(true);
init.setThresholdMicros(100);
final List<MetaQueryPlan> appliedToPlans = server().getMetaInfoManager().queryPlanInit(init);
assertThat(appliedToPlans.size()).isGreaterThan(4);
// will collect bind captures
runQueries();
ServerMetrics metrics = server().getMetaInfoManager().collectMetrics();
@@ -189,6 +201,7 @@ public class TestCustomerFinder extends BaseTestCase {
System.out.println(txnTimed);
}
// obtains db query plans ...
QueryPlanRequest request = new QueryPlanRequest();
List<MetaQueryPlan> plans = server().getMetaInfoManager().queryPlanCollectNow(request);
assertThat(plans).isNotEmpty();
@@ -294,6 +307,10 @@ public class TestCustomerFinder extends BaseTestCase {
Customer.find.totalCount();
Customer.find.updateNames("Junk", 2000);
Customer.find.byId(3);
DB.find(Customer.class)
.setLabel("someDeleteQuery")
.where().eq("name", "JunkNotExists")
.delete();
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ datasource.default=h2
ebean.dumpMetricsOnShutdown=true
ebean.dumpMetricsOptions=sql,hash
ebean.collectQueryPlanThresholdMicros=1000
#ebean.collectQueryPlanThresholdMicros=1000
ebean.collectQueryPlans=true
ebean.autoReadOnlyDataSource=true