简体   繁体   English

从mysql数据库中检索数据会更快吗?

[英]Which would be faster in retriving data from a mysql database?

Which would be faster in retrieving data from a mysql database? 哪个从mysql数据库中检索数据会更快? Data split across two columns, or the same size data from a single column? 数据分为两列,还是来自单列的相同大小的数据?

Edit: 编辑:

Just to give an idea, I have a table for a question and five answers it will receive. 只是提出一个想法,我有一个问题表和五个答案。 These answers are quite big about 1500 words each. 这些答案相当大,每个1500字。 When it comes to data retrieval speed, should I use a column for each answer, or should I just make one column with the 5 answers separated by a delimiter then use a script to separate them? 在数据检索速度方面,我应该为每个答案使用一列,还是应该只用一个分隔符分隔5个答案的一列,然后用脚本分隔它们?

Do not combine the answers into a single column, delimited or not. 不要将答案组合成单个列,不管是否分隔。 If you do you are not only breaking a rule-of-thumb in db design ( first normal form ) you're also setting yourself up for a programming world-of-hurt down the road. 如果你这样做,你不仅打破了数据库设计第一范式的经验法则,那么你也可以为自己设定一个受到伤害的编程世界。

You should also consider that you're partaking in premature optimization here. 您还应该考虑到您在此处参与过早优化 Also don't do that. 也不要那样做。 In my experience, and I think others will concur, you should trust your RDBMS to store and retrieve the data efficiently for you. 根据我的经验,我认为其他人会同意,您应该相信您的RDBMS能够有效地存储和检索数据。 The only thing you need to do is set up your Indexes properly. 您唯一需要做的就是正确设置索引。 If this does turn into a performance issue down the road, you can denormalize at that point. 如果这确实会导致性能问题,那么您可以在此时进行非规范化。

In response to your edit, neither of the options you present is the "correct" design for this problem. 为了响应您的编辑,您提供的选项都不是此问题的“正确”设计。 You should make 5 rows in an answer table, each with the ID of the question and a single answer in one column. 您应该在答案表中创建5 ,每包含问题的ID和一列中的单个答案。

Only if this turns out to have performance problems should you consider other designs. 只有在遇到性能问题时才考虑其他设计。 It's unlikely to have problems unless you are collecting millions of questions. 除非您收集数百万个问题,否则不太可能出现问题。

If they are in the same table, it won't make a difference. 如果它们在同一个表中,它就没有区别。

Once a row is accessed, looking up data from columns takes a trivial amount of time. 访问行后,从列中查找数据需要花费大量时间。

You should make your decision based on your data and how you will be accessing it. 您应该根据您的数据以及访问方式做出决定。

Don't rely on guesses and assumptions. 不要依赖猜测和假设。 Benchmark it yourself, on your hardware, with your coding, and your data. 自己,硬件,编码和数据进行基准测试。

I would say that the way you are going to access and use the information is more relevant than the way it's actually stored. 我会说,您访问和使用信息的方式比实际存储的方式更具相关性。

I would probably say that if you are going to refer to each answer independently such as multiple choice answers, storing the answers in a 3 column table with the following structure: 我可能会说,如果您要独立引用每个答案,例如多项选择答案,请将答案存储在具有以下结构的3列表中:

CREATE TABLE answers (
  question_id INTEGER PRIMARY KEY,
  answer INTEGER,
  answer_text TEXT
);

where answer would be something like 1, 2, 3, 4,.. for each of the answers in a given question, would be more suitable and sane. 对于给定问题中的每个答案,答案将是1,2,3,4 ......的答案,将更加合适和理智。

Some DBs don't index text type columns. 某些DB不会索引文本类型列。 So if you break up the columns from a text column into a varchar, and you had each column indexed, and you're using a DB that doesn't index text columns, you'd get better performance breaking them up. 因此,如果您将文本列中的列拆分为varchar, 并且每列都已编入索引, 并且您使用的是不对文本列编制索引的数据库,则可以更好地分解它们。

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

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