Union和Concat的区别,以及它们的速度 (C# Linq)
原文发布时间为:2011-06-29 —— 来源于本人的百度文章 [由搬家工具导入]
Union 会去重复后合并。而Contact不去重直接合并。 所以Contact当然比较快了。所以如果你不用去重的时候,尽量用Contact做合并吧。
在SQL里面:Union uses 'UNION' while Concat uses 'UNION ALL'.
Union removes duplicates.Concat does not.
So, they produce different results if the sources either contain any items in common, or have any internal duplicates.
If you can guarantee there are no duplicates, or if there are few and you don't care about having them in your output, Concat will be faster since there's no need to test each value against what has already been yielded.
However, if there are many duplicates and you don't need them, the extra processing in Union to remove the dupes may be offset by the savings in your code that consumes the results.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步