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

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.

主站蜘蛛池模板: 泽州县| 海安县| 桂东县| 沛县| 东城区| 万州区| 丹巴县| 治县。| 元阳县| 上蔡县| 日照市| 庐江县| 来宾市| 汪清县| 郑州市| 达州市| 浦城县| 都昌县| 丽江市| 竹北市| 保定市| 隆化县| 格尔木市| 杭锦旗| 石景山区| 共和县| 洪江市| 肥西县| 邳州市| 龙岩市| 韶关市| 高淳县| 高雄县| 呼图壁县| 汝州市| 福贡县| 满洲里市| 资源县| 加查县| 南华县| 甘南县|