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:

  1. f.id = us.feedid = fi.feedid
  2. the f (feed) table isn't used/necessary anywhere else in query (select or where)

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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -