diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-11-17 07:11:13 -0800 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-11-17 07:11:13 -0800 |
commit | 29b3e548f32c42cb99d9dd2d03c2cd34fa53d867 (patch) | |
tree | 02cd996daf61b43ad69e1fc21a80cf0218336f68 /activerecord | |
parent | 7da5d8a5dc0116dabc395cb25482adf3d733d597 (diff) | |
download | rails-29b3e548f32c42cb99d9dd2d03c2cd34fa53d867.tar.gz rails-29b3e548f32c42cb99d9dd2d03c2cd34fa53d867.tar.bz2 rails-29b3e548f32c42cb99d9dd2d03c2cd34fa53d867.zip |
Improve the performance of quoting table names on PG
This caused a pretty major performance regression for 4.2, as this is a
hotspot for query construction. We're still slightly slower than 4.1,
but it's much less significant.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/utils.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb b/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb index 0290bcb48c..9a0b80d7d3 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb @@ -18,7 +18,11 @@ module ActiveRecord end def quoted - parts.map { |p| PGconn.quote_ident(p) }.join SEPARATOR + if schema + PGconn.quote_ident(schema) << SEPARATOR << PGconn.quote_ident(identifier) + else + PGconn.quote_ident(identifier) + end end def ==(o) @@ -32,8 +36,11 @@ module ActiveRecord protected def unquote(part) - return unless part - part.gsub(/(^"|"$)/,'') + if part && part.start_with?('"') + part[1..-2] + else + part + end end def parts @@ -57,7 +64,11 @@ module ActiveRecord # * <tt>"schema_name".table_name</tt> # * <tt>"schema.name"."table name"</tt> def extract_schema_qualified_name(string) - table, schema = string.scan(/[^".\s]+|"[^"]*"/)[0..1].reverse + schema, table = string.scan(/[^".\s]+|"[^"]*"/) + if table.nil? + table = schema + schema = nil + end PostgreSQL::Name.new(schema, table) end end |