Redian新闻
>
query estimation shows cost 900%?
avatar
query estimation shows cost 900%?# Database - 数据库
f*e
1
I run SQL query estimated execution plan again one query.
The plan showed that the cost of "delete" and "insert" is 900%.
What does that mean?
PS: Which one of the following queries is better?
Query1:
if exist (select * from table1 where ...)
begin
update table1 set ...
end
else
begin
insert into table1 ...
end
Query2:
if exist (select * from table1 where ...)
begin
delete from table1 where ...
end
insert into table1 ...
Query3:
delete from table1 where ...
insert into table1 ...
avatar
c*d
2
肯定是3了
avatar
B*g
3
google merge

【在 f*****e 的大作中提到】
: I run SQL query estimated execution plan again one query.
: The plan showed that the cost of "delete" and "insert" is 900%.
: What does that mean?
: PS: Which one of the following queries is better?
: Query1:
: if exist (select * from table1 where ...)
: begin
: update table1 set ...
: end
: else

avatar
f*e
4


【在 B*****g 的大作中提到】
: google merge
avatar
f*e
5
why?

【在 c*****d 的大作中提到】
: 肯定是3了
avatar
c*d
6
avoid exist
不过我没看懂1,2,3之间的关系
为什么1要table1中没记录要insert,有记录要update
而3就直接delete,insert

【在 f*****e 的大作中提到】
: why?
avatar
f*e
7

query 的要求就是,像你说的
如果table1中有记录就update,没有就insert
Query1是严格按照这个逻辑走的。
Query3是是不管有没有,都delete了。然后再insert

【在 c*****d 的大作中提到】
: avoid exist
: 不过我没看懂1,2,3之间的关系
: 为什么1要table1中没记录要insert,有记录要update
: 而3就直接delete,insert

avatar
B*g
8
hehe
http://msdn2.microsoft.com/en-us/library/bb510625(SQL.100).aspx

【在 f*****e 的大作中提到】
:
: query 的要求就是,像你说的
: 如果table1中有记录就update,没有就insert
: Query1是严格按照这个逻辑走的。
: Query3是是不管有没有,都delete了。然后再insert

avatar
B*g
9
I would say he means tab1 and tab2

【在 c*****d 的大作中提到】
: avoid exist
: 不过我没看懂1,2,3之间的关系
: 为什么1要table1中没记录要insert,有记录要update
: 而3就直接delete,insert

avatar
f*e
10
wrong

【在 B*****g 的大作中提到】
: I would say he means tab1 and tab2
avatar
j*n
11
not exactly, it depends.
say the server is highly transactional, simply delete first (3) will block
all other concurrent queries (exclusive lock on certain rows if exist).

【在 c*****d 的大作中提到】
: 肯定是3了
avatar
c*d
12
1中update也一样要block other transaction

【在 j*****n 的大作中提到】
: not exactly, it depends.
: say the server is highly transactional, simply delete first (3) will block
: all other concurrent queries (exclusive lock on certain rows if exist).

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。