Subject Re: [Firebird-Java] Get execution plan through JDBC
Author Mark Rotteveel
On 02 Mar 2014 14:01:18 -0800, <IJFQSFTGESJU@...> wrote:
> Hello,
> how can I get the execution plan of a query through JDBC (using Jaybird
&
> Firebird)?
>
> In Postgres or Oracle I can simply run "explain" and get a ResultSet
back
> when using executeQuery().
> As far as I can tell there is no "explain" or "explain plan" in
Firebird,
> so how can I retrieve the execution plan for an arbitrary SQL statement
> (available as a String)?

You can use

Statement stmt = ...;
FirebirdStatement fbstmt = stmt.unwrap(FirebirdStatement .class); // or:
FirebirdStatement fbstmt = (FirebirdStatement ) stmt;
fbstmt.getLastExecutionPlan();

This works for all statement types, with a 'normal' statement this only
works after you executed the statement. With a PreparedStatement or
CallableStatement it always works. For a PreparedStatement or
CallableStatement you can also cast (or unwrap) to
FirebirdPreparedStatement (or FirebirdCallableStatement) and call
getExecutionPlan().

A ResultSet when cast or unwrapped to FirebirdResultSet also has a
getExecutionPlan() method.

In all cases the return type is a string with the Firebird plan.

Mark