我有一个奇怪的问题,如果执行以下查询,则Sql Server(2008和2016)大约需要35秒才能完成。
SELECT DISTINCT F.FilterTitle, F.FilterSlug, F.FilterOrderList, F.FilterType
FROM products p
JOIN products_translations pt ON pt.ProductId = p.Id AND pt.Culture = 'it'
JOIN facets F ON F.ProductId = p.Id AND F.Culture = 'it' AND F.FilterType = 2
JOIN products_categories pc ON pc.productId = p.id
JOIN categories C ON pc.CategoryId = C.Id
JOIN categories_slugs cps ON cps.CategoryId = C.ParentCategoryId AND cps.Culture = 'it'
JOIN categories_slugs cs ON cs.CategoryId = C.Id AND cs.Culture = 'it'
WHERE cps.value = 'string1' AND cs.value = 'string2'
AND CONTAINS(pt.DescriptionForSearch, '"value*"', LANGUAGE 1040) --this is a full text
AND p.Visible = 1 AND p.Payments = 0 --both are bit fields
ORDER BY F.FilterType, F.FilterOrderList, F.FilterTitle;
如果我对此行发表评论
and p.Visible = 1 and p.Payments = 0
查询仅需要几毫秒。如果我删除行也一样
and contains(pt.DescriptionForSearch, '"value*"' , language 1040)
,并保持其他陈述不变。我还为两个位字段创建了两个索引,而没有更改。
有人可以阐明为什么会发生这种情况吗?
更新
At this link我忘记包括的两个执行计划。