【发布时间】:2015-09-30 11:18:11
【问题描述】:
我正在创建一个表,它将使用 InnoDB 存储引擎在 MySQL 5.6 中存储大约 1 亿行。该表将有一个外键链接到另一个包含大约 500 万行的表。
当前表结构:
`pid`: [Foreign key from another table]
`price`: [decimal(9,2)]
`date`: [date field]
每个pid 应该只有一个date 的记录
在此表上创建索引的最佳方法是什么?
选项 #1: 在 pid 和 date 两个字段上创建主索引
选项 #2: 使用 AUTO_INCREMENT 和 primary index 添加另一列 id,并在 pid 和 date 列上创建唯一索引
或者有其他选择吗?
我将在此表上使用的唯一选择查询是:
SELECT pid,price,date FROM table WHERE pid = 123
【问题讨论】:
标签: mysql database indexing innodb