简体   繁体   English

在SQL Server中获得最佳性能的最佳实践

[英]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两次存储在Tweet表中,一次存储给user1 ,一次存储给user2或者使用TweetFriend之间的join获取结果?

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. 除非您将其开发为繁重的OLAP系统(即数据仓库),否则应该进行标准化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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