从 mysql 数据库检索数据哪个会更快?

发布于 2024-10-01 15:32:41 字数 179 浏览 5 评论 0原文

哪个从 mysql 数据库检索数据更快?数据分为两列,还是来自单列的相同大小的数据?

编辑:

只是为了提供一个想法,我有一个问题表和它将收到的五个答案。这些答案相当大,每个大约有1500字。当谈到数据检索速度时,我应该为每个答案使用一列,还是应该只用一个分隔符分隔 5 个答案的一列,然后使用脚本来分隔它们?

Which would be faster in retrieving data from a mysql database? 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. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

很酷不放纵 2024-10-08 15:32:42

不要依赖猜测和假设。自己在硬件、编码和数据上进行基准测试。

Don't rely on guesses and assumptions. Benchmark it yourself, on your hardware, with your coding, and your data.

半透明的墙 2024-10-08 15:32:42

我想说的是,您访问和使用信息的方式比信息实际存储的方式更相关。

我可能会说,如果您要独立引用每个答案(例如多项选择答案),请将答案存储在具有以下结构的 3 列表中:

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

其中答案将类似于 1, 2, 3, 4,..对于给定问题的每个答案,都会更合适、更理智。

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:

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.

緦唸λ蓇 2024-10-08 15:32:42

有些数据库不索引文本类型列。因此,如果您将文本列中的列分解为 varchar,并且您已对每一列建立了索引,并且您使用的数据库不为文本列建立索引,分解它们你会得到更好的性能。

Some DBs don't index text type columns. 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.

听风念你 2024-10-08 15:32:41

请勿将答案合并到单个列中,无论是否有分隔符。如果您这样做,您不仅违反了数据库设计中的经验法则(< strong>第一范式)你也正在为自己的编程世界做好准备。

您还应该考虑到您正在参与过早的优化。也不要这样做。根据我的经验,并且我认为其他人也会同意,您应该相信您的 RDBMS 能够为您有效地存储和检索数据。您唯一需要做的就是正确设置索引。如果这确实会成为性能问题,那么您可以在此时进行非规范化。

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. 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.

初熏 2024-10-08 15:32:41

根据您的编辑,您提供的选项都不是解决此问题的“正确”设计。您应该在答案表中创建 5 行,每行包含问题 ID 并在一列中包含一个答案。

只有当事实证明这会带来性能问题时,您才应该考虑其他设计。除非您收集了数百万个问题,否则不太可能出现问题。

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.

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.

丢了幸福的猪 2024-10-08 15:32:41

如果它们在同一张表中,那就没有什么区别。

一旦访问了一行,从列中查找数据只需花费很少的时间。

您应该根据您的数据以及访问数据的方式做出决定。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文