lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

* Joshua Jensen:

> Sure, but I deal in lots of binary data.  While I don't understand the
> network protocols of the databases I use, there is a much better
> chance my binary data bound to the prepared statement is going to be
> handled in a much more optimal way than escaping the binary and
> compiling/sending it that way.

The performance advantage is especially noticeable with PostgreSQL
because of the way embedded binary data has to be encoded in queries.
(But the binding author needs to know about this and add a flag to
pass unquoted binary data parameters over the wire.)

> Plus, with prepared statements, you don't have to deal with escaping
> anything.  It's a double win... ease of use and performance.

It's less clear if prepared statements are a win performancewise (as
opposed to mere parametrized queries).  Some loads only benefit if you
pre-plan queries (without knowledge of the actual parameter values),
others suffer tremendously compared to non-prepared statements because
those additional constants (coming from parameters) really help the
optimizers to choose better plans.

As a general rule, I tend to avoid prepared statements, except for
bulk loads.