1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/migration
Derek Prior 9cdd0a1fdf
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
2014-10-24 16:34:30 -04:00
..
change_schema_test.rb add table.bigint support 2014-10-15 17:32:10 -07:00
change_table_test.rb Change the default null value for timestamps 2014-08-12 14:40:11 -06:00
column_attributes_test.rb
column_positioning_test.rb
columns_test.rb Be sure to reset PK name renamed in the test 2014-08-15 01:29:42 +09:00
command_recorder_test.rb
create_join_table_test.rb
foreign_key_test.rb Replace drop sql statement to drop_table method 2014-09-11 03:47:44 +09:00
helper.rb Bring original puts back after finishing tests 2014-08-29 10:34:26 +09:00
index_test.rb index_exists? with :name checks specified columns. 2014-08-13 11:44:58 +02:00
logger_test.rb
pending_migrations_test.rb rename MiniTest to Minitest 2014-08-02 21:30:28 +05:30
references_index_test.rb Use type column first in multi-column indexes 2014-10-24 16:34:30 -04:00
references_statements_test.rb Use type column first in multi-column indexes 2014-10-24 16:34:30 -04:00
rename_table_test.rb Added enable_extension! to helper 2014-09-05 21:20:17 +00:00
table_and_index_test.rb