前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Union和Concat的区别,以及它们的速度 (C# Linq)

Union和Concat的区别,以及它们的速度 (C# Linq)

作者头像
javascript.shop
发布2019-09-04 15:48:34
2K0
发布2019-09-04 15:48:34
举报
文章被收录于专栏:杰的记事本

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.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2009年8月1日20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档