MemSQL - Surrogate key as Primary and different unique keys at the same time in table creation

岁酱吖の 提交于 2019-12-22 18:05:08

问题


I have a situation that I need to have a surrogate key (id) in place of a composite key (4 field combined to be unique: project_id, dataset_id, table_id, view_name) to easily refer that in other tables.

So to do this I used id field as Primary key and other 4 fields mentioned above as unique keys. This is allowed in MySQL but not in MemSQL.

Error Code: 1895. The unique key named: 'project_id' must contain all columns specified in the primary key when no shard key is declared

So I added the id field as the Shard key but no use.

CREATE TABLE `table_access_details` (
  `id` integer primary key,
  `project_id` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `dataset_id` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
  `table_id` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
  `view_name` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL ,
  `upload_id` decimal (14,0) DEFAULT NULL,
  `modified_datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  #SHARD KEY (`id`),
  unique(`project_id`,`dataset_id`,`table_id`,`view_name`)
);

How can I overcome this situation in MemSQL?


回答1:


So, you want unique key (id) as well as unique key (project_id, dataset_id, table_id, view_name)? This is not possible in a sharded table in memsql - the unique key cannot be efficiently enforced across shards. Your options are: don't use both unique keys, or make the table a reference table.



来源:https://stackoverflow.com/questions/40520136/memsql-surrogate-key-as-primary-and-different-unique-keys-at-the-same-time-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!