DarthVader
DarthVader

Reputation: 55022

Optimizing a SQL/NHibernate query

I have a table ReadNews as follows:

id: int
User_id: int
News_id : int
DateRead : Datetime
FacebookUser_id: int

this is stored in a table.

I am getting my friends list of id, via rest call to fb and storing as IEnumerable<string> in the memory.

I need to find the latest news that my friends (IEnumerable<string>) read ordered by datetime descending. I m using NHibernate.

What s the most efficient way of building this query?

Essentially I have all the read news by fb users, but i want to get only the ones read by my friends.

I was thinking of doing:

select * from readnews where FacebookUser_id in (IEnumerable<string>);

Upvotes: 1

Views: 180

Answers (2)

Rich Andrews
Rich Andrews

Reputation: 4188

In principle, if you are all appropriately indexed up then using IN(x,y,z) is pretty performant and linq/nh should intemperate it fine for you. Try out nhibernate rino to be sure though.

http://nhprof.com/

Upvotes: 1

empi
empi

Reputation: 15881

Have you found any performance problem with it? top n + index on FacebookUser_id should do just fine.

It all depends on amount of data you have, etc. Ask yourself if you don't see any problems with it, aren't you trying premature optimization?

Upvotes: 1

Related Questions