aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration/references_statements_test.rb
diff options
context:
space:
mode:
authorDerek Prior <derekprior@gmail.com>2014-02-21 11:33:36 -0500
committerDerek Prior <derekprior@gmail.com>2014-10-24 16:34:30 -0400
commit9cdd0a1fdf8308985231242d378e3a1c29c4ab00 (patch)
treee08b52e63109c2c5df044dde264de95e65023839 /activerecord/test/cases/migration/references_statements_test.rb
parent85faea4b8320e728854838c6da97c9435de8869e (diff)
downloadrails-9cdd0a1fdf8308985231242d378e3a1c29c4ab00.tar.gz
rails-9cdd0a1fdf8308985231242d378e3a1c29c4ab00.tar.bz2
rails-9cdd0a1fdf8308985231242d378e3a1c29c4ab00.zip
Use type column first in multi-column indexes
`add_reference` can very helpfully add a multi-column index when you use it to add a polymorphic reference. However, the first column in the index is the `id` column, which is less than ideal. The [PostgreSQL docs][1] say: > A multicolumn B-tree index can be used with query conditions that > involve any subset of the index's columns, but the index is most > efficient when there are constraints on the leading (leftmost) > columns. The [MySQL docs][2] say: > MySQL can use multiple-column indexes for queries that test all the > columns in the index, or queries that test just the first column, the > first two columns, the first three columns, and so on. If you specify > the columns in the right order in the index definition, a single > composite index can speed up several kinds of queries on the same > table. In a polymorphic relationship, the type column is much more likely to be useful as the first column in an index than the id column. That is, I'm more likely to query on type without an id than I am to query on id without a type. [1]: http://www.postgresql.org/docs/9.3/static/indexes-multicolumn.html [2]: http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html
Diffstat (limited to 'activerecord/test/cases/migration/references_statements_test.rb')
-rw-r--r--activerecord/test/cases/migration/references_statements_test.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/test/cases/migration/references_statements_test.rb b/activerecord/test/cases/migration/references_statements_test.rb
index b8b4fa1135..988bd9c89f 100644
--- a/activerecord/test/cases/migration/references_statements_test.rb
+++ b/activerecord/test/cases/migration/references_statements_test.rb
@@ -42,7 +42,7 @@ module ActiveRecord
def test_creates_polymorphic_index
add_reference table_name, :taggable, polymorphic: true, index: true
- assert index_exists?(table_name, [:taggable_id, :taggable_type])
+ assert index_exists?(table_name, [:taggable_type, :taggable_id])
end
def test_creates_reference_type_column_with_default