简体   繁体   中英

Best practice to achieve max performance in SQL Server

What is more efficient(faster): to store the same tweet twice in Tweet table, once for user1 and again for user2 or using join between Tweet and Friend to get the results ?

Tweet => Id
         UserId
         SenderId
         JSONdata

User =>  Id

Friend => UserId 
          FriendId 

with join :

SELECT TOP 20 a.* FROM Tweet a INNER JOIN Friend b ON a.SenderId = b.UserId WHERE b.UserId = {0} 

or I can save the tweet twice for the sender and the receiver and use a simple query :

SELECT TOP 20 * FROM TWEET WHERE UserId = {0}

which one is more faster, if joins then what type of index should I use, I'll be happy to hear any advice.

thanx

Store your data only once (Tweet) and you will not have any consistency issues. Unless you are developing this as a heavy OLAP system (ie data warehouse), then you should be normalizing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM