求高手解释一下,为什么Sqlserver有这样的低级错误

shenen 2007-09-06 10:58:32
http://community.csdn.net/Expert/topic/5744/5744184.xml?temp=4.096621E-02
把应该0秒查询出来的结果,搞了近10秒才查出来。
...全文
521 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljs1519 2007-09-08
  • 打赏
  • 举报
回复
楼主:
会不会是你的P_PORDUCT 等报表记录很多(虽然筛选的结果不多)?
试试这样做:
把这段语句……FROM p_Product
left JOIN p_product2type b ON p_Product.productguid = b.productguid……
改成:……FROM p_Product order by productguid) a left join (select FROM P_PORDUCT2TYPE ORDRE BY PRODUCTCODE) B……


yjlhch 2007-09-08
  • 打赏
  • 举报
回复
mark
shenen 2007-09-07
  • 打赏
  • 举报
回复
我的操作系统是winServer2003,更新步骤没有错。
  • 打赏
  • 举报
回复
不应该的!在看看是不是其他的原因!
superhasty 2007-09-07
  • 打赏
  • 举报
回复
嗯,索引过多也不好.
seulty 2007-09-07
  • 打赏
  • 举报
回复
重新下一个看看 我当时也下了好几个 才搞定的。。。
shenen 2007-09-06
  • 打赏
  • 举报
回复
我打了
SQL2000-KB884525-SP4-x86-CHS.exe
再查看版本还是sp1.不知道哪儿有对应的补丁呀。
微软网站上也没找到。
Limpire 2007-09-06
  • 打赏
  • 举报
回复
我看还是索引问题。不是索引少了,而是索引多了。

把其中一个索引删了测试,不行再删再测试。应该是某个重复键特别多的索引作怪。
zjcxc 元老 2007-09-06
  • 打赏
  • 举报
回复
楼主该打补丁了
hb_gx 2007-09-06
  • 打赏
  • 举报
回复
ORDER BY 是会浪费很多时间的

这些表关键还是要看索引建立的如何,虽然数据不多,可是 join 的表也很多
shenen 2007-09-06
  • 打赏
  • 举报
回复
拷过来,看着方便些:

select *
from
(SELECT p_Product.ProductGUID, ProductName, ProductCode, ProductSpec, Unit, Price, Remarks
FROM p_Product
left JOIN p_product2type b ON p_Product.productguid = b.productguid
LEFT JOIN vp_product2unit c ON p_Product.productguid =c.productguid
left JOIN mybusinessunit d ON c.bucode = d.hierarchycode
WHERE (1=1) AND ( CharIndex('01.01.01' + '.',b.ProductTypeCode + '.')=1 )
AND d.BUGUID=('11b11db4-e907-4f1f-8835-b9daab6e1f23')
) p_Product
结果集有18条记录。执行时间:76 ms

select *
from
(SELECT p_Product.ProductGUID, ProductName, ProductCode, ProductSpec, Unit, Price, Remarks
FROM p_Product
left JOIN p_product2type b ON p_Product.productguid = b.productguid
LEFT JOIN vp_product2unit c ON p_Product.productguid =c.productguid
left JOIN mybusinessunit d ON c.bucode = d.hierarchycode
WHERE (1=1) AND ( CharIndex('01.01.01' + '.',b.ProductTypeCode + '.')=1 )
AND d.BUGUID=('11b11db4-e907-4f1f-8835-b9daab6e1f23')
) p_Product
ORDER BY p_Product.ProductCode ASC,p_Product.ProductGUID
结果集:还是18条记录。 执行时间:9733 ms
想不通为什么会差别那么大,仅仅排18条记录的序,就要费那么长时间吗?

---补充说明:mybusinessunit 表有24条记录,其他表都是3000条记录。
主要原因还是它把sql语句改了,从查询计划上看到,它把语句改成下面的样式,但是就是下面的语句执行起来也只有5秒左右,也不会那么慢呀。
SELECT p_Product.ProductGUID, ProductName, ProductCode, ProductSpec, Unit, Price, Remarks
from
(select top 100000000 p_Product.ProductGUID, ProductName, ProductCode, ProductSpec, Unit, Price, Remarks,d.bucode
from p_Product
LEFT JOIN vp_product2unit c ON p_Product.productguid =c.productguid
left JOIN mybusinessunit d ON c.bucode = d.hierarchycode
where d.BUGUID=('11b11db4-e907-4f1f-8835-b9daab6e1f23')
order by p_Product.ProductCode ASC,p_Product.ProductGUID
)
p_Product
left JOIN mybusinessunit d ON p_Product.bucode = d.hierarchycode
left JOIN p_product2type b ON p_Product.productguid = b.productguid
where ( CharIndex('01.01.01' + '.',b.ProductTypeCode + '.')=1 )
dawugui 2007-09-06
  • 打赏
  • 举报
回复
有 CharIndex的比较(字符串的比较),可能会慢.
fa_ge 2007-09-06
  • 打赏
  • 举报
回复
看看
shenen 2007-09-06
  • 打赏
  • 举报
回复
Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000 00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
我同事用的企业版sp1,也有同样的问题。
yuzi19990853 2007-09-06
  • 打赏
  • 举报
回复
还是用oracle吧

用server 用的很爽
Limpire 2007-09-06
  • 打赏
  • 举报
回复
我觉得楼主还不至于,都说了打过企业版,一打就上。
sunhonglei2004 2007-09-06
  • 打赏
  • 举报
回复
双击下载的文件,执行的是解压缩, 不是安装
安装是到解压的目录中去执行 setup.bat
---------------------------------------
还是邹老大正解,
zjcxc 元老 2007-09-06
  • 打赏
  • 举报
回复
双击下载的文件,执行的是解压缩, 不是安装
安装是到解压的目录中去执行 setup.bat
Limpire 2007-09-06
  • 打赏
  • 举报
回复
是用同一个补丁呀,怎么没打上,就不知道了。

/*
更新信息:Microsoft 在 SP4 的最终内部版本中发现了一个问题,如果用户在运行 SQL Server 时启用了 AWE 支持功能,就会受到该问题的影响。此问题对 ia64 平台没有影响。在 x86 和 x64 系统上,该问题只会影响符合以下条件的用户:已经启用 AWE 并占用了超出 2 GB 的内存(仅适用于 Enterprise、Developer 和 Evaluation 版本)
*/
lost_queen 2007-09-06
  • 打赏
  • 举报
回复
开发版~没有用过哦~
但时间变多不全是补丁的问题吧?
就因为一个order by?
学习!
加载更多回复(8)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧