diff options
author | kennyj <kennyj@gmail.com> | 2012-12-05 01:12:46 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-12-05 02:19:03 +0900 |
commit | 634d28e6cf536d2135e1dfd32a58a57441608216 (patch) | |
tree | 9ed13a7f0e576a490518afb84af4862017dbd7f3 /activerecord/lib/active_record | |
parent | d3f4625aed505353573960526f2a40f753f205a1 (diff) | |
download | rails-634d28e6cf536d2135e1dfd32a58a57441608216.tar.gz rails-634d28e6cf536d2135e1dfd32a58a57441608216.tar.bz2 rails-634d28e6cf536d2135e1dfd32a58a57441608216.zip |
Fix #8414. Performance problem with postgresql adapter primary_key function.
Diffstat (limited to 'activerecord/lib/active_record')
-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 |