【发布时间】:2014-03-21 00:54:11
【问题描述】:
我有一个包含 10 亿行的表,其中包含目标设定程序的可能解决方案。 每列值的组合创建了一个成功的目标路径。我想过滤记录以显示按用户选择排序的前 10 行。有人可能想要最低的退休年龄,然后是最低的存款金额。其他人可能想要尽可能高的生存机会,然后是最高的结局平衡,...... 这是我的专栏:
age tinyint
retirement_age tinyint
retirement_length tinyint
survival smallint
deposit int
balance_start int
balance_end int
SLOW 10 MIN QUERY:
select top(10) age,retirement_age,retirement_length,survival,deposit,balance_start,balance_end
from TABLE
where
age >= 30
and survival >= 8000 --OUT OF 10000
and balance_start <= 20000
and retirement_age >= 60
and retirement_age <= 75
and retirement_length >= 10
and retirement_length <= 25
and deposit >= 1000
and deposit <= 20000
ORDER BY -- (COLUMN ORDER PREFERENCES UNKNOWN)
retirement_age,
deposit,
retirement_length desc,
balance_end desc,
age desc,
survival desc
该查询需要 10 分钟。 所有记录都生成一次,因此不再需要对数据库进行写入/更新。我在想我应该索引每一列,但没有这样做。数据库现在是 30GB,但空间不是问题。
我已经运行了预计执行计划:
选择:0% 并行度:0% 排序:23% 表扫描:77%
【问题讨论】:
-
我想你的意思是估计的执行计划? ;)
-
好的,谢谢。估计的例外计划... :)
标签: sql sql-server performance tsql indexing