简体   繁体   English

这两种方法中的哪一种更适合组织和查询mysql中的数据?

[英]Which of these two approaches is better for organizing and querying data from a mysql?

Im trying to decide how Im gonna implement this, I hope that your experience can help me. 我试图决定如何实施,希望您的经验对我有所帮助。

The problem 问题

A user login into the webapp using facebook api, this gives me a bunch of data, name, facebook id (Im using that number to identify the user in my site), age, and some other random data that I need to store for later analysis. 用户使用facebook api登录到webapp,这给了我很多数据,名称,facebook id(我使用该数字来标识我的网站中的用户),年龄以及我需要存储以供以后使用的其他一些随机数据分析。 After that the user can ask for a ticket (just a piece of text with a number generated in a php script), when the ticket is generated I stored the user facebook id, the date (MM/DD/YYYY) and of course a unique id for the ticket, the same user can ask for several tickets. 之后,用户可以索取票证(只是一段文本,其中包含一个在php脚本中生成的数字),当票证生成时,我存储了用户facebook id,日期(MM / DD / YYYY),当然还有票证的唯一ID,同一用户可以要求几张票证。

Solution 1 (the organized one but seems stressful for the mysql server) 解决方案1(有组织的解决方案,但对于MySQL服务器而言似乎压力很大)

To have two tables, one called users where I store all the user personal information retrived fron the facebook api, including the facebook user id. 要有两个表,一个叫users ,我在其中存储所有用户个人信息,从Facebook api检索到,包括Facebook用户ID。 The second table called Tickets where to store only the date of the creation of the ticket and the facebook user id of the user who create it, and of course this table have an auto increment unique id to identify the ticket it self. 第二个表称为“ Tickets ,其中仅存储票证的创建日期和创建票证的用户的Facebook用户ID,当然,此表具有自动递增的唯一ID,以标识票证本身。

In the future, I will need to display a list of all the users who created a ticket, displaying not only their facebook user id but also their personal information, so this means I need to query tickets and for each row/ticket I found using the facebook id I need to query users to retrive the personal information of that user (name, age, ...). 将来,我将需要显示所有创建票证的用户的列表,不仅显示其Facebook用户ID,而且还显示其个人信息,因此这意味着我需要查询tickets以及针对使用的每行/票证我需要查询users的Facebook ID来检索该users的个人信息(姓名,年龄,...)。 So if I have 10000 tickets created by 10000 uniques users i will need to query my Mysql server 10001, one for retriving an array of tickets and 10000 for retriving the info of each user... 因此,如果我有10000个唯一身份用户创建的10000张票证,则需要查询Mysql服务器10001,一个用于检索票证数组,一个用于检索每个用户的信息10000 ...

Solution 2 (not that organized as I like) 解决方案2(不像我喜欢的那样组织)

Intead of having two tables, just have one, where I store everything, tickets and user data, so when a user creates a ticket I store not only the information related with the ticket but also the user personal data in the same table, later if I want to display the list of users who creates a ticket Im just going to make a single query to tickets that will retrive eventualy (if I have 10000 tickets) a big pack of data that I later will parse using php. 有两个表,只有一个表,我在其中存储所有内容,票据和用户数据,因此,当用户创建票据时,我不仅将与票据相关的信息存储在同一表中,还将用户个人数据存储在同一表中,如果以后我想显示谁创造了票我只是要做一个单一查询用户的列表tickets将eventualy retrive(如果我有10000票)数据的大包,我以后将解析使用PHP。 These way I have less querys but bigger data. 这样,我的查询更少,但是数据更大。


Right now I have running a basic implentation of the first solution, but now Im a bit worry about scalability issues. 现在,我已经运行了第一个解决方案的基本功能,但是现在我有点担心可伸缩性问题。

This is how a part of my users table looks: 这是我的users表的一部分的外观: 在此处输入图片说明

And this is tickets table: 这是tickets表: 在此处输入图片说明

So for listing the users I proceed like this; 因此,要列出用户,我会这样进行: discount_id from tickets represent a type of ticket, so if need the type 1 I query * tickets WHERE discount_id=1, from the array it gives me using the winner_id (which is the facebook user id of the creator of the ticket) I compre it to the face_id from users to retrive the personal information. 来自tickets discount_id代表tickets一种类型,因此如果需要类型1我可以查询*票证winner_id = 1,从数组中它使用winner_id (票证创建者的Facebook用户ID)给我,我将其winner_idusers获取face_id以检索个人信息。

I was thinking in a third way to solve this, that is kinda combining 1 and 2, having the same two tables, right after I query tickets for the type I need, then I query (just one) table users asking for an array of ALL the user ids tickets gave me, but I have no idea how to do this and if is worth it. 我想用第三种方式解决这个问题,就是将1和2相结合,并具有相同的两个表,在我查询所需类型的tickets之后,然后查询(仅一个)表users要求一个数组所有的用户ID tickets都给了我,但是我不知道该怎么做以及是否值得。


Which solution is better? 哪种解决方案更好? Is there a smart way to proceed? 有什么明智的方式进行吗? Thanks! 谢谢!

Like commented definitley break down table structure when you can. 就像评论definitley时一样,可以分解表结构。 It makes life easier hence use the first version. 它使生活更轻松,因此使用第一个版本。 Many things is only possible with many tables. 许多事情只有通过许多表才有可能。

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

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