Google Groups Home
Help | Sign in
Message from discussion Request for comments: prepared statements in ActiveRecord
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Hongli Lai  
View profile
 More options May 14 2007, 2:40 pm
From: Hongli Lai <hongli...@gmail.com>
Date: Mon, 14 May 2007 11:40:41 -0700
Local: Mon, May 14 2007 2:40 pm
Subject: Re: Request for comments: prepared statements in ActiveRecord
On May 14, 8:25 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com>
wrote:

> So, every query ever issued will become a prepared statement. Isn't this
> going to lead to unnecessary overhead? I mean, there are *a lot* of various
> SELECT statements generated by even a simple Rails application. Does it
> really make sense to prepare every one of them? Having backends cache the
> execution plan for rare SELECTs can possibly have undesirable overhead.
> Also, how will ActiveRecord know how to reuse these statements? For example:

>   a = Author.find(1)
>   post = Author.posts.first
>   post.author

> The first and the last query are different to AR, yet they take a same shape
> ("SELECT * FROM authors WHERE authors.id = ?") and can both be represented
> by a single prepared statement. With your solution, will AR know how to
> reuse the prepared statement in different places, or will it try to prepare
> it twice?

The current implementation immediately removes prepared statements
after using them once, so they will be reparsed twice. Right now I'm
trying to make it actually work and getting the framework in place.
Optimization can be done later (and I'm fairly confident that it can
be optimized).
In the future I can add caching. The cache will have a limited size,
and items can be removed based on least-recently-used or some other
criteria, similar to how CPU caches work.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google