Merge pull request #3254 from ebean-orm/feature/query-plan-capture-yuga

Use DIST with query plan capture for Yugabyte plus simplify
This commit is contained in:
Rob Bygrave
2023-10-25 08:23:01 +13:00
committed by GitHub
3 changed files with 13 additions and 37 deletions
@@ -590,14 +590,16 @@ public final class InternalConfiguration {
*/
QueryPlanLogger queryPlanLogger(Platform platform) {
switch (platform.base()) {
case POSTGRES:
return new QueryPlanLoggerPostgres();
case SQLSERVER:
return new QueryPlanLoggerSqlServer();
case ORACLE:
return new QueryPlanLoggerOracle();
case POSTGRES:
return new QueryPlanLoggerExplain("explain (analyze, buffers) ");
case YUGABYTE:
return new QueryPlanLoggerExplain("explain (analyze, buffers, dist) ");
default:
return new QueryPlanLoggerExplain();
return new QueryPlanLoggerExplain("explain ");
}
}
@@ -17,9 +17,16 @@ import static java.lang.System.Logger.Level.WARNING;
*/
public final class QueryPlanLoggerExplain extends QueryPlanLogger {
private final String prefix;
public QueryPlanLoggerExplain(String prefix) {
this.prefix = prefix;
}
@SuppressWarnings("all")
@Override
public SpiDbQueryPlan collectPlan(Connection conn, SpiQueryPlan plan, BindCapture bind) {
try (PreparedStatement explainStmt = conn.prepareStatement("EXPLAIN " + plan.sql())) {
try (PreparedStatement explainStmt = conn.prepareStatement(prefix + plan.sql())) {
bind.prepare(explainStmt, conn);
try (ResultSet rset = explainStmt.executeQuery()) {
return readQueryPlan(plan, bind, rset);
@@ -1,33 +0,0 @@
package io.ebeaninternal.server.query;
import io.ebeaninternal.api.CoreLog;
import io.ebeaninternal.api.SpiDbQueryPlan;
import io.ebeaninternal.api.SpiQueryPlan;
import io.ebeaninternal.server.bind.capture.BindCapture;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import static java.lang.System.Logger.Level.WARNING;
/**
* A QueryPlanLogger for Postgres that prefixes "EXPLAIN ANALYZE" to the query.
*/
public final class QueryPlanLoggerPostgres extends QueryPlanLogger {
@Override
public SpiDbQueryPlan collectPlan(Connection conn, SpiQueryPlan plan, BindCapture bind) {
String explain = "explain (analyze, buffers) " + plan.sql();
try (PreparedStatement explainStmt = conn.prepareStatement(explain)) {
bind.prepare(explainStmt, conn);
try (ResultSet rset = explainStmt.executeQuery()) {
return readQueryPlanBasic(plan, bind, rset);
}
} catch (SQLException e) {
CoreLog.log.log(WARNING, "Could not log query plan: " + explain, e);
return null;
}
}
}