I have a view containing UNION ALL. For instance:
CRATE VIEW myView as
(SELECT col1, col2, col3
FROM tab1)
UNION ALL
(SELECT col1, col2, col3
FROM tab2)
These are large tables containing 10 milliseconds each. If I write:
SELECT *
FROM myView
LIMIT 1;
instead of being immediate, in principle, it never returns, like other requests written against this submission. If I use LIMIT in a query for individual base tables, this is immediate. I have indexes on base tables. It seems that MySQL creates the entire aggregate data set (queries in the view) for presentation before applying any filtering criteria. This is madness. So does MySQL optimize view queries? By the way, I can’t even run an explanation plan against a presentation because it never returns.