Forum: Ruby on Rails Prepared statements, bind variables, and bikesheds (was Re:

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2007-02-15 17:00
(Received via mailing list)
On 2/15/07, Wes Gamble <> wrote:
> I agree with some of your points.  However, I'd like to add that it is
> because I am "actually using Rails" (and have been for a year) that I
> find these features to be important.  I've been using prepared DB
> statements to optimize DB access for over 10 years on innumerable
> platforms/deployment scenarios and I don't have access to them in AR -
> feels like I'm taking a step back.

I apologize for the generalization. I don't mean to single you out.
I challenge the community to trash the bikeshed and conscientiously
the bits of Rails that suck the life out of you.

If the prospect of increased CPU consumption due to unprepared queries
you deep, hard, and oh so wrong, don't stop marking your hurt at some
words in a mailing list thread -- write the well-tested code to scream
out to the world!

Your apps-- all of ours-- will purr in thanks, memorializing your genius
forever ;-)

I'd love to work on this when I get some time.  As it stands, I've
> submitted two (admittedly small) patches on ActiveRecord::Base in the
> last 6 months.  Maybe I will give it a try.  Thanks for the
> encouragement.


It's probably easier than it seems: bind variables are emulated and
could be
pushed down to the adapter.
The adapter could prepare the statement in Adapter#sanitize_sql, cache
and return a SqlStatement < String holding both the query string and its
bound vars. Adapter#execute can pass bound vars directly to the db when
given a SqlStatement.

Thorough test coverage and broad database support are likely the greater

Be09addcbb47f2a684fa5c48bac94149?d=identicon&s=25 unknown (Guest)
on 2007-02-16 04:03
(Received via mailing list)
This has been tested, with the results posted to this list.  Check the
2nd half of 2006.

The tester used Postgres, and with a fairly crude setup reported
improvements of overall throughput from rails apps starting at 60
percent.  His alterations for testing  were mostly adaptable to other
SQL adapters, but not entirely portable.

He did a detailed timing breakdown of the ruby code versus the sql
engine, and determined that with prepared statements the bottleneck
changed   from the SQL to the ruby code.
This topic is locked and can not be replied to.