多列VS一个大容量列?

时间:2016-01-04 15:17:05

标签: mysql performance data-structures

我有一张这样的表:

// table_A
+--------+---------------+------------+
|   id   |  short-text   | long-text  |
+--------+---------------+------------+
 int(11)    varchar(200)      text         // <= type

注1: sort-textlong-text中的一个始终为NULL。从来没有两个都没有包含数据。像这样:

+--------+---------------+------------+
|   id   |  short-text   | long-text  |
+--------+---------------+------------+
| 1      |some character |  NULL      |
| 2      |some character |  NULL      |
| 3      |some character |  NULL      |
| 4      |some character |  NULL      |
| 5      |some character |  NULL      |
| 6      |NULL           |  some text |
| 7      |some character |  NULL      |
| 8      |some character |  NULL      |
| 9      |some character |  NULL      |
| 10     |some character |  NULL      |
| 11     |some character |  NULL      |
| 12     |NULL           |  some text |
+--------+---------------+------------+

注2:正如您在上表示例中看到的那样,总共有5行long-textNULL,然后是1行,short-text为{ {1}}。

现在我的问题是,上面的结构更好还是只创建一列(NULL)而不是这两列?像这样的东西:

type = text

这是包含数据的表:

// table_B
+--------+---------------------+
|   id   | short-and-long-text |
+--------+---------------------+
 int(11)         text                // <= type

嗯,哪一个更有效率和优化? +--------+---------------------+ | id | short-and-long-text | +--------+---------------------+ | 1 | some character | | 2 | some character | | 3 | some character | | 4 | some character | | 5 | some character | | 6 | some text | | 7 | some character | | 8 | some character | | 9 | some character | | 10 | some character | | 11 | some character | | 12 | some text | +--------+---------------------+ table_A

注3:我总是按ID查找。

0 个答案:

没有答案