Logging Services 简介
2011-10-17 14:58
176 查看
select distinct userpo1_.ID as ID60_, userpo1_.CUST_ID as CUST2_60_, userpo1_.CARD_TYPE as CARD3_60_, userpo1_.USER_CODE as USER4_60_, userpo1_.LOGIN_PASS as LOGIN5_60_, userpo1_.LOGIN_NAME as LOGIN6_60_, userpo1_.USER_NAME as USER7_60_, userpo1_.GENDER as GENDER60_, userpo1_.CARD_CODE as CARD9_60_, userpo1_.IDENTITY as IDENTITY60_, userpo1_.TEL1 as TEL11_60_, userpo1_.TEL2 as TEL12_60_, userpo1_.REC_FLAG as REC13_60_, userpo1_.CHK_FLAG as CHK14_60_, userpo1_.OPT_TYPE as OPT15_60_, userpo1_.OPT_USERID as OPT16_60_, userpo1_.CHK_USERID as CHK17_60_, userpo1_.LASTUPDATE as LASTUPDATE60_, userpo1_.TEMP1 as TEMP19_60_, userpo1_.TEMP2 as TEMP20_60_ from RUN08110.T_ACCUSR accountuse0_, RUN08110.T_USRINFO userpo1_, RUN08110.T_CUSTOMER customerpo2_ where userpo1_.CUST_ID=customerpo2_.ID and accountuse0_.USER_ID=userpo1_.ID and accountuse0_.CHK_FLAG>0 and userpo1_.IDENTITY>3 and (customerpo2_.CUST_CODE like '%0000000009%') and userpo1_.IDENTITY=7 and accountuse0_.REC_FLAG=1 fetch first 10 rows only
就是这么一个由Hibernate转换出来的SQL语句 在IBM AS400数据库中执行就出现了问题,问题是由于有了fetch以后distinct失效了,本来这条语句的目的是先distinct取出不重复的记录,然后从不重复的记录中取出前面的10条记录,但是在AS400中执行以后结果却取出了重复的结果,其实就是distinct失效了。我认为这应该算这个数据库产品的一个BUG,后来我也解决了问题。解决问题的方法是改写了上面这条语句,先用户distinct取出了不重复的记录,语句变成这样的了:
select * from run08110.T_USRINFO where id in(select distinct userpo1_.ID as ID60 from RUN08110.T_ACCUSR accountuse0_, RUN08110.T_USRINFO userpo1_, RUN08110.T_CUSTOMER customerpo2_ where userpo1_.CUST_ID=customerpo2_.ID and accountuse0_.USER_ID=userpo1_.ID and accountuse0_.CHK_FLAG>0 and userpo1_.IDENTITY>3 and (customerpo2_.CUST_CODE like '%0000000009%') and userpo1_.IDENTITY=7 and accountuse0_.REC_FLAG=1) fetch first 10 rows only
也就是先用子查询找到不重复的记录,然后再从不重复的记录中取出10条,问题得到解决了,而且查询速度得到了大幅的提升。
就是这么一个由Hibernate转换出来的SQL语句 在IBM AS400数据库中执行就出现了问题,问题是由于有了fetch以后distinct失效了,本来这条语句的目的是先distinct取出不重复的记录,然后从不重复的记录中取出前面的10条记录,但是在AS400中执行以后结果却取出了重复的结果,其实就是distinct失效了。我认为这应该算这个数据库产品的一个BUG,后来我也解决了问题。解决问题的方法是改写了上面这条语句,先用户distinct取出了不重复的记录,语句变成这样的了:
select * from run08110.T_USRINFO where id in(select distinct userpo1_.ID as ID60 from RUN08110.T_ACCUSR accountuse0_, RUN08110.T_USRINFO userpo1_, RUN08110.T_CUSTOMER customerpo2_ where userpo1_.CUST_ID=customerpo2_.ID and accountuse0_.USER_ID=userpo1_.ID and accountuse0_.CHK_FLAG>0 and userpo1_.IDENTITY>3 and (customerpo2_.CUST_CODE like '%0000000009%') and userpo1_.IDENTITY=7 and accountuse0_.REC_FLAG=1) fetch first 10 rows only
也就是先用子查询找到不重复的记录,然后再从不重复的记录中取出10条,问题得到解决了,而且查询速度得到了大幅的提升。
相关文章推荐
- LIBSVM简介
- vc下使用windows的性能计数器简介
- Web 服务器的配置与应用(一) —— Apache 简介
- GMT、UTC、PDT 时间简介
- RAIDb 简介
- js--浏览器的渲染原理简介
- 软件级负载均衡器(LVS/HAProxy/LVS)的特点简介和对比
- node.js 简介之一
- UML 之 各种视图简介
- 事务简介及隔离
- 第1章 c#简介
- elasticsearch Getting Started (一)-简介
- 第一章(JavaScript简介)
- Retrofit——简介
- View编程指南1—Windows 和 Views 简介
- C#使用String和StringBuilder运行速度测试及各自常用方法简介
- 资料:电视剧《楚汉骄雄》剧情简介
- 主要Linux 平台高可用HA集群软件简介及软件下载
- Linux 2.6.19.x 内核编译配置选项简介
- Redis 简介