After reviewing this issue, I noticed that MySQL and MariaDB are taking advantage of UNION ALL in TABLE_PER_CLASS, falling back to using UNION which does an extra sort and duplicate removal that are not necessary.