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:
Rob Bygrave
2018-12-19 16:04:28 +13:00
committed by GitHub
parent e611353163
commit 94591954b3
108 changed files with 1908 additions and 233 deletions
@@ -0,0 +1,31 @@
package io.ebeaninternal.server.query;
import io.ebeaninternal.server.type.bindcapture.BindCapture;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* A QueryPlanlogger that prefixes "EXPLAIN " to the query. This works for Postgres, H2 and MySql.
*/
public class QueryPlanLoggerPostgres extends QueryPlanLogger {
@Override
public DQueryPlanOutput logQueryPlan(Connection conn, CQueryPlan plan, BindCapture bind) {
String explain = "EXPLAIN " + plan.getSql();
try (PreparedStatement explainStmt = conn.prepareStatement(explain)) {
bind.prepare(explainStmt, conn);
try (ResultSet rset = explainStmt.executeQuery()) {
return readQueryPlanBasic(plan, bind, rset);
}
} catch (SQLException e) {
queryPlanLog.error("Could not log query plan: " + explain, e);
throw new IllegalStateException("Failed to obtain explain plan: " + explain, e);
}
}
}