Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"

The combination of a :uniq => true association and the #distinct call
in #construct_limited_ids_condition combine to create invalid SQL, because
we're explicitly selecting DISTINCT, and also sending #distinct on to AREL,
via the relation#distinct_value.

Rather than build a select distinct clause in #construct_limited_ids_condition,
I set #distinct! and pass just the columns into the select statement.
This requires introducing a #columns_for_distinct method to return the
select columns but not the statement itself.
Don't try to EXPLAIN select_db calls
Set the inverse when association queries are refined

Suppose Man has_many interests, and inverse_of is used.

Man.first.interests.first.man will correctly execute two queries,
avoiding the need for a third query when Interest#man is called. This is
because CollectionAssociation#first calls set_inverse_instance.

However Man.first.interests.where("1=1").first.man will execute three
queries, even though this is obviously a subset of the records in the
association.

This is because calling where("1=1") spawns a new Relation object from
the CollectionProxy object, and the Relation has no knowledge of the
association, so it cannot set the inverse instance.

This commit solves the problem by making relations spawned from
CollectionProxies return a new Relation subclass called
AssociationRelation, which does know about associations. Records loaded
from this class will get the inverse instance set properly.

Fixes #5717.

Live commit from La Conf! :sparkles:
Move #proxy_association method to AssociationRelation
Merge pull request #10554 from dasch/dasch/dont-try-to-explain-it-dont-matter

Don't try to EXPLAIN select_db calls
Don't modify args in TableDefinition#primary_key

Previously, if you reused a hash that was passed into a table definition,
then subsequent tables' primary keys would be set to "true" instead of "id".
Merge pull request #10572 from nertzy/dont-modify-options-hash-in-primary-key

Don't modify args in TableDefinition#primary_key
Merge pull request #10503 from kstevens715/master

Avoid method missing when calling assume_migrated_upto_version (master)

Conflicts:
	activerecord/CHANGELOG.md
Improve CHANGELOG entry [ci skip]
Deprecate SchemaStatements#distinct, and make SchemaStatements#columns_for_distinct nodoc.

#distinct was previously used by #construct_limited_ids_condition, but
no more after #6792. #columns_for_distinct is just a utility method for
#construct_limited_ids_condition and shouldn't be public.
specify that dom_(id|class) are deprecated in controllers, views are fine
respond_to -> respond to in a message from AM::Lint

The error message uses English to say that the object should respond
to a certain method. You check that with respond_to, but that's not
English.

This makes this error message also consistent with the rest.
Merge pull request #10556 from Empact/deprecate-schema-statements-distinct

Deprecate SchemaStatements#distinct, and make SchemaStatements#columns_for_distinct nodoc.
Merge pull request #10560 from jkutner/master

Remove jruby-openssl from default Gemfile
Merge pull request #10586 from AJ-Acevedo/comments

Updated comment to Rails 4
Merge pull request #10584 from alindeman/range-missing-alias-attribute

Fixes NoMethodError: `alias_method_chain` when requiring just active_support/core_ext
Update mail to minimum version 2.5.4
Revert "Merge pull request #10397 from BMorearty/remove-varargs-from-in-4-0-stable"

This reverts commit a8ef0bbb776b734b80853dfb3c7553d334cb9fe8, reversing
changes made to 1296adb90b3ffd478d988186bc82a96757b219db.

Reason: Partially revert this commit and properly deprecate #in? with
multiple arguments in 4-0.
Revert "Add the options method to action_controller testcase."

This reverts commit 0303c2325fab253adf5e4a0b738cb469c048f008.

Conflicts:
	actionpack/lib/action_controller/test_case.rb

REASON: It will conflict with a lot of test cases. Better to call
`process` directly since this is a very uncommon HTTP method.

Fixes #10638.
Merge pull request #10639 from cbartlett/master

Remove trailing line break in template