1 Reply Latest reply on May 6, 2015 3:01 PM by Galo Balda

    Any difference for performance after union all or before union all

    makbolat

      Hi all,

      I have SQL 1. But I want to write it like SQL 2. But I have some reservations about the performance.

      Question is: Is the two sql performans same or difference. Does Oracle optimize the second one?

       

      SQL 1:

       

      SELECT FA1 F1, FA2 F1, FA3 F3 FROM TABLEA  WHERE FA1 BETWEEN CURRENT_DATE -30 AND CURRENT_DATE
      UNION ALL
      SELECT FB1 F1, FB2 F2, FB3 F3 FROM TABLEB WHERE FB1 BETWEEN CURRENT_DATE -30 AND CURRENT_DATE
      

       

       

      SQL 2:

       

      SELECT F1, F2, F3
      FROM (SELECT FA1 F1, FA2 F1, FA3 F3 FROM TABLEA
                  UNION ALL
                  SELECT FB1 F1, FB2 F2, FB3 F3 FROM TABLEB )
      WHERE F1 BETWEEN CURRENT_DATE -30 AND CURRENT_DATE