问题描述
在MySQL中,通常是更快/更高效/可扩展,返回100行3列,或1行100列吗?
In MySQL, is it generally faster/more efficient/scalable to return 100 rows with 3 columns, or 1 row with 100 columns?
换句话说,存储与记录相关的许多key =>值对,最好将每个key =>值对存储在单独的行中,并以record_id作为键,或者每个record_id有一行,每个键有一列?
In other words, when storing many key => value pairs related to a record, is it better to store each key => value pair in a separate row with with the record_id as a key, or to have one row per record_id with a column for each key?
此外,假设键需要相当规则地添加/删除,我假设一旦表变得足够大,会影响许多列方法的长期可维护性
Also, assume also that keys will need to be added/removed fairly regularly, which I assume would affect the long term maintainability of the many column approach once the table gets sufficiently large.
编辑:以澄清,定期我的意思是每月一次添加或删除密钥。 / p>
to clarify, by "a regular basis" I mean the addition or removal of a key once a month or so.
推荐答案
您不应定期添加或删除列。
You should never add or remove columns on a regular basis.
这篇关于哪个更快:多行或多列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!