MYSQL:用户-个人资料详细信息表设置-最佳做法 [英] MYSQL: User - profile details table setup - best practice

查看:391
本文介绍了MYSQL:用户-个人资料详细信息表设置-最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在普通用户表"user"(user_id/user_email/user_pwd/etc)旁边,什么是存储配置文件信息的最佳方法?

Next to your normal user table "user"(user_id/user_email/user_pwd/etc), what is the best way to go to store profile information?

请问是否只需向用户表中添加"user"之类的字段

Would one just add fields to the user table like "user"

(user_id/user_email/user_pwd/user_firstname/user_lastname/user_views/etc)

或创建另一个名为个人资料"的表

or create another table called "profiles"

(profile_id/user_id/user_firstname/user_lastname/user_views/etc)

还是会去一个带有属性定义的表,另一个去存储这些值的表?

or would one go for a table with property definitions and another table to store those values?

我知道最后一个是最灵活的,因为您可以轻松添加和删除字段. 但是对于大型网站(用户数超过5万),这会很快吗?

I know the last one is the most flexible, as you can add and remove fields easily. But for a big site (50k users up) would this be fast?

推荐答案

您的方法应考虑的事项

在用户表中存储用户个人资料

  • 就获取个人资料数据而言,这通常是最快的方法,尽管此处可能有很多冗余数据(列中可能没有任何信息).
  • 快速(尤其是如果您仅从数据库中提取所需的列)
  • 浪费的数据
  • 使用/维护(可以说是使用PHPMyAdmin之类的接口)更困难/

在User_Profile表1-1中与用户的关系中存储用户配置文件

  • 使用联接仍然应该很快,并且如果不创建用户配置文件,除非用户填写其中一个,否则您可以消除一些数据冗余.
  • 更易于使用
  • 由于加入(或第二次查询)而变得有点慢

将用户配置文件作为属性和值存储在表中

*即用于存储可能选项的表,用于存储user_id,option_id和值的表*

*i.e. Table to store possible options, table to store user_id, option_id and value*

  • 没有存储冗余数据,所有数据都是相关的
  • 大多数归一化方法
  • 检索和更新数据的速度较慢

我的印象是,大多数网站都使用第二种方法并将配置文件信息存储在第二个表中,这对于大多数大型网站来说,通常是对数据库(twitter,facebook)进行非规范化以实现更高的读取性能,但代价是写入速度较慢性能.

My impression is that most websites use the 2nd method and store profile information in a second table, its common for most larger websites to de-normalize the database (twitter, facebook) to achieve greater read performance at the expense of slower write performance.

当您查看50,000条记录时,我认为将配置文件信息保存在第二个表中可能是一种方法.为了获得最佳性能,您希望将写入的数据与读取的数据隔离开来,以确保高速缓存可以有效地工作.

I would think that keeping the profile information in a second table is likely the way to go when you are looking at 50,000 records. For optimum performance you want to keep data that is written heavily seperated from data that is read heavy to ensure cache can work effectively.

这篇关于MYSQL:用户-个人资料详细信息表设置-最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆