2019-Emily

今天创建视图的时候,里面包含union ,select * from (select a from A union select b from B ),但是查询1000条数据,居然花了45s的时间,于是查询了资料,资料显示:

UNION 因为会将各查询子集的记录做比较,故比起UNION ALL ,通常速度都会慢上许多。一般来说,如果使用UNION ALL能满足要求的话,务必使用UNION ALL。 

而我的A表和B表不可能有重复数据,于是换成select * from (select a from A union all select b from B ),时间缩短到 了1s以内,长见识了。以前只知道union和union all的用法

而不知道它们的使用,居然对sql的效率影响如此之大。

分类:

技术点:

相关文章:

  • 2021-09-17
  • 2021-05-16
  • 2021-10-10
猜你喜欢
  • 2021-10-25
  • 2022-02-26
  • 2022-12-23
  • 2021-11-26
  • 2021-11-02
  • 2021-09-23
  • 2021-06-11
相关资源
相似解决方案