Skip to content

Instantly share code, notes, and snippets.

@jcalvert
Created December 15, 2011 23:41
Show Gist options
  • Save jcalvert/1483515 to your computer and use it in GitHub Desktop.
Save jcalvert/1483515 to your computer and use it in GitHub Desktop.
arjdbc + postgres = slow?
alias_chained_method :columns, :query_cache, :pg_columns
def pg_columns(table_name, name=nil)
val = nil
Benchmark.bm do |r|
r.report do
schema_name = @config[:schema_search_path]
if table_name =~ /\./
parts = table_name.split(/\./)
table_name = parts.pop
schema_name = parts.join(".")
end
schema_list = if schema_name.nil?
[]
else
schema_name.split(/\s*,\s*/)
end
while schema_list.size > 1
s = schema_list.shift
begin
val = @connection.columns_internal(table_name, name, s)
rescue ActiveRecord::JDBCError=>ignored_for_next_schema
end
end
if val.nil?
s = schema_list.shift
val= @connection.columns_internal(table_name, name, s)
end
end
end
return val
end
---------
$ rails c
Using ActiveModel validations.
Loading development environment (Rails 3.0.9)
/Users/jcalvert/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/irb/input-method.rb:108 warning: Ignoring internal encoding UTF-8: it is identical to external encoding UTF-8
/Users/jcalvert/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/irb/input-method.rb:109 warning: Ignoring internal encoding UTF-8: it is identical to external encoding UTF-8
jruby-1.6.5 :001 > u = User.last
user system total real
3.794000 0.000000 3.794000 ( 3.794000)
=> #<User id: 22536649, email: "[email protected]", ...
def pg_columns(table_name, name=nil)
schema_name = @config[:schema_search_path]
if table_name =~ /\./
parts = table_name.split(/\./)
table_name = parts.pop
schema_name = parts.join(".")
end
schema_list = if schema_name.nil?
[]
else
schema_name.split(/\s*,\s*/)
end
while schema_list.size > 1
s = schema_list.shift
begin
return @connection.columns_internal(table_name, name, s)
rescue ActiveRecord::JDBCError=>ignored_for_next_schema
end
end
s = schema_list.shift
return @connection.columns_internal(table_name, name, s)
end
def columns(table_name, name = nil)
# Limit, precision, and scale are all handled by the superclass.
val = nil
Benchmark.bm do |r|
r.report do
val = column_definitions(table_name).collect do |name, type, default, notnull|
PostgreSQLColumn.new(name, default, type, notnull == 'f')
end
end
end
return val
end
----
jcalvert$ rails c
Using ActiveModel validations.
Loading development environment (Rails 3.0.9)
ruby-1.9.2-p290 :001 > u = User.last
user system total real
0.000000 0.000000 0.000000 ( 0.052154)
=> #<User id: 22536649, email: "[email protected]", ....
@jcalvert
Copy link
Author

jcalvert commented Aug 7, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment