Technically, you will need to do something similar to ensure that you will always get rows from TABLE_A and TABLE_B if they exist:
SELECT * FROM ( SELECT * FROM ( SELECT 'A' t, TABLE_A.* FROM TABLE_A WHERE ROWNUM <= 25 UNION ALL SELECT 'B' t, TABLE_B.* FROM TABLE_B WHERE ROWNUM <= 40 UNION ALL SELECT 'C' t, TABLE_C.* FROM TABLE_C ) ORDER BY t ) WHERE ROWNUM <= 100;
This is due to the fact that the optimizer is allowed to run subqueries in any order that he likes - for example. parallel.
As far as performance is concerned, I suspect that sort op will not add too much time to the run time, because it still sorts no more than 100 rows.
source share