楼主: alan_yang

探讨一下这个sql的执行!

[复制链接]
论坛徽章:
41
ITPUB元老
日期:2005-02-28 12:57:002011新春纪念徽章
日期:2011-01-25 15:41:502011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:56管理团队成员
日期:2011-05-07 01:45:08ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18
31#
 楼主| 发表于 2001-10-11 16:49 | 只看该作者
想不到无心插柳柳成荫啊!
     这个论题反应如此热烈,实在出乎意料!
    期望与各位大小虾共同进步!

使用道具 举报

回复
论坛徽章:
63
版主7段
日期:2012-05-15 15:24:11itpub13周年纪念徽章
日期:2014-10-08 15:16:50itpub13周年纪念徽章
日期:2014-10-08 15:16:50itpub13周年纪念徽章
日期:2014-10-08 15:16:50itpub13周年纪念徽章
日期:2014-10-10 14:34:59马上加薪
日期:2015-01-08 15:39:192015年新春福章
日期:2015-03-04 14:19:112015年新春福章
日期:2015-03-06 11:57:31
32#
发表于 2001-10-12 00:34 | 只看该作者

建议用外连接。

建议用外连接代替 not in,
据说速度可以提高30倍,
我也感觉确实快很多。

使用道具 举报

回复
论坛徽章:
41
ITPUB元老
日期:2005-02-28 12:57:002011新春纪念徽章
日期:2011-01-25 15:41:502011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:56管理团队成员
日期:2011-05-07 01:45:08ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18
33#
 楼主| 发表于 2001-10-12 08:37 | 只看该作者

Re: 建议用外连接。

最初由 jlandzpa 发布
[B]建议用外连接代替 not in,
据说速度可以提高30倍,
我也感觉确实快很多。
[/B]

想知道具体就这个sql 如何写呢?

使用道具 举报

回复
论坛徽章:
1
授权会员
日期:2005-10-30 17:05:33
34#
发表于 2001-10-12 13:11 | 只看该作者
The outer join, which I mentioned in my original"method 2", should be write like this
-------------------------------------
select * from a, b
where a.c = b.c +
and b.c is null
-------------------------------------
the above outer join returns same result as
select * from a where a.c not in (select c from b)
-------------------------------------
please let us know the performance. I guess it will not be much faster than the 3 queries

使用道具 举报

回复
论坛徽章:
41
ITPUB元老
日期:2005-02-28 12:57:002011新春纪念徽章
日期:2011-01-25 15:41:502011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:56管理团队成员
日期:2011-05-07 01:45:08ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18
35#
 楼主| 发表于 2001-10-12 13:19 | 只看该作者
最初由 kezizi 发布
[B]The outer join, which I mentioned in my original"method 2", should be write like this
-------------------------------------
select * from a, b
where a.c = b.c +
and b.c is null
-------------------------------------
the above outer join returns same result as
select * from a where a.c not in (select c from b)
-------------------------------------
please let us know the performance. I guess it will not be much faster than the 3 queries [/B]

      I will test it !  Give me times !

使用道具 举报

回复
论坛徽章:
60
2015中国数据库技术大会纪念徽章
日期:2015-04-24 16:04:24茶鸡蛋
日期:2012-06-03 11:14:362012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18迷宫蛋
日期:2012-01-31 08:44:15复活蛋
日期:2012-01-11 11:50:542012新春纪念徽章
日期:2012-01-04 11:49:54
36#
发表于 2001-11-19 16:35 | 只看该作者
最初由 kezizi 发布
[B]select * from a, b
where a.c = b.c +
and b.c is null
-------------------------------------
[/B]


in this sql , why add  'and b.c is null'
if b.c is alwayse not null, does it posible?

使用道具 举报

回复
论坛徽章:
41
ITPUB元老
日期:2005-02-28 12:57:002011新春纪念徽章
日期:2011-01-25 15:41:502011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:56管理团队成员
日期:2011-05-07 01:45:08ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18
37#
 楼主| 发表于 2001-11-19 17:33 | 只看该作者


帮你提一提吧,看看谁能回答.

我是无能为力啦.我给你这么一问,也觉的怪怪的.

奇怪我就怎么没去想个为什么呢?惭愧!惭愧!

使用道具 举报

回复
论坛徽章:
0
38#
发表于 2001-11-20 05:46 | 只看该作者
'b.c is null'  is the critical condition in this query, otherwise you'll get all the rows from a. Besides, why all of you use count(*) instead of counnt(1)? It will take tons of unnecessary info into the memory, and slow down the query.

使用道具 举报

回复
论坛徽章:
41
ITPUB元老
日期:2005-02-28 12:57:002011新春纪念徽章
日期:2011-01-25 15:41:502011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:56管理团队成员
日期:2011-05-07 01:45:08ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18
39#
 楼主| 发表于 2001-11-20 08:13 | 只看该作者


Yes ! You are right!

Use count(col1) takes few times than count(*).

It's a mistake .

使用道具 举报

回复
论坛徽章:
60
2015中国数据库技术大会纪念徽章
日期:2015-04-24 16:04:24茶鸡蛋
日期:2012-06-03 11:14:362012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18迷宫蛋
日期:2012-01-31 08:44:15复活蛋
日期:2012-01-11 11:50:542012新春纪念徽章
日期:2012-01-04 11:49:54
40#
发表于 2001-11-20 08:18 | 只看该作者

thank you

i 'll test it

使用道具 举报

回复

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

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表