Aikesheng Open Source Community
Mar 3, 2020 · Databases
Optimizing a Slow MySQL Query with Derived Tables and UNION ALL
This article analyzes a slow MySQL aggregation query that joins a large table with a derived table built from many UNION ALL subqueries, explains the execution plan and derived‑table materialization, and presents two optimization approaches—adding taskname indexes and rewriting the query or using a temporary indexed table—to dramatically reduce execution time while preserving result semantics.
Derived TableIndexMySQL
0 likes · 11 min read