MySQL中使用UNION进行两表合并,去重导致效率低下,请问如何优化?

如下SQL语句在MySQL中执行需要2秒左右的时间,如果使用UNION ALL进行不去重合并只需要0.4秒,UNION ALL配合DISTINCT来去重速度又变成2秒了,请问如何进行优化?

SELECT
    a. KEY,
    a. DATA,
    a.date_added
FROM
    (
        (
            SELECT
                CONCAT('customer_', ca. KEY) AS `key`,
                ca. DATA,
                ca.date_added
            FROM
                `cf_customer_activity` ca
        )
        UNION
            (
                SELECT
                    CONCAT('affiliate_', aa. KEY) AS `key`,
                    aa. DATA,
                    aa.date_added
                FROM
                    `cf_affiliate_activity` aa
            )
    ) a
ORDER BY
    a.date_added DESC
LIMIT 0,
 5;

查看回复