aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters
diff options
context:
space:
mode:
authorJordan Lewis <jordanthelewis@gmail.com>2017-02-10 02:35:24 -0500
committerJordan Lewis <jordanthelewis@gmail.com>2017-02-13 15:20:21 -0500
commitb8e3af79ed0c2121c11bbb675dbf47126e95e0a0 (patch)
tree0eef428894b74cb1d87c08c9e238846243cd8aad /activerecord/test/cases/adapters
parentb9bee5e895e218b17a5f4ad72c3cbf6204fa4145 (diff)
downloadrails-b8e3af79ed0c2121c11bbb675dbf47126e95e0a0.tar.gz
rails-b8e3af79ed0c2121c11bbb675dbf47126e95e0a0.tar.bz2
rails-b8e3af79ed0c2121c11bbb675dbf47126e95e0a0.zip
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.
Diffstat (limited to 'activerecord/test/cases/adapters')
-rw-r--r--activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb6
-rw-r--r--activerecord/test/cases/adapters/postgresql/schema_test.rb8
2 files changed, 0 insertions, 14 deletions
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")
diff --git a/activerecord/test/cases/adapters/postgresql/schema_test.rb b/activerecord/test/cases/adapters/postgresql/schema_test.rb
index 8756507531..7b065ff320 100644
--- a/activerecord/test/cases/adapters/postgresql/schema_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/schema_test.rb
@@ -366,14 +366,6 @@ class SchemaTest < ActiveRecord::PostgreSQLTestCase
end
end
- def test_primary_key_raises_error_if_table_not_found_on_schema_search_path
- with_schema_search_path(SCHEMA2_NAME) do
- assert_raises(ActiveRecord::StatementInvalid) do
- @connection.primary_key(PK_TABLE_NAME)
- end
- end
- end
-
def test_pk_and_sequence_for_with_schema_specified
pg_name = ActiveRecord::ConnectionAdapters::PostgreSQL::Name
[