From b8e3af79ed0c2121c11bbb675dbf47126e95e0a0 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Fri, 10 Feb 2017 02:35:24 -0500 Subject: Simplify and optimize Postgres query for primary_keys() primary_keys(table) needs to query various metadata tables in Postgres to determine the primary key for the table. Previously, it did so using a complex common table expression against pg_constraint and pg_attribute. This patch simplifies the query by using information_schema tables. This simplifies the logic, making the query far easier to understand, and additionally avoids an expensive unnest, window function query, and common table expression. --- .../test/cases/adapters/postgresql/postgresql_adapter_test.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb') diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 4de04646ed..3054f0271f 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -54,12 +54,6 @@ module ActiveRecord end end - def test_primary_key_raises_error_if_table_not_found - assert_raises(ActiveRecord::StatementInvalid) do - @connection.primary_key("unobtainium") - end - end - def test_exec_insert_with_returning_disabled connection = connection_without_insert_returning result = connection.exec_insert("insert into postgresql_partitioned_table_parent (number) VALUES (1)", nil, [], "id", "postgresql_partitioned_table_parent_id_seq") -- cgit v1.2.3