【发布时间】:2017-09-10 18:13:45
【问题描述】:
我有一个多对多表,这将有数百万行。让我用一个例子来描述我的困惑。
示例:
表:car_dealer_rel
选择:1
columns: car_id: int unsigned, dealer_id: int unsigned index on: car_id, dealer_id
car_id|dealer_id
-------|---------
1 | 1
1 | 2
....
- sub-opt:1:在这里我可以在两列上都有一个索引。
- sub-opt:2:2 列上的一个组合索引。
选择-2:
一列表格
col: car_id_dealer_id: varchar:21 index on: PKI on this single column.
这里的想法是将值设置为:car_id.dealer_id 并搜索为%.xxx and or xxx.%
car_id_dealer_id
----------------
1.1
1.2
1.15
2.10
...
...
在数百万条记录之后会更快:
- 从 读取
- 添加/更新/删除。
我是 MySQL 新手,感谢所有帮助。
【问题讨论】:
-
第一个是正确的 .. 永远不要使用组合值 .. 就像在第二个示例中一样 .. 使用分离列作为分离值 .. 您可以轻松添加复合索引