diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-04 09:25:16 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-04 09:25:16 -0800 |
commit | 2715c4a19a15ba075d3932c093a34d5067a80dd4 (patch) | |
tree | 5aa89d8c52124cfff66048711ed302e26abbf768 /activerecord/lib/active_record/connection_adapters | |
parent | 40e16121c05f10f9b75b6cd68c32092876142861 (diff) | |
parent | 634d28e6cf536d2135e1dfd32a58a57441608216 (diff) | |
download | rails-2715c4a19a15ba075d3932c093a34d5067a80dd4.tar.gz rails-2715c4a19a15ba075d3932c093a34d5067a80dd4.tar.bz2 rails-2715c4a19a15ba075d3932c093a34d5067a80dd4.zip |
Merge pull request #8417 from kennyj/fix_8414
Fix #8414. Performance problem with postgresql adapter primary_key function.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 9f7086cd07..18bf14d1fb 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -305,12 +305,11 @@ module ActiveRecord # Returns just a table's primary key def primary_key(table) row = exec_query(<<-end_sql, 'SCHEMA').rows.first - SELECT DISTINCT(attr.attname) + SELECT attr.attname FROM pg_attribute attr - INNER JOIN pg_depend dep ON attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1] WHERE cons.contype = 'p' - AND dep.refobjid = '#{quote_table_name(table)}'::regclass + AND cons.conrelid = '#{quote_table_name(table)}'::regclass end_sql row && row.first |