BobBuck
2012-Sep-11 18:21 UTC
question about how to set up an active record adapter to prefer use of prepared statements...
Hi, I am writing an active record adapter for our new database and when I run the tests I see lots of statements that could be run as prepared statements, but instead of passing me bindings AR passes me a fully specialized SQL string, not in all cases, but in many. Here is an example: SELECT addrs.* FROM addrs WHERE addrs.user_id = 153 FETCH FIRST 1 ROWS ONLY I do have this hook set up: def supports_statement_cache? trueend And I added this, but I am not familiar with its function, copying from another driver: if @config.fetch(:prepared_statements) { true } @visitor = Arel::Visitors::NuoDB.new self else @visitor = BindSubstitution.new self end Is there anything I need to do to get more statements run as prepared statements instead of ordinary ones? Thanks in advance, Bob -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/hrGxhA-lYyEJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
BobBuck
2012-Sep-17 16:04 UTC
Re: question about how to set up an active record adapter to prefer use of prepared statements...
Is there anyone available that could answer the question I asked? Or is there a better forum to ask these sorts of questions? Bob On Sep 11, 2:21 pm, BobBuck <rb...@nuodb.com> wrote:> Hi, > > I am writing an active record adapter for our new database and when I run > the tests I see lots of statements that could be run as prepared > statements, but instead of passing me bindings AR passes me a fully > specialized SQL string, not in all cases, but in many. Here is an example: > > SELECT addrs.* FROM addrs WHERE addrs.user_id = 153 FETCH FIRST 1 ROWS ONLY > > I do have this hook set up: > > def supports_statement_cache? > trueend > > And I added this, but I am not familiar with its function, copying from > another driver: > > if @config.fetch(:prepared_statements) { true } > @visitor = Arel::Visitors::NuoDB.new self > else > @visitor = BindSubstitution.new self > end > > Is there anything I need to do to get more statements run as prepared > statements instead of ordinary ones? > > Thanks in advance, > > Bob-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Aaron Patterson
2012-Sep-23 20:36 UTC
Re: question about how to set up an active record adapter to prefer use of prepared statements...
On Tue, Sep 11, 2012 at 11:21:19AM -0700, BobBuck wrote:> > > Hi, > > I am writing an active record adapter for our new database and when I run > the tests I see lots of statements that could be run as prepared > statements, but instead of passing me bindings AR passes me a fully > specialized SQL string, not in all cases, but in many. Here is an example: > > SELECT addrs.* FROM addrs WHERE addrs.user_id = 153 FETCH FIRST 1 ROWS ONLY > > I do have this hook set up: > > def supports_statement_cache? > trueend > > And I added this, but I am not familiar with its function, copying from > another driver: > > if @config.fetch(:prepared_statements) { true } > @visitor = Arel::Visitors::NuoDB.new self > else > @visitor = BindSubstitution.new self > end > > Is there anything I need to do to get more statements run as prepared > statements instead of ordinary ones?IIRC, this should be it. We don''t have all statements using bind values with AR (yet). Try testing with code like this: SomeModel.find(1) -- Aaron Patterson http://tenderlovemaking.com/
BobBuck
2012-Sep-23 21:33 UTC
Re: question about how to set up an active record adapter to prefer use of prepared statements...
Thank you, Aaron. On Sep 23, 4:36 pm, Aaron Patterson <tenderl...@ruby-lang.org> wrote:> On Tue, Sep 11, 2012 at 11:21:19AM -0700, BobBuck wrote: > > > Hi, > > > I am writing an active record adapter for our new database and when I run > > the tests I see lots of statements that could be run as prepared > > statements, but instead of passing me bindings AR passes me a fully > > specialized SQL string, not in all cases, but in many. Here is an example: > > > SELECT addrs.* FROM addrs WHERE addrs.user_id = 153 FETCH FIRST 1 ROWS ONLY > > > I do have this hook set up: > > > def supports_statement_cache? > > trueend > > > And I added this, but I am not familiar with its function, copying from > > another driver: > > > if @config.fetch(:prepared_statements) { true } > > @visitor = Arel::Visitors::NuoDB.new self > > else > > @visitor = BindSubstitution.new self > > end > > > Is there anything I need to do to get more statements run as prepared > > statements instead of ordinary ones? > > IIRC, this should be it. We don''t have all statements using bind values > with AR (yet). Try testing with code like this: SomeModel.find(1) > > -- > Aaron Pattersonhttp://tenderlovemaking.com/ > > application_pgp-signature_part > < 1KViewDownload-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.