I wanted to quantify this difference, so I took a stab at it. Used a large dataset, and just performed a couple selects using fiscal year as the filters on each. I ran the same set of SELECTs, just changing the UNION to UNION ALL for the second iteration.
Conclusion is that UNION ALL is faster, but almost a negligible amount in this exercise. Likely to increase with result set size, but typically we'll be aggregating somewhat before the union even occurs.
SELECT COUNT(*)
FROM "SCHEMA_NAME"."CE12000"
WHERE "GJAHR" IN ('2013','2014')
RESULT -> 1,347,849,619
SELECT "GJAHR", "PERIO", "BUKRS", "SPART", "VKORG", "FKART", "WWMDC",SUM ("VVREV"),SUM("VVBBC")
FROM "SCHEMA_NAME"."CE12000"
WHERE "GJAHR" = '2013'
GROUP BY "GJAHR", "PERIO", "BUKRS", "SPART", "VKORG", "FKART","WWMDC"
UNION / (UNION ALL in second test)
SELECT "GJAHR", "PERIO", "BUKRS", "SPART", "VKORG", "FKART", "WWMDC",SUM ("VVREV"),SUM("VVBBC")
FROM "SCHEMA_NAME"."CE12000"
WHERE "GJAHR" = '2014'
GROUP BY "GJAHR", "PERIO", "BUKRS", "SPART","VKORG","FKART","WWMDC";
UNION DB average = 2.29s
UNION ALL DB average = 2.28s
The main difference from the VizPlan is the aggregation/de-duplication that takes place after the UNION. I was curious how this worked, so here are the plans.
UNION - notice the analytical search present after the union
UNION ALL - notice no analytical search, so it saves you the .01s
Regards,
Justin