简体   繁体   English

具有多列或单列的MySQL数据库设计

[英]MySQL Database design with multiple column or single column

Hi just a simple question 嗨只是一个简单的问题
I need to store data to database, there are 2 option to show now 我需要将数据存储到数据库,现在有2个选项可以显示

Data : a,b,c,d 数据:a,b,c,d
1. store a,b,c,d in 1 column, when needed only query and perform splitting in application 1.将a,b,c,d存储在1列中,只需要查询并在应用程序中执行拆分
2. store a,b,c,d to 4 different column, can query directly from database 2.存储a,b,c,d到4个不同的列,可以直接从数据库查询

Which option will be better? 哪个选项更好? My concern is split it into 4 different column will make the tables contain many column, does it slow down the performance? 我关心的是将其拆分为4个不同的列,这会使表包含许多列,这会降低性能吗? And also I am curious is it possible the query is fast but the transfer of data to my application is slow? 我也很好奇,查询是否可能很快,但是向我的应用程序的数据传输却很慢?

MySQL performance is a complicated subject. MySQL性能是一个复杂的主题。 To the issue you raised: 对于你提出的问题:

My concern is split it into 4 different column will make the tables contain many column, does it slow down the performance? 我关心的是将其拆分为4个不同的列,这会使表包含许多列,这会降低性能吗?

there is nothing inherently worse, from a performance perspective, to have 4 columns, or 10, or 20, or 50. 从性能的角度来看,没有什么本质上更糟的是有4列,或10,或20,或50。

Now, that being said, there are things that could impact performance, and probably will if you don't know about them. 现在,有人说,有些东西可能会影响性能,如果你不了解它们,可能会有所影响。 For example, if you SELECT * FROM {my_table} when really you only need to SELECT a FROM {my_table} ... yeah, that'll impact your performance (although there are arguments to be made in favor of SELECT * FROM {my_table} depending on your caching strategy). 例如,如果您SELECT * FROM {my_table} ,那么您只需要SELECT a FROM {my_table} ...是的,这会影响您的表现(尽管有一些参数支持SELECT * FROM {my_table}取决于你的缓存策略)。

Likewise, you'll want to consider LIMIT statements. 同样,您将要考虑LIMIT语句。 To your question 对你的问题

And also I am curious is it possible the query is fast but the transfer of data to my application is slow? 我也很好奇,查询是否可能很快,但是向我的应用程序的数据传输却很慢?

Yes, of course. 当然是。 If you only need 50 rows and your table has 50000, you're gonna want to add limit clauses to your SQL statements, or you'll be sending a lot more data over the wire than you need to be. 如果你只需要50行而你的表有50000,那么你需要在你的SQL语句中添加限制子句,或者你将通过线路发送比你需要的更多的数据。 Memory is faster than disk and disk is faster than network. 内存比磁盘快,磁盘比网络快。 If you're sending a lot of data over the wire that you don't need, you better believe it's gonna cause performance problems. 如果您通过线路发送大量不需要的数据,您最好相信它会导致性能问题。 But again, keep in mind, that has nothing to do with how many columns you have. 但请记住,这与您拥有的列数无关。 There is absolutely nothing inherent in the number of columns a table has that affects performance (at least not at the scale that you're talking about and in the way that you are thinking about it) 表格的列数绝对没有任何内在因素影响性能(至少不是你所谈论的规模和你想到的方式)

All of which to say, performance is a complex topic. 总而言之,性能是一个复杂的话题。 You should take a look into it, if you're interested. 如果您有兴趣,应该看看它。 And it sounds like a,b,c, and d are logically different columns, so you should probably go ahead and store them in different columns in MySQL. 它听起来像a,b,c和d是逻辑上不同的列,所以你应该继续将它们存储在MySQL的不同列中。 Hope this helps. 希望这可以帮助。

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

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