6

I have a, in general, very simple query and don't understand why the actual execution plan shows me a warning "No Join Predicate" right after the initial select on a "Nested Loops" node.

I think the query is pretty self-explanatory: I have Users and they have UserSubscriptions to Feeds (m:n) - I want to query all FeedItems from one Feed the user must be subscribed to, so this query does this very well:

select fi.Title, fi.Content, fi.Published
from [User] u 
inner join UserSubscription us on u.id = us.UserId
inner join Feed f on f.id = us.FeedId
inner join FeedItem fi on fi.FeedId = f.Id
where u.EMailAddress = 'xxx@xxx.xx'
and f.id = 3
and fi.Inserted > getdate() - 30

The interesting part is that there is no warning as long as i leave out this condition:

and f.id = 3

As soon as I remove this, the warning about the missing join predicate disappears. I don't understand the cause for this warning here.

Any help understanding this would be greatly appreciated!

Thanks b.

4

1 回答 1

3

您不需要在 Feed 表上 JOIN 的原因是:

  1. f.id = us.FeedId = fi.FeedId
  2. ( Feed) 表在查询 (或)f的其他任何地方都不需要/不需要SELECTWHERE

这是一个更优化的查询:

select fi.Title, fi.Content, fi.Published
from [User] u 
inner join UserSubscription us on u.id = us.UserId and us.FeedId = 3
inner join FeedItem fi on fi.FeedId = us.FeedId
where u.EMailAddress = 'xxx@xxx.xx'
and fi.Inserted > getdate() - 30

通过更早地将其限制为特定的 FeedId,您可以使数据集更小,从而更快。优化器可能会为您更改您的查询;我不确定。

于 2013-05-02T16:41:07.883 回答