brianhempel / active_record_union

UNIONs in ActiveRecord! Adds proper union and union_all methods to ActiveRecord::Relation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

There are different results of UNION subqueries depending on mysql version

c80609a opened this issue · comments

commented

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).

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.