官术网_书友最值得收藏!

When to use static columns

We've now seen two ways to model users, each of whom has many status updates. The first approach was simply to define a table for users and a table for their status updates; the relationship between the two is encoded in the key structure of user_status_updates. The second approach is to store all of the information in one users_with_status_updates table using static columns to associate user-level data with the username partition key rather than having a different value for each clustering column. Which is better?

The answer largely depends on how closely coupled the related data types are. If we expect that most of our interactions with user profile information will also involve interacting with the user's status updates, and vice versa, then it makes a lot of sense to store them together in one table. The reasoning is similar to the parent-child conceptual framework discussed earlier, but in reverse. Not only is the user a special relationship from the standpoint of the status update, but also the status update is a special relationship from the standpoint of the user.

In the case of MyStatus, on balance, the relationship between users and status updates doesn't quite pass this test. In subsequent chapters, we'll expand our schema to accommodate several different one-to-many relationships where the user plays the role of parent. It's not clear that the relationship between users and status updates is more fundamental than the other relationships that we will model for users.

For this reason, we'll continue to work with the users and user_status_updates tables and leave behind the users_with_status_updates table as an interesting exercise.

主站蜘蛛池模板: 岗巴县| 斗六市| 孝昌县| 新田县| 瑞安市| 牡丹江市| 两当县| 凯里市| 清徐县| 英德市| 三江| 宣恩县| 休宁县| 丰宁| 诏安县| 承德市| 深泽县| 苍溪县| 锦屏县| 静宁县| 延吉市| 衡东县| 南木林县| 溧水县| 亚东县| 鲁甸县| 长阳| 游戏| 阿拉善盟| 高清| 河北区| 阳曲县| 耿马| 莱芜市| 惠来县| 信宜市| 望城县| 漳平市| 房产| 阿克陶县| 柞水县|