我有一個多對多的表,這將有數百萬行。讓我用一個例子來描述我的困惑。多對多索引問題,mysql
例如:
表: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的新手,所有幫助表示讚賞。
的firts一個是正確的..never使用組合值。至於第二個樣品中..永遠用分離柱分隔值..你可以輕鬆地添加複合指數 – scaisEdge