brianhempel / active_record_union

UNIONs in ActiveRecord! Adds proper union and union_all methods to ActiveRecord::Relation.
Other
423 stars 41 forks source link

There are different results of UNION subqueries depending on mysql version #13

Closed c80609a closed 7 years ago

c80609a commented 7 years ago

It's not a gem bug, just a quick important note:

My development server (MySQL Ver 14.14 Distrib 5.6.17). But when I run the same code on production (mysql Ver 15.1 Distrib 5.5.47-MariaDB), I consistently get different results (different records order).

brianhempel commented 7 years ago

UNION is a set operation, so I'm not surprised that order isn't guaranteed.

Note that your different result orders could be because of a different query plan rather than a different database version--that is, on a larger dataset MySQL might use a different method to remove duplicates.