查询返回很慢,什么原因呢

lailu 2006-08-31 04:03:51
一张表里记录太多,几百万条记录
我用odbc函数+sql语句 select top 100 ID from xx where ID not in (select top 100 from xx where Time<yy and Time>dd order by ID) and where Time<yy and Time>dd order by ID 实现类似的分页返回数据,表也做了ID和Time的聚集索引

结果是:查询日期越靠后越慢,sql server的内存占用也相当多
但是我直接在sql server的查询分析器中输入语句,查询结果反应很快,写应用程序中有什么优化吗
...全文
304 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjz_1209 2006-08-31
  • 打赏
  • 举报
回复
将查询语句放入一存储过程中,会快很多。
snowmagic 2006-08-31
  • 打赏
  • 举报
回复
有not in,会很慢的
WangZWang 2006-08-31
  • 打赏
  • 举报
回复
--语句改为如下:

Select top 100 ID
from (Select top 200 ID from xx where Time<yy and Time>dd order by ID) as t
order by ID desc

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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