SELECT A.Id, AMerge.FeildA, AMerge.FeildB, AMerge.FeildC, BMerge.FeildD, BMerge.FeildE, BMerge.FeildF,
FROM
(SELECT Id, FieldA, FieldB, FieldC from A1
UNION ALL
SELECT Id, FieldA, FieldB, FieldC from A2
) AS A
INNER JOIN
(
SELECT Id, FieldD, FieldE, FieldF FROM B1
UNION ALL
SELECT Id, FieldD, FieldE, FieldF FROM B2
) AS B
ON A.Id = B.Id
其中 A 的 n = 8102869,B 的 n = 17935860,导致表大小 n=17935860。
如何重构此查询以提高效率,或者我可以对表或数据库执行哪些流程以提高上述查询的性能?