On Monday, July 6, 2015 at 5:17:41 PM UTC-7, Rafe Colton wrote:
>
> Hello,
>
> Is it possible to run an explain plan on a prepared statement (in 
> postgres)?
>
> Let's say I have the following setup:
>
> ds = db['select * from my_table where id = ?', :$id]
> ps = ds.prepare(:select, :my_prepared_statement)
>
> I can do `ps.call(id: 123)` but as far as I can tell, there is no 
> equivalent syntax for explain.
>
> It is possible to do the explain manually, but there are multiple steps 
> and they are a bit clunky:
>
> # Step 1: create the prepared statement in the db - otherwise this is not 
> done until the ps.call, as far as I can tell
> db["prepare my_prepared_statement as #{ps.prepared_sql}"].all
>
> # Step 2: actually run the explain
> db["explain execute my_prepared_statement(123)"].all
>
> Ideally, there would be something like `ps.explain(id: 123)`.  Any advice?
>

Currently, this isn't supported.  It would be kind of tricky to implement, 
since you'd have to execute the prepare on the same connection before 
explaining it.  Because of Sequel's connection pooling, there isn't a 
separate method to prepare a query than there is to execute it, prepared 
statements are automatically prepared before execution if executed on a 
connection that doesn't have the prepared statement already cached.  I 
think in order to get this to work, you'd need to have Dataset#explain in 
the postgres adapter pass an :explain option through to execute so that 
#execute_prepared_statement could act on it, and have it automatically call 
EXPLAIN EXECUTE after optionally preparing the statement, but only if the 
pg driver is used.

I'm not sure how widely used this feature is.  Does anyone else need this?

I won't rule out including the feature, but I'd have to see a patch 
implementing it before I could say whether I would accept it.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to