创建一个没有聚簇索引的mysql主键? [英] Create a mysql primary key without a clustered index?

查看:208
本文介绍了创建一个没有聚簇索引的mysql主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名SQL Server专家,正在为即将进行的大型项目(由于许可)而在MySQL上进行试验,但在没有聚集索引的情况下创建主键的方式方面我找不到很多信息.我在5.1上阅读的所有文档都说主键会自动获得聚簇索引.由于我在主键列(GUID)上使用了binary(16),所以我宁愿不使用聚簇索引.所以...

I'm a SQL Server guy experimenting with MySQL for a large upcoming project (due to licensing) and I'm not finding much information in the way of creating a primary key without a clustered index. All the documentation I've read says on 5.1 says that a primary key is automatically given a clustered index. Since I'm using a binary(16) for the primary key column (GUID), I'd rather not have a clustered index on it. So...

  1. 是否可以在没有聚集索引的情况下创建主键?我总是可以将聚簇索引放在date_created列上,但是如何防止mysql自动在主键上创建聚簇索引?
  2. 如果不可能的话,在GUID列上具有唯一索引并且在表上没有主键的情况下,我可以在性能上做到吗?我打算在这里使用nhibernate,所以不确定是否没有主键(还没有到此为止).

推荐答案

考虑

Considering what is said on 13.6.10.1. Clustered and Secondary Indexes, it seems you cannot really define on which column the clustered index is set :

  • 它在PK列上
  • 或在具有唯一索引(仅具有非空值)的第一列上
  • 或在某些内部列上-不适用于您的情况^^

关于您帖子中的第二个问题:表上没有PK,GUID上有UNIQUE索引;可能,但是它不会改变聚簇索引的任何内容:它仍可能在GUID列上.

About the second question in your post : no PK on the table, and a UNIQUE index on the GUID ; it might be possible, but it will not change anything about the clustered index : it will still probably be on the GUID column.


可能是某种黑客手段:


Some kind of a hack might be to :

  • 未定义主键
  • 在date_created字段上放置一个UNIQUE索引(如果您在短时间内没有创建太多行,那可能是可行的...)

不确定您可以在GUID上放置第二个UNIQUE索引...也许^^
并且不确定聚集索引的变化是否很大;但可能值得一试...

Not sure you can place a second UNIQUE index on the GUID... Maybe ^^
And not sure that would change much about the clustered index ; but might be worth a try...

这篇关于创建一个没有聚簇索引的mysql主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆