我想对我的表进行分区。表格是:
create_table "multimedia", :force => true do |t|
t.integer "id"
t. binary "data"
t.integer "device_id"
t.datetime "created_at"
end
id
是主键
created_at 是表的简单索引并且没有唯一性
我需要按字段 created_at 对表进行分区。在我的表中,只有过去 7 天的记录,所以我想按天对它进行分区。我写了这个:
partition by range (to_days(created_at))
( PARTITION p20120417 VALUES LESS THAN (to_days('2012-04-17 23:59:59 +0200')),
PARTITION p20120418 VALUES LESS THAN (to_days('2012-04-18 23:59:59 +0200')),
PARTITION p20120419 VALUES LESS THAN (to_days('2012-04-19 23:59:59 +0200')),
PARTITION p20120420 VALUES LESS THAN (to_days('2012-04-20 23:59:59 +0200')),
PARTITION p20120421 VALUES LESS THAN (to_days('2012-04-21 23:59:59 +0200')),
PARTITION p20120422 VALUES LESS THAN (to_days('2012-04-22 23:59:59 +0200')),
PARTITION p20120423 VALUES LESS THAN (to_days('2012-04-23 23:59:59 +0200')),
PARTITION p20120424 VALUES LESS THAN (to_days('2012-04-24 23:59:59 +0200'))
);
代码给了我这个错误:
PRIMARY KEY 必须包含表的分区函数中的所有列
我需要该表仅由 created_at 分区并且它不能是唯一的。
我能怎么做?