ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Does the SQL processor skip unneeded Union Alls?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Does the SQL processor skip unneeded Union Alls?

    Code:
    select * from fileA
    union all
    select * from fileB
    union all
    select * from fileC
    fetch first 10 rows only;
    Consider the above code - results from 3 files merged together

    Say the first select statement returns 11 rows. That covers the "fetch first 10 rows only" clause, all 10 returned rows will be from the first select statement.
    Is the SQL processor smart enough to know it does not need to bother executing the second and third select statements?


  • #2
    Just check it with Visual Explain.
    But I assume it runs the SELECTs in paralell and merges them at the end and filters the first 10 rows.
    If you really need accessing the second and third table to be accessed only if there are not enough rows returned by the first SELECT, you should perform 3 statements.

    Birgitta

    Comment

    Working...
    X