免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: netkiller
打印 上一主题 下一主题

子查询与性能问题,!真线下降为什么!? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-05-30 09:55 |只看该作者
原帖由 netkiller 于 2008-5-30 09:51 发表
是不是因为MyISAM 问题。
以前用Innodb 我写过更复杂的都没有问题。相当的好。
SQL 打印出来可能好几页A4纸。



和你的嵌套层数以及子查询的结果集大小有关

论坛徽章:
0
12 [报告]
发表于 2008-05-30 12:07 |只看该作者

回复 #11 voxxu 的帖子

我的结果集很小,有时是说不清楚的。。:)

论坛徽章:
1
白银圣斗士
日期:2015-11-23 08:33:04
13 [报告]
发表于 2008-05-30 12:22 |只看该作者
原帖由 netkiller 于 2008-5-30 12:07 发表
我的结果集很小,有时是说不清楚的。。:)


说不清就不说。

现在一般是自己折腾。^_^ 这种情况我是建立临时表,如下。


create table temp_bk6
select * from
(
select * from prehandle_aa a where a.bk6 !='-' and create_time > '2008-05-29'
) as b
where bk6LIKE '%bcc%' or bk6LIKE '%baidu%' or bk6LIKE '%kil%';


select a.webSite,a.weburl,a.customerId,a.customerName,b.name,c.realityName from TCustomerBaseInfo a, TDepartment b,TCustomerService c
where a.customerId  in
(

select bb.customer_id from
(
select * from temp_bk6  where src_href not like '%id%' or src_href not like '%icd%'
) as bb
where  bb.customer_id != '-1'
group by bb.customer_id

)

and a.csId=c.id and c.department_id=b.department_id
group by a.customerId;

论坛徽章:
1
白银圣斗士
日期:2015-11-23 08:33:04
14 [报告]
发表于 2008-05-30 16:44 |只看该作者
下午测试优化一下sql语句,应该创建真正存放在内存的临时表,效果提升明显。



http://codex.wordpress.org.cn/in ... %A8&oldid=89005

论坛徽章:
0
15 [报告]
发表于 2008-06-02 09:28 |只看该作者
原帖由 枫影谁用了 于 2008-5-30 12:22 发表


说不清就不说。

现在一般是自己折腾。^_^ 这种情况我是建立临时表,如下。


create table temp_bk6
select * from
(
select * from prehandle_aa a where a.bk6 !='-' and create_time > '2008-0 ...



This will increase the cost of IO,
The fundamental solution is replace subquery to join.

论坛徽章:
0
16 [报告]
发表于 2008-06-02 13:25 |只看该作者
针对IN的行比较:
IN实施是通过将其重新编写为“=”比较和AND操作的序列完成的。
可想而知当in内遇到大结果集时会发生什么,更何况还嵌套。

[ 本帖最后由 sunnyfun 于 2008-6-2 13:30 编辑 ]

论坛徽章:
0
17 [报告]
发表于 2008-06-04 16:42 |只看该作者
原帖由 sunnyfun 于 2008-6-2 13:25 发表
针对IN的行比较:
IN实施是通过将其重新编写为“=”比较和AND操作的序列完成的。
可想而知当in内遇到大结果集时会发生什么,更何况还嵌套。


Right answer.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP