From 4794a9a6c18439657a2f888d394a85ae93368190 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Mon, 16 Mar 2015 12:52:02 +0000 Subject: Materialize subqueries by adding `DISTINCT` to support MySQL 5.7.6 `optimizer_switch='derived_merge=on'` --- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 9625fcf9b8..7e41772227 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -785,7 +785,9 @@ module ActiveRecord subselect = Arel::SelectManager.new(select.engine) subselect.project Arel.sql(key.name) - subselect.from subsubselect.as('__active_record_temp') + # Materialized subquery by adding distinct + # to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on' + subselect.from subsubselect.distinct.as('__active_record_temp') end def add_index_length(option_strings, column_names, options = {}) -- cgit v1.2.3