关于强制索引能否取代ORDER BY的问题

wubaozhang 2008-06-23 02:23:35
两张表tabelA(id,LastUpdate,c1),其中在日期LastUpdate上建立desc索引IX_tableA_LastUpdate,在数字值c1上也建有索引

两条SQL:
SQL1:select top 1000 * from tableA with(index(IX_tableA_LastUpdate))
SQL2:select top 1000 * from tableA order by LastUpdate desc
这两个是等效的吗?从试验结果看是一致的

但是增加条件后
SQL1:select top 1000 * from tableA with(index(IX_tableA_LastUpdate)) where c1=1
SQL2:select top 1000 * from tableA where c1=1 order by LastUpdate desc
两个查询结果就大部分不一致了SQL1的内容就不是按照时间取的最后值了,我想可能的结果是因为改进过的SQL1除了IX_tableA_LastUpdate起作用以外,c1的索引起了干扰效果导致的

请问有什么办法解决这个问题吗?
...全文
50 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wubaozhang 2008-06-23
  • 打赏
  • 举报
回复
由于未给分,关闭重开贴

34,590

社区成员

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

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