performance - 集群主键与非集群主键

标签 performance sqlite clustered-index

begin transaction;
create table person_id(person_id integer primary key);
insert into person_id values(1);
... snip ...
insert into person_id values(50000);
commit;

此代码在我的机器上大约需要 0.9 秒,并创建一个占用 392K 的 db 文件。如果我将第二行更改为,这些数字将变为 1.4 秒和 864K

create table person_id(person_id integer nonclustered primary key);

为什么会这样?

最佳答案

在 DBA StackExchange 上可以找到这个问题的一个很好的答案:https://dba.stackexchange.com/questions/7741/when-should-a-primary-key-be-declared-non-clustered/7744#7744

关于performance - 集群主键与非集群主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2138507/

相关文章:

ruby-on-rails - 如何将排序移动到数据库级别

sql - 我如何在 SQLite 中使用 ESCAPE?

mysql - MySQL InnoDB 中的簇主键

mysql - 你能在 MySQL 中设计一个简单的例子,其中聚集索引是解决方案,而不是普通索引吗?

sql-server - `primary key`关键字与SQL Server中的聚集索引有何关系?

c - 将 char * 重新解释为用于只读操作的另一种原始类型的数组的任何合法方法?

python - 为什么使用 mask=None 或 mask=0 创建一个屏蔽的 numpy 数组这么慢

java - 将一种数据结构与另一种数据结构进行比较,导致运行时间超过 50 分钟

iphone - 在 iPhone 应用程序中将日期保存到 SQLite3

android - 查询同步数据库列与星期几