Slow execution with MariaDB
I suspect the combined query is not doing what you think it is doing.

Add parentheses to make it clear whether the second ORDER BY belongs to the second SELECT or to the UNION.  Ditto for the LIMIT.

( SELECT ...
)
UNION
( SELECT ... 
     -- Do the ORDER BY and LIMIT belong here?
) 
-- Or here (for the UNION)?


For further discussion, Please provide

EXPLAIN ...
SHOW CREATE TABLE ...
how big are the tables