我有一个在旧的ANSI样式中在应用程序中进行硬编码的查询,但我希望使用适当的过滤索引进行优化。
SELECT HISTORY.UNITS
FROM branch, detail, HISTORY --WITH(INDEX(test))
WHERE
HISTORY.DETAIL_ID = detail.ID
AND HISTORY.BRANCH_ID = branch.ID
AND HISTORY.WEEK_SELECTOR=123456
AND (branch.BRANCH_CODE='016')
AND (detail.CODE='01308054')
我在HISTORY上尝试了过滤索引并将列切换为无效。分支和细节是小表,但历史非常大。
CREATE UNIQUE NONCLUSTERED INDEX [test] ON [HISTORY]
(
[WEEK_SELECTOR] ASC,
[DETAIL_ID] ASC,
[BRANCH_ID] ASC
)
INCLUDE ([UNITS])
WHERE ([week_selector]=(123456))
当我强迫它尝试使用我得到的索引时:
Msg 8622,Level 16,State 1,Line 1查询处理器无法生成 查询计划,因为此查询中定义了提示。重新提交 查询时没有指定任何提示,也没有使用SET FORCEPLAN。
有人可以告诉我如何计算正确的顺序,考虑JOIN和WHERE条款吗?
答案 0 :(得分:0)
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
base.OnCellPropertyChanged(sender, args);
if (args.PropertyName == "IsSelected")
{
_selected = !_selected;
if (_selected)
{
_cellCore.SetBackgroundColor(Color.Transparent);
}
else
{
_cellCore.SetBackground(_unselectedBackground);
}
}
}
我个人从不在生产环境中使用查询提示。我使用的索引:
SELECT HISTORY.UNITS
FROM HISTORY
INNER JOIN branch
ON branch.ID = HISTORY.BRANCH_ID
INNER JOIN detail
ON detail.ID = HISTORY.DETAIL_ID
WHERE
HISTORY.WEEK_SELECTOR = 123456
AND branch.BRANCH_CODE = '016'
AND detail.CODE = '01308054';
detail(CODE, ID)
branch(BRANCH_CODE, ID)
包含HISTORY(WEEK_SELECTOR, BRANCH_ID, DETAIL_ID)
列我不确定您的数据,但您可能需要更换UNITS
和DETAIL_ID
以获得更好的性能提升。