Oracle使用子查询,和左连接查询同样结果性能差距。
来源:互联网 发布:艺术字生成器软件下载 编辑:程序博客网 时间:2024/04/29 14:38
这条SQL,执行,查询所有员工当月的考勤记录汇总,展示全部数据耗时2.3秒
String sql = "select userid,orgid," + 子查询,性能太慢,不适用
"(select username from t_acl_userinfo where userid=t.userid) username," +
"(select count(state) from t_chk_manage where userid=t.userid and state='01'"+sqlappend+") state01 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='02'"+sqlappend+") state02 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='03'"+sqlappend+") state03 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='04'"+sqlappend+") state04 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='05'"+sqlappend+") state05 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='06'"+sqlappend+") state06 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='07'"+sqlappend+") state07 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='08'"+sqlappend+") state08 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='09'"+sqlappend+") state09 " +
"from t_chk_manage t group by userid,orgid HAVING 1=1";
//使用左连接,先查出基本数据,再连接, Oracle 耗时0.2秒(速度提升将近10倍)
String sql = "select s.* , userInfo.username as username , state1.state as state01 , state2.state as state02 , state3.state as state03 , state4.state as state04 , " +
"state5.state as state05 , state6.state as state06 , state7.state as state07 , state8.state as state08 , state9.state as state09 " +
"from (select userid,orgid from t_chk_manage t where 1=1 "+dataSearch+" group by userid , orgid HAVING 1=1 "+search+") s " +
"left join (select username,userid from t_acl_userinfo)userInfo on userInfo.userid = s.userid "+
"left join (select userid,count(state) as state from t_chk_manage where state = '01' "+dataSearch+" group by userid)state1 on state1.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '02' "+dataSearch+" group by userid)state2 on state2.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '03' "+dataSearch+" group by userid)state3 on state3.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '04' "+dataSearch+" group by userid)state4 on state4.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '05' "+dataSearch+" group by userid)state5 on state5.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '06' "+dataSearch+" group by userid)state6 on state6.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '07' "+dataSearch+" group by userid)state7 on state7.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '08' "+dataSearch+" group by userid)state8 on state8.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '09' "+dataSearch+" group by userid)state9 on state9.userid = s.userid";
//这条sql查询当月员工考勤明细记录,耗时0.4秒,(原本使用子查询需要7秒,提升20倍)
select day0.*,username,"+dayAppend+" from (select userid,orgid,substr(t.create_time,0,7) from t_chk_manage t where substr(t.create_time,0,7)='"+daystart.substring(0, 7)+"' " +
"group by userid,orgid,substr(t.create_time,0,7) HAVING 1=1 "+search+")day0 " +
"left join (select userid,username from t_acl_userinfo)username on username.userid = day0.userid " +
""+sqlAppend
String sql = "select userid,orgid," + 子查询,性能太慢,不适用
"(select username from t_acl_userinfo where userid=t.userid) username," +
"(select count(state) from t_chk_manage where userid=t.userid and state='01'"+sqlappend+") state01 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='02'"+sqlappend+") state02 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='03'"+sqlappend+") state03 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='04'"+sqlappend+") state04 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='05'"+sqlappend+") state05 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='06'"+sqlappend+") state06 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='07'"+sqlappend+") state07 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='08'"+sqlappend+") state08 ," +
"(select count(state) from t_chk_manage where userid=t.userid and state='09'"+sqlappend+") state09 " +
"from t_chk_manage t group by userid,orgid HAVING 1=1";
//使用左连接,先查出基本数据,再连接, Oracle 耗时0.2秒(速度提升将近10倍)
String sql = "select s.* , userInfo.username as username , state1.state as state01 , state2.state as state02 , state3.state as state03 , state4.state as state04 , " +
"state5.state as state05 , state6.state as state06 , state7.state as state07 , state8.state as state08 , state9.state as state09 " +
"from (select userid,orgid from t_chk_manage t where 1=1 "+dataSearch+" group by userid , orgid HAVING 1=1 "+search+") s " +
"left join (select username,userid from t_acl_userinfo)userInfo on userInfo.userid = s.userid "+
"left join (select userid,count(state) as state from t_chk_manage where state = '01' "+dataSearch+" group by userid)state1 on state1.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '02' "+dataSearch+" group by userid)state2 on state2.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '03' "+dataSearch+" group by userid)state3 on state3.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '04' "+dataSearch+" group by userid)state4 on state4.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '05' "+dataSearch+" group by userid)state5 on state5.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '06' "+dataSearch+" group by userid)state6 on state6.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '07' "+dataSearch+" group by userid)state7 on state7.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '08' "+dataSearch+" group by userid)state8 on state8.userid = s.userid " +
"left join (select userid,count(state) as state from t_chk_manage where state = '09' "+dataSearch+" group by userid)state9 on state9.userid = s.userid";
//这条sql查询当月员工考勤明细记录,耗时0.4秒,(原本使用子查询需要7秒,提升20倍)
select day0.*,username,"+dayAppend+" from (select userid,orgid,substr(t.create_time,0,7) from t_chk_manage t where substr(t.create_time,0,7)='"+daystart.substring(0, 7)+"' " +
"group by userid,orgid,substr(t.create_time,0,7) HAVING 1=1 "+search+")day0 " +
"left join (select userid,username from t_acl_userinfo)username on username.userid = day0.userid " +
""+sqlAppend
- Oracle使用子查询,和左连接查询同样结果性能差距。
- 子查询和连接查询性能比较
- oracle中查询:子查询,连接查询
- oracle子查询和表连接
- oracle左连接,右连接查询 (+)
- 05-Oracle学习_子查询 和 连接查询
- 06-Oracle学习_练习-子查询 和 连接查询
- 子查询和连接
- MySQL连接查询(交叉连接,左连接,右连接,全连接,子查询,联合查询)
- sql查询。子查询,内、左、右连接
- 使用左外连接查询,ORDERS 和 CUSTOMERS 表
- oracle左连接查询出现数据重复
- oracle 连接查询,子查询,分组函数
- 数据库表左连接查询首先一个表和3张表进行左连接查询,将查询的结果看做一张虚拟表,再将这个虚拟表,和另外一张表进行左连接查询
- mysql的查询、子查询及连接查询 , 左连接,右联接,内连接
- SQL左连接查询和又连接查询的区别
- Linq 左连接查询和右连接查询
- Oracle: 四、Oracle连接查询,子查询(相关子查询,嵌套子查询)
- oracle 查询当前正在执行的事务
- c#调用Java webService的专题
- 视频技术发展历史:H.264技术简介
- 编译原理学习导论
- CHtmlDialog调用Javascript例子代码
- Oracle使用子查询,和左连接查询同样结果性能差距。
- opencv画线的时候,RGB颜色顺序
- 自从密码问题出现以后,csdn似乎更慢了
- SELECT INTO 临时表时,不能往同样的表INTO两遍
- 子衿的事(62)
- CSS简写方法说明
- not exists 解决group by排序问题
- java中synchronized关键字作用
- 视频技术发展历史:MPEG-2技术简介