关于sql 查询性能优化的小经验

最近接到一些sql优化的任务。数据库类型:DB2

有一个长sql查询效率低,大概要几十秒,大概查询逻辑如下:

select * from tableA a where exists (select 1 from tableB b where a.id=b.id )

or exists (select 1 from tableC c where a.id=c.id );

tableA ,tableB ,tableC都是大表,数据量大,最终执行时间要几十秒,

但是把or 条件改成 union all 却可以大大提升执行效率,时间降到几秒:

select * from tableA a where exists (select 1 from tableB b where a.id=b.id )

union all

select * from tableA a where exists (select 1 from tableC c where a.id=c.id );

小结:union all 替换 or 条件, 有时候可以提高查询效率。

相关推荐
极限实验室9 小时前
Easysearch 2.0.0 性能测试
数据库·性能优化
卿雪11 小时前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
John_ToDebug11 小时前
深度解析:如何在 Chromium 中实现 SVG 渲染与优化
chrome·性能优化
QQ 192263813 小时前
采用整数规划的光储调度:光伏储能优化调度探究
sql
l1t14 小时前
利用Duckdb求解Advent of Code 2025第5题 自助餐厅
数据库·sql·mysql·算法·oracle·duckdb·advent of code
驾数者14 小时前
Flink SQL关联查询:双流Join与维表Join实战技巧
数据库·sql·flink
Deng87234734815 小时前
虚拟机性能优化实战技术指
性能优化
白衣衬衫 两袖清风15 小时前
SQL索引优化
数据库·sql
Kathleen10017 小时前
iOS--TableView的复用机制以及性能优化(处理网络数据)
ios·性能优化·网络请求·gcd·uitableview
Hello.Reader17 小时前
在 Flink SQL 中玩转实时模型推理 —— ML_PREDICT 实战解析
sql·flink·linq