sql server - "No Join Predicate" when adding an additional condition - why? -
i have a, in general, simple query , don't understand why actual execution plan shows me warning "no join predicate" right after initial select on "nested loops" node.
i think query pretty self-explanatory: have users , have usersubscriptions feeds (m:n) - want query feeditems 1 feed user must subscribed to, query well:
select fi.title, fi.content, fi.published [user] u inner join usersubscription on u.id = us.userid inner join feed f on f.id = us.feedid inner join feeditem fi on fi.feedid = f.id u.emailaddress = 'xxx@xxx.xx' , f.id = 3 , fi.inserted > getdate() - 30
the interesting part there no warning long leave out condition:
and f.id = 3
as remove this, warning missing join predicate disappears. don't understand cause warning here.
any understanding appreciated!
thanks b.
the reason don't need join on feed table because:
f.id = us.feedid = fi.feedid
- the
f
(feed) table isn't used/necessary anywhere else in query (select
orwhere
)
here's more optimized query:
select fi.title, fi.content, fi.published [user] u inner join usersubscription on u.id = us.userid , us.feedid = 3 inner join feeditem fi on fi.feedid = us.feedid u.emailaddress = 'xxx@xxx.xx' , fi.inserted > getdate() - 30
by limiting particular feedid earlier, keep dataset smaller, , therefore faster. optimizer may change query you; i'm not sure.
Comments
Post a Comment