Redian新闻
>
beijing呀,教教我怎么optimize sql server吧。
avatar
beijing呀,教教我怎么optimize sql server吧。# Database - 数据库
f*e
1
看得头都大了。
avatar
B*g
2
bu hui.
learning java now, nnd.
你不是都当小头头了吗?还学这干啥?

【在 f*****e 的大作中提到】
: 看得头都大了。
avatar
c*t
3
check execution plan first to find where the bottleneck is...

【在 f*****e 的大作中提到】
: 看得头都大了。
avatar
f*e
4

谁又在散播谣言?

【在 B*****g 的大作中提到】
: bu hui.
: learning java now, nnd.
: 你不是都当小头头了吗?还学这干啥?

avatar
B*g
5
你自己说的都去参加architect meeting了

【在 f*****e 的大作中提到】
:
: 谁又在散播谣言?

avatar
f*e
6
Did I?
我怎么都不记得了。
再说architect meeting也没什么呀。
该干活还是得干。

【在 B*****g 的大作中提到】
: 你自己说的都去参加architect meeting了
avatar
B*g
7
你到特奈特干的好好的,学啥西口色乌尔。

【在 f*****e 的大作中提到】
: Did I?
: 我怎么都不记得了。
: 再说architect meeting也没什么呀。
: 该干活还是得干。

avatar
j*n
8
帖个例子上来,俺给你瞧瞧?
beijing 是做orancle 的,你寻错人了,呵呵
往下看看我的帖子,一位给了我一本电子版的书,很好很强大。
avatar
j*n
9
some rules for you to start
rule 1. avoid table scan... check your execution plan by hit ctrl+l
rule 2. avoid CASE...THEN... in select statement
rule 3. avoid NOT IN, NOT EXIST
rule 4. use INNER JOIN when possible instead of LEFT/RIGHT OUTER JOIN
rule 5. use UNION ALL when possible against UNION
rule 6. avoid function against columns in WHERE clause
rule 7. use ISNULL() instead of OR in WHERE clause
e.g. WHERE col1 = @var1 OR @var1 IS NULL
can be written to
WHERE col1
avatar
p*a
10
I am a newbie too, curious to know?

what to use?
wha to use?
whay not coalesce?

【在 j*****n 的大作中提到】
: some rules for you to start
: rule 1. avoid table scan... check your execution plan by hit ctrl+l
: rule 2. avoid CASE...THEN... in select statement
: rule 3. avoid NOT IN, NOT EXIST
: rule 4. use INNER JOIN when possible instead of LEFT/RIGHT OUTER JOIN
: rule 5. use UNION ALL when possible against UNION
: rule 6. avoid function against columns in WHERE clause
: rule 7. use ISNULL() instead of OR in WHERE clause
: e.g. WHERE col1 = @var1 OR @var1 IS NULL
: can be written to

avatar
j*n
11
so what is your question?

【在 p******a 的大作中提到】
: I am a newbie too, curious to know?
:
: what to use?
: wha to use?
: whay not coalesce?

avatar
B*g
12
人家要optimize sql server,不是tuning sql。

【在 j*****n 的大作中提到】
: 帖个例子上来,俺给你瞧瞧?
: beijing 是做orancle 的,你寻错人了,呵呵
: 往下看看我的帖子,一位给了我一本电子版的书,很好很强大。

avatar
B*g
13
what to use?
wha to use?
whay not coalesce?
avatar
B*g
14
这个对新手足够了,你把整本书贴出来吧。

【在 j*****n 的大作中提到】
: some rules for you to start
: rule 1. avoid table scan... check your execution plan by hit ctrl+l
: rule 2. avoid CASE...THEN... in select statement
: rule 3. avoid NOT IN, NOT EXIST
: rule 4. use INNER JOIN when possible instead of LEFT/RIGHT OUTER JOIN
: rule 5. use UNION ALL when possible against UNION
: rule 6. avoid function against columns in WHERE clause
: rule 7. use ISNULL() instead of OR in WHERE clause
: e.g. WHERE col1 = @var1 OR @var1 IS NULL
: can be written to

avatar
c*t
15
good, should be marked

【在 j*****n 的大作中提到】
: some rules for you to start
: rule 1. avoid table scan... check your execution plan by hit ctrl+l
: rule 2. avoid CASE...THEN... in select statement
: rule 3. avoid NOT IN, NOT EXIST
: rule 4. use INNER JOIN when possible instead of LEFT/RIGHT OUTER JOIN
: rule 5. use UNION ALL when possible against UNION
: rule 6. avoid function against columns in WHERE clause
: rule 7. use ISNULL() instead of OR in WHERE clause
: e.g. WHERE col1 = @var1 OR @var1 IS NULL
: can be written to

avatar
c*t
16
where is the e-Book? can you share?

【在 j*****n 的大作中提到】
: 帖个例子上来,俺给你瞧瞧?
: beijing 是做orancle 的,你寻错人了,呵呵
: 往下看看我的帖子,一位给了我一本电子版的书,很好很强大。

avatar
j*n
18
这样哈,理解错误了....等我整理一下我的经验再发上来。

【在 B*****g 的大作中提到】
: 人家要optimize sql server,不是tuning sql。
avatar
j*n
19
rule 2. avoid CASE...THEN... in select statement
avatar
j*n
21
这个俺没有书... 干活的时候琢磨,然后在网上找的资料...
Online Book 其实能解决很多问题了。

【在 B*****g 的大作中提到】
: 这个对新手足够了,你把整本书贴出来吧。
avatar
B*g
22
rule2:
这个和front end有什么关系?
rule3:
这个永远是depends
rule7:
nod,I think you are right.

【在 j*****n 的大作中提到】
: rule 2. avoid CASE...THEN... in select statement
avatar
B*g
23
我还是先看oracle吧,学无止境呀

【在 j*****n 的大作中提到】
: 这个俺没有书... 干活的时候琢磨,然后在网上找的资料...
: Online Book 其实能解决很多问题了。

avatar
j*n
24
嗯,这个比较麻烦,得看情况:
多少个 cpu,
多少 ram,
磁盘阵列/SAN 的连接情况,有几个 physical I/O path,
SQL Server 2k5 EE 的话还要考虑是否作 table partitioning,
32 bit 得考虑 AWE (Allocation Windowing Extensions)
数据库是用作 OLTP/OLAP,
OLTP 的话还得小心 clustered index,
建议先开一个 perfmon 看看, 找到bottle neck 再说其他。

【在 B*****g 的大作中提到】
: 人家要optimize sql server,不是tuning sql。
avatar
j*n
25


【在 B*****g 的大作中提到】
: rule2:
: 这个和front end有什么关系?
: rule3:
: 这个永远是depends
: rule7:
: nod,I think you are right.

avatar
j*n
26
倒数第二个回帖不是么?

【在 B*****g 的大作中提到】
: wk,我竟然还会了这个帖子。没找到下载link
avatar
p*a
27
STILL CONFUSED---
rule 2. avoid CASE...THEN... in select statement
avatar
B*g
28
如果我有10000个record要在backend做这个select怎么办?

【在 j*****n 的大作中提到】

avatar
B*g
29
算了,不着了。等下半年直接看sql2008

【在 j*****n 的大作中提到】
: 倒数第二个回帖不是么?
avatar
j*n
30
***************************************************************
What is wrong with this:
select result=case when type like 'Dec%' then 1 else 0 end.....
what other better way can do the same?
***************************************************************
that's why I suggested that you need ask front-end to do this job...
or, if this query is frequently used, add one more column to handle it:
UPDATE table
SET newCol = 1
FROM table
WHERE type LIKE 'Dec%'
UPDATE table
SET newCol = 0
FROM table
W
avatar
j*n
31
实在要用也行。
看楼上我另一个跟帖。

【在 B*****g 的大作中提到】
: 如果我有10000个record要在backend做这个select怎么办?
avatar
j*n
32
6兆多一个文件,你懒得找给个信箱我发给你好了。

【在 B*****g 的大作中提到】
: 算了,不着了。等下半年直接看sql2008
avatar
B*g
33
其实我就是跟你闹,这些书应该很好电驴的。
你那个sql optimize再展开说说,还有怎样有效利用execution plan

【在 j*****n 的大作中提到】
: 6兆多一个文件,你懒得找给个信箱我发给你好了。
avatar
j*n
34
你可能不记得了,咱俩去年开始就有无数互相跟贴了,好像是从jobhunting 开始的,
呵呵
再要展开确实不知从何说起了,得有好的案例了。
execution plan 一般找找 table/index scan 就差不多了,其他的象 hash join 什么
的还不如直接看code来得快。
你把这个主题里面我的跟贴都看了的话主要idea 应该也差不多了吧。

【在 B*****g 的大作中提到】
: 其实我就是跟你闹,这些书应该很好电驴的。
: 你那个sql optimize再展开说说,还有怎样有效利用execution plan

avatar
w*e
35
看execution plan, 偶主要看:
1. table scan ---这是worst的, 最好避免 (当然, 要select*也没办法)
2. index scan --- this is 2nd worst, 也要避免
3. bookmark lookup ---说明你的index没放对地方
4. hash/nest/merge join --- 要根据情况用JOIN hint

【在 B*****g 的大作中提到】
: 其实我就是跟你闹,这些书应该很好电驴的。
: 你那个sql optimize再展开说说,还有怎样有效利用execution plan

avatar
B*g
36
2要不好哪个好用?

【在 w*******e 的大作中提到】
: 看execution plan, 偶主要看:
: 1. table scan ---这是worst的, 最好避免 (当然, 要select*也没办法)
: 2. index scan --- this is 2nd worst, 也要避免
: 3. bookmark lookup ---说明你的index没放对地方
: 4. hash/nest/merge join --- 要根据情况用JOIN hint

avatar
j*n
37
index seek is the best.
index scan is slightly better than table scan when scan in nonclustered
index, because it looks into smaller file.
Q: why index scan?
A: no enough info (column(s) within index)

【在 B*****g 的大作中提到】
: 2要不好哪个好用?
avatar
B*g
38
ding。
我现在sql server也是小牛牛了

【在 j*****n 的大作中提到】
: index seek is the best.
: index scan is slightly better than table scan when scan in nonclustered
: index, because it looks into smaller file.
: Q: why index scan?
: A: no enough info (column(s) within index)

avatar
j*n
39
恭喜 mm, 你已经成为了大牛牛了,oracle 俺是不懂地,呵呵

【在 B*****g 的大作中提到】
: ding。
: 我现在sql server也是小牛牛了

avatar
d*y
40
哈,什么牛人总结的?挺对啊。
把OPTIMIZER的难点都列出来了。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。