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 22:23:56 -0200 |
commit | d70539c1ec4c1f615bb359468b7b0c58276bf71b (patch) | |
tree | 7a1988101dc6bd366e897a82f0875fb96f726aa8 /activerecord/lib/active_record | |
parent | fbf23ed9338f935736dd840ea973fd6372b6ab7d (diff) | |
download | rails-d70539c1ec4c1f615bb359468b7b0c58276bf71b.tar.gz rails-d70539c1ec4c1f615bb359468b7b0c58276bf71b.tar.bz2 rails-d70539c1ec4c1f615bb359468b7b0c58276bf71b.zip |
Merge pull request #8417 from kennyj/fix_8414
Fix #8414. Performance problem with postgresql adapter primary_key function.
Conflicts:
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 08ef704752..5a53135901 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -988,12 +988,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 |