performance of union versus union all

后端 未结 5 2053
忘掉有多难
忘掉有多难 2020-12-18 18:55

I have to run a select statement across several tables. I am sure the tables return different records. I am anyway using UNION ALL.

Is it better to use UNION or of U

5条回答
  •  别那么骄傲
    2020-12-18 19:28

    UNION implement internally two queries. 1.SELECT which will return a dataset 2.DISTINCT. Anyone who has studied database internals can easily understand that a DISTINCT clause is extremely costly in terms of processing.

    If you are pretty sure that the resultant dataset need not have unique rows then we can skip UNION and use UNION ALL instead.

    UNION ALL will be same as UNION except that it doesn't fire a DISTINCT internally sparing us costly operations

提交回复
热议问题